An interface for numeric types

Enum FPCategory

Used for representing the classification of floating point numbers

Variants

Trait Algebraic

Method pow

fn pow(&self, n: &Self) -> Self

Method sqrt

fn sqrt(&self) -> Self

Method rsqrt

fn rsqrt(&self) -> Self

Method cbrt

fn cbrt(&self) -> Self

Method hypot

fn hypot(&self, other: &Self) -> Self

Trait BitCount

Method population_count

fn population_count(&self) -> Self

Method leading_zeros

fn leading_zeros(&self) -> Self

Method trailing_zeros

fn trailing_zeros(&self) -> Self

Trait Bitwise

Collects the bitwise operators under one trait.

Trait Bounded

Method min_value

fn min_value() -> Self

Method max_value

fn max_value() -> Self

Trait Exponential

Method exp

fn exp(&self) -> Self

Method exp2

fn exp2(&self) -> Self

Method ln

fn ln(&self) -> Self

Method log

fn log(&self, base: &Self) -> Self

Method log2

fn log2(&self) -> Self

Method log10

fn log10(&self) -> Self

Trait Float

Primitive floating point numbers

Method NaN

fn NaN() -> Self

Method infinity

fn infinity() -> Self

Method neg_infinity

fn neg_infinity() -> Self

Method neg_zero

fn neg_zero() -> Self

Method is_NaN

fn is_NaN(&self) -> bool

Method is_infinite

fn is_infinite(&self) -> bool

Method is_finite

fn is_finite(&self) -> bool

Method is_normal

fn is_normal(&self) -> bool

Method classify

fn classify(&self) -> FPCategory

Method mantissa_digits

fn mantissa_digits() -> uint

Method digits

fn digits() -> uint

Method epsilon

fn epsilon() -> Self

Method min_exp

fn min_exp() -> int

Method max_exp

fn max_exp() -> int

Method min_10_exp

fn min_10_exp() -> int

Method max_10_exp

fn max_10_exp() -> int

Method ldexp

fn ldexp(x: Self, exp: int) -> Self

Method frexp

fn frexp(&self) -> (Self, int)

Method exp_m1

fn exp_m1(&self) -> Self

Method ln_1p

fn ln_1p(&self) -> Self

Method mul_add

fn mul_add(&self, a: Self, b: Self) -> Self

Method next_after

fn next_after(&self, other: Self) -> Self

Trait Fractional

Method recip

fn recip(&self) -> Self

Trait FromStrRadix

Method from_str_radix

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

Trait Hyperbolic

Method sinh

fn sinh(&self) -> Self

Method cosh

fn cosh(&self) -> Self

Method tanh

fn tanh(&self) -> Self

Method asinh

fn asinh(&self) -> Self

Method acosh

fn acosh(&self) -> Self

Method atanh

fn atanh(&self) -> Self

Trait Int

A collection of traits relevant to primitive signed and unsigned integers

Trait IntConvertible

Method to_int

fn to_int(&self) -> int

Method from_int

fn from_int(n: int) -> Self

Trait Integer

Method div_rem

fn div_rem(&self, other: &Self) -> (Self, Self)

Method div_floor

fn div_floor(&self, other: &Self) -> Self

Method mod_floor

fn mod_floor(&self, other: &Self) -> Self

Method div_mod_floor

fn div_mod_floor(&self, other: &Self) -> (Self, Self)

Method gcd

fn gcd(&self, other: &Self) -> Self

Method lcm

fn lcm(&self, other: &Self) -> Self

Method is_multiple_of

fn is_multiple_of(&self, other: &Self) -> bool

Method is_even

fn is_even(&self) -> bool

Method is_odd

fn is_odd(&self) -> bool

Trait Num

The base trait for numeric types

Trait NumCast

An interface for casting between machine scalars

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 Orderable

Method min

fn min(&self, other: &Self) -> Self

Method max

fn max(&self, other: &Self) -> Self

Method clamp

fn clamp(&self, mn: &Self, mx: &Self) -> Self

Trait Primitive

Specifies the available operations common to all of Rust's core numeric primitives. These may not always make sense from a purely mathematical point of view, but may be useful for systems programming.

Method bits

fn bits() -> uint

Method bytes

fn bytes() -> uint

Trait Real

Defines constants and methods common to real numbers

Method pi

fn pi() -> Self

Method two_pi

fn two_pi() -> Self

Method frac_pi_2

fn frac_pi_2() -> Self

Method frac_pi_3

fn frac_pi_3() -> Self

Method frac_pi_4

fn frac_pi_4() -> Self

Method frac_pi_6

fn frac_pi_6() -> Self

Method frac_pi_8

fn frac_pi_8() -> Self

Method frac_1_pi

fn frac_1_pi() -> Self

Method frac_2_pi

fn frac_2_pi() -> Self

Method frac_2_sqrtpi

fn frac_2_sqrtpi() -> Self

Method sqrt2

fn sqrt2() -> Self

Method frac_1_sqrt2

fn frac_1_sqrt2() -> Self

Method e

fn e() -> Self

Method log2_e

fn log2_e() -> Self

Method log10_e

fn log10_e() -> Self

Method ln_2

fn ln_2() -> Self

Method ln_10

fn ln_10() -> Self

Method to_degrees

fn to_degrees(&self) -> Self

Method to_radians

fn to_radians(&self) -> Self

Trait RealExt

Methods that are harder to implement and not commonly used.

Method lgamma

fn lgamma(&self) -> (int, Self)

Method tgamma

fn tgamma(&self) -> Self

Method j0

fn j0(&self) -> Self

Method j1

fn j1(&self) -> Self

Method jn

fn jn(&self, n: int) -> Self

Method y0

fn y0(&self) -> Self

Method y1

fn y1(&self) -> Self

Method yn

fn yn(&self, n: int) -> Self

Trait Round

Method floor

fn floor(&self) -> Self

Method ceil

fn ceil(&self) -> Self

Method round

fn round(&self) -> Self

Method trunc

fn trunc(&self) -> Self

Method fract

fn fract(&self) -> Self

Trait Signed

Method abs

fn abs(&self) -> Self

Method abs_sub

fn abs_sub(&self, other: &Self) -> Self

Method signum

fn signum(&self) -> Self

Method is_positive

fn is_positive(&self) -> bool

Method is_negative

fn is_negative(&self) -> bool

Trait ToStrRadix

Method to_str_radix

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

Trait Trigonometric

Method sin

fn sin(&self) -> Self

Method cos

fn cos(&self) -> Self

Method tan

fn tan(&self) -> Self

Method asin

fn asin(&self) -> Self

Method acos

fn acos(&self) -> Self

Method atan

fn atan(&self) -> Self

Method atan2

fn atan2(&self, other: &Self) -> Self

Method sin_cos

fn sin_cos(&self) -> (Self, Self)

Trait Unsigned

Trait Zero

Method zero

fn zero() -> Self

Method is_zero

fn is_zero(&self) -> bool

Implementation of ::std::cmp::Eq for FPCategory

Automatically derived.

Method eq

fn eq(&self, __arg_0: &FPCategory) -> ::bool

Method ne

fn ne(&self, __arg_0: &FPCategory) -> ::bool

Implementation of NumCast for u8

Method from

fn from<N: NumCast>(n: N) -> u8

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

Implementation of NumCast for u16

Method from

fn from<N: NumCast>(n: N) -> u16

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

Implementation of NumCast for u32

Method from

fn from<N: NumCast>(n: N) -> u32

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

Implementation of NumCast for u64

Method from

fn from<N: NumCast>(n: N) -> u64

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

Implementation of NumCast for uint

Method from

fn from<N: NumCast>(n: N) -> uint

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

Implementation of NumCast for i8

Method from

fn from<N: NumCast>(n: N) -> i8

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

Implementation of NumCast for i16

Method from

fn from<N: NumCast>(n: N) -> i16

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

Implementation of NumCast for i32

Method from

fn from<N: NumCast>(n: N) -> i32

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

Implementation of NumCast for i64

Method from

fn from<N: NumCast>(n: N) -> i64

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

Implementation of NumCast for int

Method from

fn from<N: NumCast>(n: N) -> int

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

Implementation of NumCast for f32

Method from

fn from<N: NumCast>(n: N) -> f32

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

Implementation of NumCast for f64

Method from

fn from<N: NumCast>(n: N) -> f64

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

Implementation of NumCast for float

Method from

fn from<N: NumCast>(n: N) -> float

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

Implementation of Zero for @mut T where <T: Zero>

Method zero

fn zero() -> @mut T

Method is_zero

fn is_zero(&self) -> bool

Implementation of Zero for @T where <T: Zero>

Method zero

fn zero() -> @T

Method is_zero

fn is_zero(&self) -> bool

Implementation of Zero for ~T where <T: Zero>

Method zero

fn zero() -> ~T

Method is_zero

fn is_zero(&self) -> bool

Function abs

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

Function cast

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

Cast from one machine scalar to another

Example

let twenty: f32 = num::cast(0x14);
assert_eq!(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.