Struct num::rational::RatioExperimental [-]  [+] [src]

pub struct Ratio<T> {
    // some fields omitted
}

Represents the ratio between 2 numbers.

Methods

impl<T: Clone + Integer + PartialOrd> Ratio<T>

fn from_integer(t: T) -> Ratio<T>

Creates a ratio representing the integer t.

fn new_raw(numer: T, denom: T) -> Ratio<T>

Creates a ratio without checking for denom == 0 or reducing.

fn new(numer: T, denom: T) -> Ratio<T>

Create a new Ratio. Fails if denom == 0.

fn to_integer(&self) -> T

Converts to an integer.

fn numer<'a>(&'a self) -> &'a T

Gets an immutable reference to the numerator.

fn denom<'a>(&'a self) -> &'a T

Gets an immutable reference to the denominator.

fn is_integer(&self) -> bool

Returns true if the rational number is an integer (denominator is 1).

fn reduced(&self) -> Ratio<T>

Returns a reduced copy of self.

fn recip(&self) -> Ratio<T>

Returns the reciprocal.

fn floor(&self) -> Ratio<T>

Rounds towards minus infinity.

fn ceil(&self) -> Ratio<T>

Rounds towards plus infinity.

fn round(&self) -> Ratio<T>

Rounds to the nearest integer. Rounds half-way cases away from zero.

fn trunc(&self) -> Ratio<T>

Rounds towards zero.

fn fract(&self) -> Ratio<T>

Returns the fractional part of a number.

impl Ratio<BigInt>

fn from_float<T: Float>(f: T) -> Option<BigRational>

Converts a float into a rational number.

Trait Implementations

impl<T: Mul<T, T> + PartialEq> PartialEq for Ratio<T>

fn eq(&self, other: &Ratio<T>) -> bool

fn ne(&self, other: &Ratio<T>) -> bool

impl<T: Mul<T, T> + PartialOrd> PartialOrd for Ratio<T>

fn lt(&self, other: &Ratio<T>) -> bool

fn gt(&self, other: &Ratio<T>) -> bool

fn le(&self, other: &Ratio<T>) -> bool

fn ge(&self, other: &Ratio<T>) -> bool

fn partial_cmp(&self, other: &Ratio<T>) -> Option<Ordering>

impl<T: Mul<T, T> + Eq> Eq for Ratio<T>

fn assert_receiver_is_total_eq(&self)

impl<T: Mul<T, T> + Ord> Ord for Ratio<T>

fn cmp(&self, other: &Ratio<T>) -> Ordering

impl<T: Clone + Integer + PartialOrd> Mul<Ratio<T>, Ratio<T>> for Ratio<T>

fn mul(&self, rhs: &Ratio<T>) -> Ratio<T>

impl<T: Clone + Integer + PartialOrd> Div<Ratio<T>, Ratio<T>> for Ratio<T>

fn div(&self, rhs: &Ratio<T>) -> Ratio<T>

impl<T: Clone + Integer + PartialOrd> Add<Ratio<T>, Ratio<T>> for Ratio<T>

fn add(&self, rhs: &Ratio<T>) -> Ratio<T>

impl<T: Clone + Integer + PartialOrd> Sub<Ratio<T>, Ratio<T>> for Ratio<T>

fn sub(&self, rhs: &Ratio<T>) -> Ratio<T>

impl<T: Clone + Integer + PartialOrd> Rem<Ratio<T>, Ratio<T>> for Ratio<T>

fn rem(&self, rhs: &Ratio<T>) -> Ratio<T>

impl<T: Clone + Integer + PartialOrd> Neg<Ratio<T>> for Ratio<T>

fn neg(&self) -> Ratio<T>

impl<T: Clone + Integer + PartialOrd> Zero for Ratio<T>

fn zero() -> Ratio<T>

fn is_zero(&self) -> bool

impl<T: Clone + Integer + PartialOrd> One for Ratio<T>

fn one() -> Ratio<T>

impl<T: Clone + Integer + PartialOrd> Num for Ratio<T>

impl<T: Clone + Integer + PartialOrd> Signed for Ratio<T>

fn abs(&self) -> Ratio<T>

fn abs_sub(&self, other: &Ratio<T>) -> Ratio<T>

fn signum(&self) -> Ratio<T>

fn is_positive(&self) -> bool

fn is_negative(&self) -> bool

impl<T: Show + Eq + One> Show for Ratio<T>

fn fmt(&self, f: &mut Formatter) -> Result

Renders as numer/denom. If denom=1, renders as numer.

impl<T: FromStr + Clone + Integer + PartialOrd> FromStr for Ratio<T>

fn from_str(s: &str) -> Option<Ratio<T>>

Parses numer/denom or just numer.

impl<T: FromStrRadix + Clone + Integer + PartialOrd> FromStrRadix for Ratio<T>

fn from_str_radix(s: &str, radix: uint) -> Option<Ratio<T>>

Parses numer/denom where the numbers are in base radix.

Derived Implementations

impl<__D: Decoder<__E>, __E, T: Decodable<__D, __E>> Decodable<__D, __E> for Ratio<T>

fn decode(__arg_0: &mut __D) -> Result<Ratio<T>, __E>

impl<__S: Encoder<__E>, __E, T: Encodable<__S, __E>> Encodable<__S, __E> for Ratio<T>

fn encode(&self, __arg_0: &mut __S) -> Result<(), __E>

impl<__S: Writer, T: Hash<__S>> Hash<__S> for Ratio<T>

fn hash(&self, __arg_0: &mut __S)

impl<T: Clone> Clone for Ratio<T>

fn clone(&self) -> Ratio<T>

fn clone_from(&mut self, source: &Self)