Struct rational::Rational[][src]

pub struct Rational { /* fields omitted */ }
Expand description

A rational number (a fraction of two integers).

Implementations

impl Rational[src]

pub fn new<N, D>(numerator: N, denominator: D) -> Self where
    Rational: From<N>,
    Rational: From<D>, 
[src]

Construct a new Rational.

Panics

  • If the resulting denominator is 0.

pub fn new_checked<N, D>(numerator: N, denominator: D) -> Option<Self> where
    Rational: From<N>,
    Rational: From<D>, 
[src]

Construct a new Rational, returning None if the denominator is 0.

pub fn numerator(&self) -> i128[src]

Get the numerator in this Rational.

pub fn denominator(&self) -> i128[src]

Get the denominator in this Rational.

pub fn inverse_checked(self) -> Option<Self>[src]

Returns the inverse of this Rational, or None if the denominator of the inverse is 0.

pub fn inverse(self) -> Self[src]

Returns the inverse of this Rational.

Panics

  • If the denominator of the inverse is 0.

pub fn decimal_value(self) -> f64[src]

Returns the decimal value of this Rational. Equivalent to f64::from(self).

pub fn checked_add<T>(self, other: T) -> Option<Self> where
    Self: From<T>, 
[src]

pub fn checked_mul<T>(self, other: T) -> Option<Self> where
    Self: From<T>, 
[src]

pub fn checked_sub<T>(self, other: T) -> Option<Self> where
    Self: From<T>, 
[src]

pub fn checked_div<T>(self, other: T) -> Option<Self> where
    Self: From<T>, 
[src]

Trait Implementations

impl<T> Add<T> for Rational where
    Rational: From<T>, 
[src]

type Output = Self

The resulting type after applying the + operator.

fn add(self, rhs: T) -> Self::Output[src]

Performs the + operation. Read more

impl<T> AddAssign<T> for Rational where
    Rational: From<T>, 
[src]

fn add_assign(&mut self, rhs: T)[src]

Performs the += operation. Read more

impl Clone for Rational[src]

fn clone(&self) -> Rational[src]

Returns a copy of the value. Read more

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

Performs copy-assignment from source. Read more

impl Debug for Rational[src]

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

Formats the value using the given formatter. Read more

impl Display for Rational[src]

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

Formats the value using the given formatter. Read more

impl<T> Div<T> for Rational where
    Rational: From<T>, 
[src]

type Output = Self

The resulting type after applying the / operator.

fn div(self, rhs: T) -> Self::Output[src]

Performs the / operation. Read more

impl<T> DivAssign<T> for Rational where
    Rational: From<T>, 
[src]

fn div_assign(&mut self, rhs: T)[src]

Performs the /= operation. Read more

impl From<i128> for Rational[src]

fn from(v: i128) -> Self[src]

Performs the conversion.

impl From<i16> for Rational[src]

fn from(v: i16) -> Self[src]

Performs the conversion.

impl From<i32> for Rational[src]

fn from(v: i32) -> Self[src]

Performs the conversion.

impl From<i64> for Rational[src]

fn from(v: i64) -> Self[src]

Performs the conversion.

impl From<i8> for Rational[src]

fn from(v: i8) -> Self[src]

Performs the conversion.

impl From<isize> for Rational[src]

fn from(v: isize) -> Self[src]

Performs the conversion.

impl From<u16> for Rational[src]

fn from(v: u16) -> Self[src]

Performs the conversion.

impl From<u32> for Rational[src]

fn from(v: u32) -> Self[src]

Performs the conversion.

impl From<u64> for Rational[src]

fn from(v: u64) -> Self[src]

Performs the conversion.

impl From<u8> for Rational[src]

fn from(v: u8) -> Self[src]

Performs the conversion.

impl Hash for Rational[src]

fn hash<__H: Hasher>(&self, state: &mut __H)[src]

Feeds this value into the given Hasher. Read more

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

Feeds a slice of this type into the given Hasher. Read more

impl<T> Mul<T> for Rational where
    Rational: From<T>, 
[src]

type Output = Self

The resulting type after applying the * operator.

fn mul(self, rhs: T) -> Self::Output[src]

Performs the * operation. Read more

impl<T> MulAssign<T> for Rational where
    Rational: From<T>, 
[src]

fn mul_assign(&mut self, rhs: T)[src]

Performs the *= operation. Read more

impl Neg for Rational[src]

type Output = Self

The resulting type after applying the - operator.

fn neg(self) -> Self::Output[src]

Performs the unary - operation. Read more

impl Ord for Rational[src]

fn cmp(&self, other: &Self) -> Ordering[src]

This method returns an Ordering between self and other. Read more

#[must_use]
fn max(self, other: Self) -> Self
1.21.0[src]

Compares and returns the maximum of two values. Read more

#[must_use]
fn min(self, other: Self) -> Self
1.21.0[src]

Compares and returns the minimum of two values. Read more

#[must_use]
fn clamp(self, min: Self, max: Self) -> Self
1.50.0[src]

Restrict a value to a certain interval. Read more

impl PartialEq<Rational> for Rational[src]

fn eq(&self, rhs: &Rational) -> bool[src]

This method tests for self and other values to be equal, and is used by ==. Read more

#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests for !=.

impl PartialOrd<Rational> for Rational[src]

fn partial_cmp(&self, other: &Self) -> Option<Ordering>[src]

This method returns an ordering between self and other values if one exists. Read more

#[must_use]
fn lt(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests less than (for self and other) and is used by the < operator. Read more

#[must_use]
fn le(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

#[must_use]
fn gt(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests greater than (for self and other) and is used by the > operator. Read more

#[must_use]
fn ge(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

impl<T> Sub<T> for Rational where
    Rational: From<T>, 
[src]

type Output = Self

The resulting type after applying the - operator.

fn sub(self, rhs: T) -> Self::Output[src]

Performs the - operation. Read more

impl<T> SubAssign<T> for Rational where
    Rational: From<T>, 
[src]

fn sub_assign(&mut self, rhs: T)[src]

Performs the -= operation. Read more

impl Copy for Rational[src]

impl Eq for Rational[src]

Auto Trait Implementations

Blanket Implementations

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

pub fn type_id(&self) -> TypeId[src]

Gets the TypeId of self. Read more

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

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

Immutably borrows from an owned value. Read more

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

pub fn borrow_mut(&mut self) -> &mut T[src]

Mutably borrows from an owned value. Read more

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

pub fn from(t: T) -> T[src]

Performs the conversion.

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

pub fn into(self) -> U[src]

Performs the conversion.

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

type Owned = T

The resulting type after obtaining ownership.

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

Creates owned data from borrowed data, usually by cloning. Read more

pub fn clone_into(&self, target: &mut T)[src]

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

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

pub default fn to_string(&self) -> String[src]

Converts the given value to a String. Read more

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.

pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]

Performs the conversion.

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.

pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>[src]

Performs the conversion.