# [−][src]Struct num_rational::Ratio

pub struct Ratio<T> {
pub numer: T,
pub denom: T,
}

Represents the ratio between two numbers.

numer: T

Numerator.

denom: T

Denominator.

## Implementations

### impl<T> Ratio<T>[src]

These method are const for Rust 1.31 and later.

#### pub const fn new_raw(numer: T, denom: T) -> Ratio<T>[src]

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

#### pub const fn numer(&self) -> &T[src]

Gets an immutable reference to the numerator.

#### pub const fn denom(&self) -> &T[src]

Gets an immutable reference to the denominator.

### impl<T: Clone + Integer> Ratio<T>[src]

#### pub fn new(numer: T, denom: T) -> Ratio<T>[src]

Creates a new Ratio. Fails if denom is zero.

#### pub fn from_integer(t: T) -> Ratio<T>[src]

Creates a Ratio representing the integer t.

#### pub fn to_integer(&self) -> T[src]

Converts to an integer, rounding towards zero.

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

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

#### pub fn reduced(&self) -> Ratio<T>[src]

Returns a reduced copy of self.

In general, it is not necessary to use this method, as the only method of procuring a non-reduced fraction is through new_raw.

#### pub fn recip(&self) -> Ratio<T>[src]

Returns the reciprocal.

Fails if the Ratio is zero.

#### pub fn floor(&self) -> Ratio<T>[src]

Rounds towards minus infinity.

#### pub fn ceil(&self) -> Ratio<T>[src]

Rounds towards plus infinity.

#### pub fn round(&self) -> Ratio<T>[src]

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

#### pub fn trunc(&self) -> Ratio<T>[src]

Rounds towards zero.

#### pub fn fract(&self) -> Ratio<T>[src]

Returns the fractional part of a number, with division rounded towards zero.

Satisfies self == self.trunc() + self.fract().

### impl<T: Clone + Integer + Pow<u32, Output = T>> Ratio<T>[src]

#### pub fn pow(&self, expon: i32) -> Ratio<T>[src]

Raises the Ratio to the power of an exponent.

### impl Ratio<BigInt>[src]

#### pub fn from_float<T: FloatCore>(f: T) -> Option<BigRational>[src]

Converts a float into a rational number.

## Trait Implementations

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

#### type Output = Ratio<T>

The resulting type after applying the + operator.

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

#### type Output = Ratio<T>

The resulting type after applying the + operator.

### impl<'a, 'b, T: Clone + Integer> Add<&'b Ratio<T>> for &'a Ratio<T>[src]

#### type Output = Ratio<T>

The resulting type after applying the + operator.

### impl<'a, 'b, T: Clone + Integer> Add<&'b T> for &'a Ratio<T>[src]

#### type Output = Ratio<T>

The resulting type after applying the + operator.

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

#### type Output = Ratio<T>

The resulting type after applying the + operator.

### impl<T: Clone + Integer> Add<Ratio<T>> for Ratio<T>[src]

#### type Output = Ratio<T>

The resulting type after applying the + operator.

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

#### type Output = Ratio<T>

The resulting type after applying the + operator.

### impl<T: Clone + Integer> Add<T> for Ratio<T>[src]

#### type Output = Ratio<T>

The resulting type after applying the + operator.

### impl<T> Display for Ratio<T> where    T: Display + Eq + One, [src]

#### fn fmt(&self, f: &mut Formatter<'_>) -> Result[src]

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

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

#### type Output = Ratio<T>

The resulting type after applying the / operator.

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

#### type Output = Ratio<T>

The resulting type after applying the / operator.

### impl<'a, 'b, T: Clone + Integer> Div<&'b Ratio<T>> for &'a Ratio<T>[src]

#### type Output = Ratio<T>

The resulting type after applying the / operator.

### impl<'a, 'b, T: Clone + Integer> Div<&'b T> for &'a Ratio<T>[src]

#### type Output = Ratio<T>

The resulting type after applying the / operator.

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

#### type Output = Ratio<T>

The resulting type after applying the / operator.

### impl<T> Div<Ratio<T>> for Ratio<T> where    T: Clone + Integer, [src]

#### type Output = Ratio<T>

The resulting type after applying the / operator.

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

#### type Output = Ratio<T>

The resulting type after applying the / operator.

### impl<T> Div<T> for Ratio<T> where    T: Clone + Integer, [src]

#### type Output = Ratio<T>

The resulting type after applying the / operator.

### impl<T: FromStr + Clone + Integer> FromStr for Ratio<T>[src]

#### type Err = ParseRatioError

The associated error which can be returned from parsing.

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

Parses numer/denom or just numer.

### impl<T> Inv for Ratio<T> where    T: Clone + Integer, [src]

#### type Output = Ratio<T>

The result after applying the operator.

### impl<'a, T> Inv for &'a Ratio<T> where    T: Clone + Integer, [src]

#### type Output = Ratio<T>

The result after applying the operator.

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

#### type Output = Ratio<T>

The resulting type after applying the * operator.

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

#### type Output = Ratio<T>

The resulting type after applying the * operator.

### impl<'a, 'b, T: Clone + Integer> Mul<&'b Ratio<T>> for &'a Ratio<T>[src]

#### type Output = Ratio<T>

The resulting type after applying the * operator.

### impl<'a, 'b, T: Clone + Integer> Mul<&'b T> for &'a Ratio<T>[src]

#### type Output = Ratio<T>

The resulting type after applying the * operator.

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

#### type Output = Ratio<T>

The resulting type after applying the * operator.

### impl<T> Mul<Ratio<T>> for Ratio<T> where    T: Clone + Integer, [src]

#### type Output = Ratio<T>

The resulting type after applying the * operator.

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

#### type Output = Ratio<T>

The resulting type after applying the * operator.

### impl<T> Mul<T> for Ratio<T> where    T: Clone + Integer, [src]

#### type Output = Ratio<T>

The resulting type after applying the * operator.

### impl<T> Neg for Ratio<T> where    T: Clone + Integer + Neg<Output = T>, [src]

#### type Output = Ratio<T>

The resulting type after applying the - operator.

### impl<'a, T> Neg for &'a Ratio<T> where    T: Clone + Integer + Neg<Output = T>, [src]

#### type Output = Ratio<T>

The resulting type after applying the - operator.

### impl<T: Clone + Integer> Num for Ratio<T>[src]

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

### impl<'a, T: Clone + Integer + Pow<u16, Output = T>> Pow<&'a i16> for Ratio<T>[src]

#### type Output = Ratio<T>

The result after applying the operator.

### impl<'a, 'b, T: Clone + Integer + Pow<u16, Output = T>> Pow<&'a i16> for &'b Ratio<T>[src]

#### type Output = Ratio<T>

The result after applying the operator.

### impl<'a, T: Clone + Integer + Pow<u32, Output = T>> Pow<&'a i32> for Ratio<T>[src]

#### type Output = Ratio<T>

The result after applying the operator.

### impl<'a, 'b, T: Clone + Integer + Pow<u32, Output = T>> Pow<&'a i32> for &'b Ratio<T>[src]

#### type Output = Ratio<T>

The result after applying the operator.

### impl<'a, T: Clone + Integer + Pow<u64, Output = T>> Pow<&'a i64> for Ratio<T>[src]

#### type Output = Ratio<T>

The result after applying the operator.

### impl<'a, 'b, T: Clone + Integer + Pow<u64, Output = T>> Pow<&'a i64> for &'b Ratio<T>[src]

#### type Output = Ratio<T>

The result after applying the operator.

### impl<'a, T: Clone + Integer + Pow<u8, Output = T>> Pow<&'a i8> for Ratio<T>[src]

#### type Output = Ratio<T>

The result after applying the operator.

### impl<'a, 'b, T: Clone + Integer + Pow<u8, Output = T>> Pow<&'a i8> for &'b Ratio<T>[src]

#### type Output = Ratio<T>

The result after applying the operator.

### impl<'a, T: Clone + Integer + Pow<usize, Output = T>> Pow<&'a isize> for Ratio<T>[src]

#### type Output = Ratio<T>

The result after applying the operator.

### impl<'a, 'b, T: Clone + Integer + Pow<usize, Output = T>> Pow<&'a isize> for &'b Ratio<T>[src]

#### type Output = Ratio<T>

The result after applying the operator.

### impl<'a, T: Clone + Integer + Pow<u16, Output = T>> Pow<&'a u16> for Ratio<T>[src]

#### type Output = Ratio<T>

The result after applying the operator.

### impl<'a, 'b, T: Clone + Integer + Pow<u16, Output = T>> Pow<&'a u16> for &'b Ratio<T>[src]

#### type Output = Ratio<T>

The result after applying the operator.

### impl<'a, T: Clone + Integer + Pow<u32, Output = T>> Pow<&'a u32> for Ratio<T>[src]

#### type Output = Ratio<T>

The result after applying the operator.

### impl<'a, 'b, T: Clone + Integer + Pow<u32, Output = T>> Pow<&'a u32> for &'b Ratio<T>[src]

#### type Output = Ratio<T>

The result after applying the operator.

### impl<'a, T: Clone + Integer + Pow<u64, Output = T>> Pow<&'a u64> for Ratio<T>[src]

#### type Output = Ratio<T>

The result after applying the operator.

### impl<'a, 'b, T: Clone + Integer + Pow<u64, Output = T>> Pow<&'a u64> for &'b Ratio<T>[src]

#### type Output = Ratio<T>

The result after applying the operator.

### impl<'a, T: Clone + Integer + Pow<u8, Output = T>> Pow<&'a u8> for Ratio<T>[src]

#### type Output = Ratio<T>

The result after applying the operator.

### impl<'a, 'b, T: Clone + Integer + Pow<u8, Output = T>> Pow<&'a u8> for &'b Ratio<T>[src]

#### type Output = Ratio<T>

The result after applying the operator.

### impl<'a, T: Clone + Integer + Pow<usize, Output = T>> Pow<&'a usize> for Ratio<T>[src]

#### type Output = Ratio<T>

The result after applying the operator.

### impl<'a, 'b, T: Clone + Integer + Pow<usize, Output = T>> Pow<&'a usize> for &'b Ratio<T>[src]

#### type Output = Ratio<T>

The result after applying the operator.

### impl<T: Clone + Integer + Pow<u16, Output = T>> Pow<i16> for Ratio<T>[src]

#### type Output = Ratio<T>

The result after applying the operator.

### impl<'a, T: Clone + Integer + Pow<u16, Output = T>> Pow<i16> for &'a Ratio<T>[src]

#### type Output = Ratio<T>

The result after applying the operator.

### impl<T: Clone + Integer + Pow<u32, Output = T>> Pow<i32> for Ratio<T>[src]

#### type Output = Ratio<T>

The result after applying the operator.

### impl<'a, T: Clone + Integer + Pow<u32, Output = T>> Pow<i32> for &'a Ratio<T>[src]

#### type Output = Ratio<T>

The result after applying the operator.

### impl<T: Clone + Integer + Pow<u64, Output = T>> Pow<i64> for Ratio<T>[src]

#### type Output = Ratio<T>

The result after applying the operator.

### impl<'a, T: Clone + Integer + Pow<u64, Output = T>> Pow<i64> for &'a Ratio<T>[src]

#### type Output = Ratio<T>

The result after applying the operator.

### impl<T: Clone + Integer + Pow<u8, Output = T>> Pow<i8> for Ratio<T>[src]

#### type Output = Ratio<T>

The result after applying the operator.

### impl<'a, T: Clone + Integer + Pow<u8, Output = T>> Pow<i8> for &'a Ratio<T>[src]

#### type Output = Ratio<T>

The result after applying the operator.

### impl<T: Clone + Integer + Pow<usize, Output = T>> Pow<isize> for Ratio<T>[src]

#### type Output = Ratio<T>

The result after applying the operator.

### impl<'a, T: Clone + Integer + Pow<usize, Output = T>> Pow<isize> for &'a Ratio<T>[src]

#### type Output = Ratio<T>

The result after applying the operator.

### impl<T: Clone + Integer + Pow<u16, Output = T>> Pow<u16> for Ratio<T>[src]

#### type Output = Ratio<T>

The result after applying the operator.

### impl<'a, T: Clone + Integer + Pow<u16, Output = T>> Pow<u16> for &'a Ratio<T>[src]

#### type Output = Ratio<T>

The result after applying the operator.

### impl<T: Clone + Integer + Pow<u32, Output = T>> Pow<u32> for Ratio<T>[src]

#### type Output = Ratio<T>

The result after applying the operator.

### impl<'a, T: Clone + Integer + Pow<u32, Output = T>> Pow<u32> for &'a Ratio<T>[src]

#### type Output = Ratio<T>

The result after applying the operator.

### impl<T: Clone + Integer + Pow<u64, Output = T>> Pow<u64> for Ratio<T>[src]

#### type Output = Ratio<T>

The result after applying the operator.

### impl<'a, T: Clone + Integer + Pow<u64, Output = T>> Pow<u64> for &'a Ratio<T>[src]

#### type Output = Ratio<T>

The result after applying the operator.

### impl<T: Clone + Integer + Pow<u8, Output = T>> Pow<u8> for Ratio<T>[src]

#### type Output = Ratio<T>

The result after applying the operator.

### impl<'a, T: Clone + Integer + Pow<u8, Output = T>> Pow<u8> for &'a Ratio<T>[src]

#### type Output = Ratio<T>

The result after applying the operator.

### impl<T: Clone + Integer + Pow<usize, Output = T>> Pow<usize> for Ratio<T>[src]

#### type Output = Ratio<T>

The result after applying the operator.

### impl<'a, T: Clone + Integer + Pow<usize, Output = T>> Pow<usize> for &'a Ratio<T>[src]

#### type Output = Ratio<T>

The result after applying the operator.

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

#### type Output = Ratio<T>

The resulting type after applying the % operator.

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

#### type Output = Ratio<T>

The resulting type after applying the % operator.

### impl<'a, 'b, T: Clone + Integer> Rem<&'b Ratio<T>> for &'a Ratio<T>[src]

#### type Output = Ratio<T>

The resulting type after applying the % operator.

### impl<'a, 'b, T: Clone + Integer> Rem<&'b T> for &'a Ratio<T>[src]

#### type Output = Ratio<T>

The resulting type after applying the % operator.

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

#### type Output = Ratio<T>

The resulting type after applying the % operator.

### impl<T: Clone + Integer> Rem<Ratio<T>> for Ratio<T>[src]

#### type Output = Ratio<T>

The resulting type after applying the % operator.

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

#### type Output = Ratio<T>

The resulting type after applying the % operator.

### impl<T: Clone + Integer> Rem<T> for Ratio<T>[src]

#### type Output = Ratio<T>

The resulting type after applying the % operator.

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

#### type Output = Ratio<T>

The resulting type after applying the - operator.

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

#### type Output = Ratio<T>

The resulting type after applying the - operator.

### impl<'a, 'b, T: Clone + Integer> Sub<&'b Ratio<T>> for &'a Ratio<T>[src]

#### type Output = Ratio<T>

The resulting type after applying the - operator.

### impl<'a, 'b, T: Clone + Integer> Sub<&'b T> for &'a Ratio<T>[src]

#### type Output = Ratio<T>

The resulting type after applying the - operator.

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

#### type Output = Ratio<T>

The resulting type after applying the - operator.

### impl<T: Clone + Integer> Sub<Ratio<T>> for Ratio<T>[src]

#### type Output = Ratio<T>

The resulting type after applying the - operator.

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

#### type Output = Ratio<T>

The resulting type after applying the - operator.

### impl<T: Clone + Integer> Sub<T> for Ratio<T>[src]

#### type Output = Ratio<T>

The resulting type after applying the - operator.

## Blanket Implementations

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

#### type Owned = T

The resulting type after obtaining ownership.

### 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.