An interface for numeric types
RoundMode
FromStrRadix
IntConvertible
NumCast
- An interface for generic numeric type castsOne
Round
ToStrRadix
Zero
abs
cast
- Cast a number the the enclosing typepow_with_uint
- Calculates a power to a given radix, optimized for uint pow
and radix
.num::strconv
RoundMode
RoundDown
RoundUp
RoundToZero
RoundFromZero
FromStrRadix
from_str_radix
fn from_str_radix(str: &str, radix: uint) -> Option<Self>
IntConvertible
to_int
fn to_int(&self) -> int
from_int
fn from_int(n: int) -> Self
NumCast
An interface for generic numeric type casts
from
fn from<T: NumCast>(n: T) -> Self
to_u8
fn to_u8(&self) -> u8
to_u16
fn to_u16(&self) -> u16
to_u32
fn to_u32(&self) -> u32
to_u64
fn to_u64(&self) -> u64
to_uint
fn to_uint(&self) -> uint
to_i8
fn to_i8(&self) -> i8
to_i16
fn to_i16(&self) -> i16
to_i32
fn to_i32(&self) -> i32
to_i64
fn to_i64(&self) -> i64
to_int
fn to_int(&self) -> int
to_f32
fn to_f32(&self) -> f32
to_f64
fn to_f64(&self) -> f64
to_float
fn to_float(&self) -> float
One
one
fn one() -> Self
Round
round
fn round(&self, mode: RoundMode) -> Self
floor
fn floor(&self) -> Self
ceil
fn ceil(&self) -> Self
fract
fn fract(&self) -> Self
ToStrRadix
to_str_radix
fn to_str_radix(&self, radix: uint) -> ~str
Zero
zero
fn zero() -> Self
abs
fn abs<T: Ord + Zero + Neg<T>>(v: T) -> T
cast
fn cast<T: NumCast, U: NumCast>(n: T) -> U
Cast a number the the enclosing type
let twenty: f32 = num::cast(0x14);
assert!(twenty == 20f32);
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
.