[][src]Struct ramp::rational::Rational

pub struct Rational { /* fields omitted */ }

An arbitrary-precision rational number.

This type is used to represent numbers in the form a / b where a and b are Ints and b is non-zero.

Implementations

impl Rational[src]

pub fn abs(self) -> Rational[src]

Consumes this Rational, returning its absolute value.

pub fn new(n: Int, d: Int) -> Rational[src]

Creates a new Rational from a numerator n and denominator d.

This method normalizes the Rational.

Panics

Panics if d is zero.

pub fn into_parts(self) -> (Int, Int)[src]

Returns the (numerator, denominator) of this Rational in normalized form.

pub fn normalized(&self) -> bool[src]

Returns whether or not this Rational is normalized.

pub fn normalize(&mut self)[src]

Normalize this Rational in place.

This method ensures that the Rational is represented in lowest forms, i.e. as a/b such that a and b share no common factors. It also ensures that the denominator is positive.

Normalizing rationals results in faster calculations, ensuring that the numerator and denominator are as small as possible.

Most of the time, this method is called automatically.

pub fn invert(self) -> Rational[src]

Consumes this Rational, returning its reciprocal.

Panics

Panics if the Rational is zero. This can be checked with the is_zero method.

pub fn round(self) -> Int[src]

Consumes this Rational, rounding it to the nearest Int.

This method will round half values away from zero, similarly to f64::round.

pub fn sign(&self) -> i32[src]

Returns the sign of this Rational as either -1, 0 or 1 depending on whether it is negative, zero, or positive, respectively.

pub fn to_f64(&self) -> f64[src]

Converts this Rational into an f64.

This is not an exact conversion, because this Rational may be more precise than an f64 can account for.

Currently, this conversion is naïve, simply converting the numerator and denominator into f64s and dividing them.

Trait Implementations

impl<'a> Add<&'a Int> for Rational[src]

type Output = Rational

The resulting type after applying the + operator.

impl<'a, 'b> Add<&'a Int> for &'b Rational[src]

type Output = Rational

The resulting type after applying the + operator.

impl<'a> Add<&'a Rational> for Rational[src]

type Output = Rational

The resulting type after applying the + operator.

impl<'a, 'b> Add<&'a Rational> for &'b Rational[src]

type Output = Rational

The resulting type after applying the + operator.

impl<'a> Add<&'a Rational> for Int[src]

type Output = Rational

The resulting type after applying the + operator.

impl<'a, 'b> Add<&'a Rational> for &'b Int[src]

type Output = Rational

The resulting type after applying the + operator.

impl Add<Int> for Rational[src]

type Output = Rational

The resulting type after applying the + operator.

impl<'a> Add<Int> for &'a Rational[src]

type Output = Rational

The resulting type after applying the + operator.

impl Add<Rational> for Rational[src]

type Output = Rational

The resulting type after applying the + operator.

impl<'a> Add<Rational> for &'a Rational[src]

type Output = Rational

The resulting type after applying the + operator.

impl Add<Rational> for Int[src]

type Output = Rational

The resulting type after applying the + operator.

impl<'a> Add<Rational> for &'a Int[src]

type Output = Rational

The resulting type after applying the + operator.

impl<'a> AddAssign<&'a Int> for Rational[src]

impl<'a> AddAssign<&'a Rational> for Rational[src]

impl AddAssign<Int> for Rational[src]

impl AddAssign<Rational> for Rational[src]

impl Clone for Rational[src]

impl Debug for Rational[src]

impl Default for Rational[src]

impl Display for Rational[src]

impl<'a> Div<&'a Int> for Rational[src]

type Output = Rational

The resulting type after applying the / operator.

impl<'a, 'b> Div<&'a Int> for &'b Rational[src]

type Output = Rational

The resulting type after applying the / operator.

impl<'a> Div<&'a Rational> for Rational[src]

type Output = Rational

The resulting type after applying the / operator.

impl<'a, 'b> Div<&'a Rational> for &'b Rational[src]

type Output = Rational

The resulting type after applying the / operator.

impl<'a> Div<&'a Rational> for Int[src]

type Output = Rational

The resulting type after applying the / operator.

impl<'a, 'b> Div<&'a Rational> for &'b Int[src]

type Output = Rational

The resulting type after applying the / operator.

impl Div<Int> for Rational[src]

type Output = Rational

The resulting type after applying the / operator.

impl<'a> Div<Int> for &'a Rational[src]

type Output = Rational

The resulting type after applying the / operator.

impl Div<Rational> for Rational[src]

type Output = Rational

The resulting type after applying the / operator.

impl<'a> Div<Rational> for &'a Rational[src]

type Output = Rational

The resulting type after applying the / operator.

impl Div<Rational> for Int[src]

type Output = Rational

The resulting type after applying the / operator.

impl<'a> Div<Rational> for &'a Int[src]

type Output = Rational

The resulting type after applying the / operator.

impl<'a> DivAssign<&'a Int> for Rational[src]

impl<'a> DivAssign<&'a Rational> for Rational[src]

impl DivAssign<Int> for Rational[src]

impl DivAssign<Rational> for Rational[src]

impl Eq for Rational[src]

impl<U: Into<Int>> From<U> for Rational[src]

impl From<f32> for Rational[src]

impl From<f64> for Rational[src]

impl FromStr for Rational[src]

type Err = ParseRationalError

The associated error which can be returned from parsing.

impl Hash for Rational[src]

impl<'a> Mul<&'a Int> for Rational[src]

type Output = Rational

The resulting type after applying the * operator.

impl<'a, 'b> Mul<&'a Int> for &'b Rational[src]

type Output = Rational

The resulting type after applying the * operator.

impl<'a> Mul<&'a Rational> for Rational[src]

type Output = Rational

The resulting type after applying the * operator.

impl<'a, 'b> Mul<&'a Rational> for &'b Rational[src]

type Output = Rational

The resulting type after applying the * operator.

impl<'a> Mul<&'a Rational> for Int[src]

type Output = Rational

The resulting type after applying the * operator.

impl<'a, 'b> Mul<&'a Rational> for &'b Int[src]

type Output = Rational

The resulting type after applying the * operator.

impl Mul<Int> for Rational[src]

type Output = Rational

The resulting type after applying the * operator.

impl<'a> Mul<Int> for &'a Rational[src]

type Output = Rational

The resulting type after applying the * operator.

impl Mul<Rational> for Rational[src]

type Output = Rational

The resulting type after applying the * operator.

impl<'a> Mul<Rational> for &'a Rational[src]

type Output = Rational

The resulting type after applying the * operator.

impl Mul<Rational> for Int[src]

type Output = Rational

The resulting type after applying the * operator.

impl<'a> Mul<Rational> for &'a Int[src]

type Output = Rational

The resulting type after applying the * operator.

impl<'a> MulAssign<&'a Int> for Rational[src]

impl<'a> MulAssign<&'a Rational> for Rational[src]

impl MulAssign<Int> for Rational[src]

impl MulAssign<Rational> for Rational[src]

impl Neg for Rational[src]

type Output = Rational

The resulting type after applying the - operator.

impl<'a> Neg for &'a Rational[src]

type Output = Rational

The resulting type after applying the - operator.

impl One for Rational[src]

impl Ord for Rational[src]

impl PartialEq<Int> for Rational[src]

impl PartialEq<Rational> for Rational[src]

impl PartialEq<Rational> for Int[src]

impl PartialOrd<Int> for Rational[src]

impl PartialOrd<Rational> for Rational[src]

impl PartialOrd<Rational> for Int[src]

impl<'a> Sub<&'a Rational> for Rational[src]

type Output = Rational

The resulting type after applying the - operator.

impl<'a, 'b> Sub<&'a Rational> for &'b Rational[src]

type Output = Rational

The resulting type after applying the - operator.

impl Sub<Rational> for Rational[src]

type Output = Rational

The resulting type after applying the - operator.

impl<'a> Sub<Rational> for &'a Rational[src]

type Output = Rational

The resulting type after applying the - operator.

impl<'a> SubAssign<&'a Rational> for Rational[src]

impl SubAssign<Rational> for Rational[src]

impl Zero for Rational[src]

Auto Trait Implementations

impl RefUnwindSafe for Rational

impl Send for Rational

impl Sync for Rational

impl Unpin for Rational

impl UnwindSafe for Rational

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.