Struct num::rational::Ratio [] [src]

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

Represents the ratio between 2 numbers.

Methods

impl Ratio<BigInt>

fn from_float<T>(f: T) -> Option<Ratio<BigInt>> where T: Float

Converts a float into a rational number.

impl<T> Ratio<T> where T: Clone + Integer + PrimInt

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

Raises the ratio to the power of an exponent

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

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 self) -> &'a T

Gets an immutable reference to the numerator.

fn denom(&'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.

Trait Implementations

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

type Err = ParseRatioError

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

Parses numer/denom or just numer.

impl<T> Display for Ratio<T> where T: Display + Eq + One

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

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

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

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> Num for Ratio<T> where T: Clone + Integer

type FromStrRadixErr = ParseRatioError

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

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

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

fn one() -> Ratio<T>

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

fn zero() -> Ratio<T>

fn is_zero(&self) -> bool

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

type Output = Ratio<T>

fn neg(self) -> Ratio<T>

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

type Output = Ratio<T>

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

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

type Output = Ratio<T>

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

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

type Output = Ratio<T>

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

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

type Output = Ratio<T>

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

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

type Output = Ratio<T>

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

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

type Output = Ratio<T>

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

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

type Output = Ratio<T>

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

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

type Output = Ratio<T>

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

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

type Output = Ratio<T>

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

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

type Output = Ratio<T>

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

impl<T> Eq for Ratio<T> where T: Clone + Integer

impl<T> PartialEq<Ratio<T>> for Ratio<T> where T: Clone + Integer

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

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

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

impl<T> Ord for Ratio<T> where T: Clone + Integer

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

Derived Implementations

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

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

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

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

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

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

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

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

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

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

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

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