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 Int
s and b
is non-zero.
Implementations
impl Rational
[src]
impl Rational
[src]pub fn new(n: Int, d: Int) -> Rational
[src]
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]
pub fn into_parts(self) -> (Int, Int)
[src]Returns the (numerator, denominator) of this Rational
in normalized form.
pub fn normalized(&self) -> bool
[src]
pub fn normalized(&self) -> bool
[src]Returns whether or not this Rational
is normalized.
pub fn normalize(&mut self)
[src]
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 round(self) -> Int
[src]
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
.
Trait Implementations
impl<'a> AddAssign<&'a Int> for Rational
[src]
impl<'a> AddAssign<&'a Int> for Rational
[src]fn add_assign(&mut self, other: &'a Int)
[src]
fn add_assign(&mut self, other: &'a Int)
[src]Performs the +=
operation. Read more
impl<'a> AddAssign<&'a Rational> for Rational
[src]
impl<'a> AddAssign<&'a Rational> for Rational
[src]fn add_assign(&mut self, other: &'a Rational)
[src]
fn add_assign(&mut self, other: &'a Rational)
[src]Performs the +=
operation. Read more
impl AddAssign<Int> for Rational
[src]
impl AddAssign<Int> for Rational
[src]fn add_assign(&mut self, other: Int)
[src]
fn add_assign(&mut self, other: Int)
[src]Performs the +=
operation. Read more
impl AddAssign<Rational> for Rational
[src]
impl AddAssign<Rational> for Rational
[src]fn add_assign(&mut self, other: Rational)
[src]
fn add_assign(&mut self, other: Rational)
[src]Performs the +=
operation. Read more
impl<'a> DivAssign<&'a Int> for Rational
[src]
impl<'a> DivAssign<&'a Int> for Rational
[src]fn div_assign(&mut self, other: &'a Int)
[src]
fn div_assign(&mut self, other: &'a Int)
[src]Performs the /=
operation. Read more
impl<'a> DivAssign<&'a Rational> for Rational
[src]
impl<'a> DivAssign<&'a Rational> for Rational
[src]fn div_assign(&mut self, other: &'a Rational)
[src]
fn div_assign(&mut self, other: &'a Rational)
[src]Performs the /=
operation. Read more
impl DivAssign<Int> for Rational
[src]
impl DivAssign<Int> for Rational
[src]fn div_assign(&mut self, other: Int)
[src]
fn div_assign(&mut self, other: Int)
[src]Performs the /=
operation. Read more
impl DivAssign<Rational> for Rational
[src]
impl DivAssign<Rational> for Rational
[src]fn div_assign(&mut self, other: Rational)
[src]
fn div_assign(&mut self, other: Rational)
[src]Performs the /=
operation. Read more
impl FromStr for Rational
[src]
impl FromStr for Rational
[src]type Err = ParseRationalError
type Err = ParseRationalError
The associated error which can be returned from parsing.
impl<'a> MulAssign<&'a Int> for Rational
[src]
impl<'a> MulAssign<&'a Int> for Rational
[src]fn mul_assign(&mut self, other: &'a Int)
[src]
fn mul_assign(&mut self, other: &'a Int)
[src]Performs the *=
operation. Read more
impl<'a> MulAssign<&'a Rational> for Rational
[src]
impl<'a> MulAssign<&'a Rational> for Rational
[src]fn mul_assign(&mut self, other: &'a Rational)
[src]
fn mul_assign(&mut self, other: &'a Rational)
[src]Performs the *=
operation. Read more
impl MulAssign<Int> for Rational
[src]
impl MulAssign<Int> for Rational
[src]fn mul_assign(&mut self, other: Int)
[src]
fn mul_assign(&mut self, other: Int)
[src]Performs the *=
operation. Read more
impl MulAssign<Rational> for Rational
[src]
impl MulAssign<Rational> for Rational
[src]fn mul_assign(&mut self, other: Rational)
[src]
fn mul_assign(&mut self, other: Rational)
[src]Performs the *=
operation. Read more
impl Ord for Rational
[src]
impl Ord for Rational
[src]impl PartialOrd<Int> for Rational
[src]
impl PartialOrd<Int> for Rational
[src]fn partial_cmp(&self, other: &Int) -> Option<Ordering>
[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]
#[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]
#[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
impl PartialOrd<Rational> for Rational
[src]
impl PartialOrd<Rational> for Rational
[src]fn partial_cmp(&self, other: &Rational) -> Option<Ordering>
[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]
#[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]
#[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
impl PartialOrd<Rational> for Int
[src]
impl PartialOrd<Rational> for Int
[src]fn partial_cmp(&self, other: &Rational) -> Option<Ordering>
[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]
#[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]
#[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
impl<'a> SubAssign<&'a Rational> for Rational
[src]
impl<'a> SubAssign<&'a Rational> for Rational
[src]fn sub_assign(&mut self, other: &'a Rational)
[src]
fn sub_assign(&mut self, other: &'a Rational)
[src]Performs the -=
operation. Read more
impl SubAssign<Rational> for Rational
[src]
impl SubAssign<Rational> for Rational
[src]fn sub_assign(&mut self, other: Rational)
[src]
fn sub_assign(&mut self, other: Rational)
[src]Performs the -=
operation. Read more
impl Eq 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> BorrowMut<T> for T where
T: ?Sized,
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]pub fn borrow_mut(&mut self) -> &mut T
[src]
pub fn borrow_mut(&mut self) -> &mut T
[src]Mutably borrows from an owned value. Read more
impl<T> ToOwned for T where
T: Clone,
[src]
impl<T> ToOwned for T where
T: Clone,
[src]type Owned = T
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
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]
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<V, T> VZip<V> for T where
V: MultiLane<T>,
impl<V, T> VZip<V> for T where
V: MultiLane<T>,