Struct num::rational::Ratio [] [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<T: Clone + Integer + PartialOrd + PrimInt> Ratio<T>

fn pow(&self, expon: i32) -> Ratio<T>

Raises the ratio to the power of an exponent

impl Ratio<BigInt>

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

Converts a float into a rational number.

Trait Implementations

impl<T> PartialEq for Ratio<T> where T: Clone + Mul<T, Output=T> + PartialEq

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

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

impl<T> PartialOrd for Ratio<T> where T: Clone + Mul<T, Output=T> + PartialOrd

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> Eq for Ratio<T> where T: Clone + Mul<T, Output=T> + Eq

impl<T> Ord for Ratio<T> where T: Clone + Mul<T, Output=T> + Ord

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

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

type Output = Ratio<T>

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

impl<'a, T> Mul<Ratio<T>> for &'a Ratio<T> where T: Clone + Integer + PartialOrd

type Output = Ratio<T>

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

impl<'a, T> Mul<&'a Ratio<T>> for Ratio<T> where T: Clone + Integer + PartialOrd

type Output = Ratio<T>

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

impl<'a, 'b, T> Mul<&'b Ratio<T>> for &'a Ratio<T> where T: Clone + Integer + PartialOrd

type Output = Ratio<T>

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

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

type Output = Ratio<T>

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

impl<'a, T> Div<Ratio<T>> for &'a Ratio<T> where T: Clone + Integer + PartialOrd

type Output = Ratio<T>

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

impl<'a, T> Div<&'a Ratio<T>> for Ratio<T> where T: Clone + Integer + PartialOrd

type Output = Ratio<T>

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

impl<'a, 'b, T> Div<&'b Ratio<T>> for &'a Ratio<T> where T: Clone + Integer + PartialOrd

type Output = Ratio<T>

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

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

type Output = Ratio<T>

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

impl<'a, T> Add<Ratio<T>> for &'a Ratio<T> where T: Clone + Integer + PartialOrd

type Output = Ratio<T>

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

impl<'a, T> Add<&'a Ratio<T>> for Ratio<T> where T: Clone + Integer + PartialOrd

type Output = Ratio<T>

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

impl<'a, 'b, T: Clone + Integer + PartialOrd> Add<&'b Ratio<T>> for &'a Ratio<T>

type Output = Ratio<T>

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

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

type Output = Ratio<T>

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

impl<'a, T> Sub<Ratio<T>> for &'a Ratio<T> where T: Clone + Integer + PartialOrd

type Output = Ratio<T>

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

impl<'a, T> Sub<&'a Ratio<T>> for Ratio<T> where T: Clone + Integer + PartialOrd

type Output = Ratio<T>

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

impl<'a, 'b, T: Clone + Integer + PartialOrd> Sub<&'b Ratio<T>> for &'a Ratio<T>

type Output = Ratio<T>

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

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

type Output = Ratio<T>

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

impl<'a, T> Rem<Ratio<T>> for &'a Ratio<T> where T: Clone + Integer + PartialOrd

type Output = Ratio<T>

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

impl<'a, T> Rem<&'a Ratio<T>> for Ratio<T> where T: Clone + Integer + PartialOrd

type Output = Ratio<T>

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

impl<'a, 'b, T: Clone + Integer + PartialOrd> Rem<&'b Ratio<T>> for &'a Ratio<T>

type Output = Ratio<T>

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

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

type Output = Ratio<T>

fn neg(self) -> Ratio<T>

impl<'a, T> Neg for &'a Ratio<T> where T: Clone + Integer + PartialOrd + Neg<Output=T>

type Output = 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>

type FromStrRadixErr = ParseRatioError

fn from_str_radix(s: &str, radix: u32) -> Result<Ratio<T>, ParseRatioError>

impl<T: Clone + Integer + PartialOrd + Signed> 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> Display for Ratio<T> where T: Display + Eq + One

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

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

type Err = ParseRatioError

fn from_str(s: &str) -> Result<Ratio<T>, ParseRatioError>

Derived Implementations

impl<T: Debug> Debug for Ratio<T> where T: Debug, T: Debug

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

impl<T: Hash> Hash for Ratio<T> where T: Hash, T: Hash

fn hash<__H: Hasher>(&self, __arg_0: &mut __H)

fn hash_slice<H>(data: &[Self], state: &mut H) where H: Hasher

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

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

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

impl<T: Copy> Copy for Ratio<T> where T: Copy, T: Copy

impl<T: Decodable> Decodable for Ratio<T> where T: Decodable, T: Decodable

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

impl<T: Encodable> Encodable for Ratio<T> where T: Encodable, T: Encodable

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