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

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

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.

fn add(self, other: &'a Int) -> Rational[src]

Performs the + operation. Read more

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

type Output = Rational

The resulting type after applying the + operator.

fn add(self, other: &'a Int) -> Rational[src]

Performs the + operation. Read more

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

type Output = Rational

The resulting type after applying the + operator.

fn add(self, other: &'a Rational) -> Rational[src]

Performs the + operation. Read more

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

type Output = Rational

The resulting type after applying the + operator.

fn add(self, other: &'a Rational) -> Rational[src]

Performs the + operation. Read more

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

type Output = Rational

The resulting type after applying the + operator.

fn add(self, other: &'a Rational) -> Rational[src]

Performs the + operation. Read more

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

type Output = Rational

The resulting type after applying the + operator.

fn add(self, other: &'a Rational) -> Rational[src]

Performs the + operation. Read more

impl Add<Int> for Rational[src]

type Output = Rational

The resulting type after applying the + operator.

fn add(self, other: Int) -> Rational[src]

Performs the + operation. Read more

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

type Output = Rational

The resulting type after applying the + operator.

fn add(self, other: Int) -> Rational[src]

Performs the + operation. Read more

impl Add<Rational> for Rational[src]

type Output = Rational

The resulting type after applying the + operator.

fn add(self, other: Rational) -> Rational[src]

Performs the + operation. Read more

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

type Output = Rational

The resulting type after applying the + operator.

fn add(self, other: Rational) -> Rational[src]

Performs the + operation. Read more

impl Add<Rational> for Int[src]

type Output = Rational

The resulting type after applying the + operator.

fn add(self, other: Rational) -> Rational[src]

Performs the + operation. Read more

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

type Output = Rational

The resulting type after applying the + operator.

fn add(self, other: Rational) -> Rational[src]

Performs the + operation. Read more

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

fn add_assign(&mut self, other: &'a Int)[src]

Performs the += operation. Read more

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

fn add_assign(&mut self, other: &'a Rational)[src]

Performs the += operation. Read more

impl AddAssign<Int> for Rational[src]

fn add_assign(&mut self, other: Int)[src]

Performs the += operation. Read more

impl AddAssign<Rational> for Rational[src]

fn add_assign(&mut self, other: Rational)[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, other: &Rational)[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 Default for Rational[src]

fn default() -> Rational[src]

Returns the “default value” for a type. 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<'a> Div<&'a Int> for Rational[src]

type Output = Rational

The resulting type after applying the / operator.

fn div(self, other: &'a Int) -> Rational[src]

Performs the / operation. Read more

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

type Output = Rational

The resulting type after applying the / operator.

fn div(self, other: &'a Int) -> Rational[src]

Performs the / operation. Read more

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

type Output = Rational

The resulting type after applying the / operator.

fn div(self, other: &'a Rational) -> Rational[src]

Performs the / operation. Read more

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

type Output = Rational

The resulting type after applying the / operator.

fn div(self, other: &'a Rational) -> Rational[src]

Performs the / operation. Read more

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

type Output = Rational

The resulting type after applying the / operator.

fn div(self, other: &'a Rational) -> Rational[src]

Performs the / operation. Read more

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

type Output = Rational

The resulting type after applying the / operator.

fn div(self, other: &'a Rational) -> Rational[src]

Performs the / operation. Read more

impl Div<Int> for Rational[src]

type Output = Rational

The resulting type after applying the / operator.

fn div(self, other: Int) -> Rational[src]

Performs the / operation. Read more

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

type Output = Rational

The resulting type after applying the / operator.

fn div(self, other: Int) -> Rational[src]

Performs the / operation. Read more

impl Div<Rational> for Rational[src]

type Output = Rational

The resulting type after applying the / operator.

fn div(self, other: Rational) -> Rational[src]

Performs the / operation. Read more

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

type Output = Rational

The resulting type after applying the / operator.

fn div(self, other: Rational) -> Rational[src]

Performs the / operation. Read more

impl Div<Rational> for Int[src]

type Output = Rational

The resulting type after applying the / operator.

fn div(self, other: Rational) -> Rational[src]

Performs the / operation. Read more

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

type Output = Rational

The resulting type after applying the / operator.

fn div(self, other: Rational) -> Rational[src]

Performs the / operation. Read more

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

fn div_assign(&mut self, other: &'a Int)[src]

Performs the /= operation. Read more

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

fn div_assign(&mut self, other: &'a Rational)[src]

Performs the /= operation. Read more

impl DivAssign<Int> for Rational[src]

fn div_assign(&mut self, other: Int)[src]

Performs the /= operation. Read more

impl DivAssign<Rational> for Rational[src]

fn div_assign(&mut self, other: Rational)[src]

Performs the /= operation. Read more

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

fn from(val: U) -> Rational[src]

Performs the conversion.

impl From<f32> for Rational[src]

fn from(val: f32) -> Rational[src]

Performs the conversion.

impl From<f64> for Rational[src]

fn from(val: f64) -> Rational[src]

Performs the conversion.

impl FromStr for Rational[src]

type Err = ParseRationalError

The associated error which can be returned from parsing.

fn from_str(s: &str) -> Result<Rational, ParseRationalError>[src]

Parses a string s to return a value of this type. Read more

impl Hash for Rational[src]

fn hash<H>(&self, state: &mut H) where
    H: Hasher
[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<'a> Mul<&'a Int> for Rational[src]

type Output = Rational

The resulting type after applying the * operator.

fn mul(self, other: &'a Int) -> Rational[src]

Performs the * operation. Read more

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

type Output = Rational

The resulting type after applying the * operator.

fn mul(self, other: &'a Int) -> Rational[src]

Performs the * operation. Read more

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

type Output = Rational

The resulting type after applying the * operator.

fn mul(self, other: &'a Rational) -> Rational[src]

Performs the * operation. Read more

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

type Output = Rational

The resulting type after applying the * operator.

fn mul(self, other: &'a Rational) -> Rational[src]

Performs the * operation. Read more

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

type Output = Rational

The resulting type after applying the * operator.

fn mul(self, other: &'a Rational) -> Rational[src]

Performs the * operation. Read more

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

type Output = Rational

The resulting type after applying the * operator.

fn mul(self, other: &'a Rational) -> Rational[src]

Performs the * operation. Read more

impl Mul<Int> for Rational[src]

type Output = Rational

The resulting type after applying the * operator.

fn mul(self, other: Int) -> Rational[src]

Performs the * operation. Read more

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

type Output = Rational

The resulting type after applying the * operator.

fn mul(self, other: Int) -> Rational[src]

Performs the * operation. Read more

impl Mul<Rational> for Rational[src]

type Output = Rational

The resulting type after applying the * operator.

fn mul(self, other: Rational) -> Rational[src]

Performs the * operation. Read more

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

type Output = Rational

The resulting type after applying the * operator.

fn mul(self, other: Rational) -> Rational[src]

Performs the * operation. Read more

impl Mul<Rational> for Int[src]

type Output = Rational

The resulting type after applying the * operator.

fn mul(self, other: Rational) -> Rational[src]

Performs the * operation. Read more

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

type Output = Rational

The resulting type after applying the * operator.

fn mul(self, other: Rational) -> Rational[src]

Performs the * operation. Read more

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

fn mul_assign(&mut self, other: &'a Int)[src]

Performs the *= operation. Read more

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

fn mul_assign(&mut self, other: &'a Rational)[src]

Performs the *= operation. Read more

impl MulAssign<Int> for Rational[src]

fn mul_assign(&mut self, other: Int)[src]

Performs the *= operation. Read more

impl MulAssign<Rational> for Rational[src]

fn mul_assign(&mut self, other: Rational)[src]

Performs the *= operation. Read more

impl Neg for Rational[src]

type Output = Rational

The resulting type after applying the - operator.

fn neg(self) -> Rational[src]

Performs the unary - operation. Read more

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

type Output = Rational

The resulting type after applying the - operator.

fn neg(self) -> Rational[src]

Performs the unary - operation. Read more

impl One for Rational[src]

fn one() -> Rational[src]

Returns the multiplicative identity element of Self, 1. Read more

fn set_one(&mut self)[src]

Sets self to the multiplicative identity element of Self, 1.

fn is_one(&self) -> bool where
    Self: PartialEq<Self>, 
[src]

Returns true if self is equal to the multiplicative identity. Read more

impl Ord for Rational[src]

fn cmp(&self, other: &Rational) -> 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<Int> for Rational[src]

fn eq(&self, other: &Int) -> 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 PartialEq<Rational> for Rational[src]

fn eq(&self, other: &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 PartialEq<Rational> for Int[src]

fn eq(&self, other: &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<Int> for Rational[src]

fn partial_cmp(&self, other: &Int) -> 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 PartialOrd<Rational> for Rational[src]

fn partial_cmp(&self, other: &Rational) -> 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 PartialOrd<Rational> for Int[src]

fn partial_cmp(&self, other: &Rational) -> 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<'a> Sub<&'a Rational> for Rational[src]

type Output = Rational

The resulting type after applying the - operator.

fn sub(self, other: &'a Rational) -> Rational[src]

Performs the - operation. Read more

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

type Output = Rational

The resulting type after applying the - operator.

fn sub(self, other: &'a Rational) -> Rational[src]

Performs the - operation. Read more

impl Sub<Rational> for Rational[src]

type Output = Rational

The resulting type after applying the - operator.

fn sub(self, other: Rational) -> Rational[src]

Performs the - operation. Read more

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

type Output = Rational

The resulting type after applying the - operator.

fn sub(self, other: Rational) -> Rational[src]

Performs the - operation. Read more

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

fn sub_assign(&mut self, other: &'a Rational)[src]

Performs the -= operation. Read more

impl SubAssign<Rational> for Rational[src]

fn sub_assign(&mut self, other: Rational)[src]

Performs the -= operation. Read more

impl Zero for Rational[src]

fn zero() -> Rational[src]

Returns the additive identity element of Self, 0. Read more

fn is_zero(&self) -> bool[src]

Returns true if self is equal to the additive identity.

fn set_zero(&mut self)[src]

Sets self to the additive identity element of Self, 0.

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.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>, 

pub fn vzip(self) -> V