An interface for numeric types

Enum RoundMode

Variants

Trait FromStrRadix

Method from_str_radix

fn from_str_radix(str: &str, radix: uint) -> Option<Self>

Trait IntConvertible

Method to_int

fn to_int(&self) -> int

Method from_int

fn from_int(n: int) -> Self

Trait NumCast

An interface for generic numeric type casts

Method from

fn from<T: NumCast>(n: T) -> Self

Method to_u8

fn to_u8(&self) -> u8

Method to_u16

fn to_u16(&self) -> u16

Method to_u32

fn to_u32(&self) -> u32

Method to_u64

fn to_u64(&self) -> u64

Method to_uint

fn to_uint(&self) -> uint

Method to_i8

fn to_i8(&self) -> i8

Method to_i16

fn to_i16(&self) -> i16

Method to_i32

fn to_i32(&self) -> i32

Method to_i64

fn to_i64(&self) -> i64

Method to_int

fn to_int(&self) -> int

Method to_f32

fn to_f32(&self) -> f32

Method to_f64

fn to_f64(&self) -> f64

Method to_float

fn to_float(&self) -> float

Trait One

Method one

fn one() -> Self

Trait Round

Method round

fn round(&self, mode: RoundMode) -> Self

Method floor

fn floor(&self) -> Self

Method ceil

fn ceil(&self) -> Self

Method fract

fn fract(&self) -> Self

Trait ToStrRadix

Method to_str_radix

fn to_str_radix(&self, radix: uint) -> ~str

Trait Zero

Method zero

fn zero() -> Self

Function abs

fn abs<T: Ord + Zero + Neg<T>>(v: T) -> T

Function cast

fn cast<T: NumCast, U: NumCast>(n: T) -> U

Cast a number the the enclosing type

Example

let twenty: f32 = num::cast(0x14);
assert!(twenty == 20f32);

Function pow_with_uint

fn pow_with_uint<T: NumCast + One + Zero + Copy + Div<T, T> +
                 Mul<T, T>>(radix: uint, pow: uint) -> T

Calculates a power to a given radix, optimized for uint pow and radix.

Returns radix^pow as T.

Note: Also returns 1 for 0^0, despite that technically being an undefined number. The reason for this is twofold: - If code written to use this function cares about that special case, it's probably going to catch it before making the call. - If code written to use this function doesn't care about it, it's probably assuming that x^0 always equals 1.