Struct sp_arithmetic::rational::Rational128
source · [−]pub struct Rational128(_, _);
Expand description
A wrapper for any rational number with a 128 bit numerator and denominator.
Implementations
sourceimpl Rational128
impl Rational128
sourcepub fn from_unchecked(n: u128, d: u128) -> Self
pub fn from_unchecked(n: u128, d: u128) -> Self
Build from a raw n/d
. This could lead to / 0 if not properly handled.
sourcepub fn to_den(self, den: u128) -> Result<Self, &'static str>
pub fn to_den(self, den: u128) -> Result<Self, &'static str>
Convert self
to a similar rational number where denominator is the given den
.
This only returns if the result is accurate. Err
is returned if the result cannot be
accurately calculated.
sourcepub fn lcm(&self, other: &Self) -> Result<u128, &'static str>
pub fn lcm(&self, other: &Self) -> Result<u128, &'static str>
Get the least common divisor of self
and other
.
This only returns if the result is accurate. Err
is returned if the result cannot be
accurately calculated.
sourcepub fn lazy_saturating_add(self, other: Self) -> Self
pub fn lazy_saturating_add(self, other: Self) -> Self
A saturating add that assumes self
and other
have the same denominator.
sourcepub fn lazy_saturating_sub(self, other: Self) -> Self
pub fn lazy_saturating_sub(self, other: Self) -> Self
A saturating subtraction that assumes self
and other
have the same denominator.
sourcepub fn checked_add(self, other: Self) -> Result<Self, &'static str>
pub fn checked_add(self, other: Self) -> Result<Self, &'static str>
Addition. Simply tries to unify the denominators and add the numerators.
Overflow might happen during any of the steps. Error is returned in such cases.
sourcepub fn checked_sub(self, other: Self) -> Result<Self, &'static str>
pub fn checked_sub(self, other: Self) -> Result<Self, &'static str>
Subtraction. Simply tries to unify the denominators and subtract the numerators.
Overflow might happen during any of the steps. None is returned in such cases.
Trait Implementations
sourceimpl Bounded for Rational128
impl Bounded for Rational128
sourceimpl Clone for Rational128
impl Clone for Rational128
sourcefn clone(&self) -> Rational128
fn clone(&self) -> Rational128
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
sourceimpl Debug for Rational128
impl Debug for Rational128
sourceimpl Default for Rational128
impl Default for Rational128
sourcefn default() -> Rational128
fn default() -> Rational128
Returns the “default value” for a type. Read more
sourceimpl From<Rational128> for RationalInfinite
impl From<Rational128> for RationalInfinite
sourcefn from(t: Rational128) -> Self
fn from(t: Rational128) -> Self
Performs the conversion.
sourceimpl<T: Into<u128>> From<T> for Rational128
impl<T: Into<u128>> From<T> for Rational128
sourceimpl Ord for Rational128
impl Ord for Rational128
sourceimpl PartialEq<Rational128> for Rational128
impl PartialEq<Rational128> for Rational128
sourceimpl PartialOrd<Rational128> for Rational128
impl PartialOrd<Rational128> for Rational128
sourcefn partial_cmp(&self, other: &Self) -> Option<Ordering>
fn partial_cmp(&self, other: &Self) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
1.0.0 · sourcefn lt(&self, other: &Rhs) -> bool
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
impl Copy for Rational128
impl Eq for Rational128
impl StructuralEq for Rational128
Auto Trait Implementations
impl RefUnwindSafe for Rational128
impl Send for Rational128
impl Sync for Rational128
impl Unpin for Rational128
impl UnwindSafe for Rational128
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> SaturatedConversion for T
impl<T> SaturatedConversion for T
sourcefn saturated_from<T>(t: T) -> Self where
Self: UniqueSaturatedFrom<T>,
fn saturated_from<T>(t: T) -> Self where
Self: UniqueSaturatedFrom<T>,
Convert from a value of T
into an equivalent instance of Self
. Read more
sourcefn saturated_into<T>(self) -> T where
Self: UniqueSaturatedInto<T>,
fn saturated_into<T>(self) -> T where
Self: UniqueSaturatedInto<T>,
Consume self to return an equivalent value of T
. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcepub fn to_owned(&self) -> T
pub fn to_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. Read more
sourcepub fn clone_into(&self, target: &mut T)
pub fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more
sourceimpl<T, S> UniqueSaturatedFrom<T> for S where
S: TryFrom<T> + Bounded,
impl<T, S> UniqueSaturatedFrom<T> for S where
S: TryFrom<T> + Bounded,
sourcefn unique_saturated_from(t: T) -> Self
fn unique_saturated_from(t: T) -> Self
Convert from a value of T
into an equivalent instance of Self
.
sourceimpl<T, S> UniqueSaturatedInto<T> for S where
T: Bounded,
S: TryInto<T>,
impl<T, S> UniqueSaturatedInto<T> for S where
T: Bounded,
S: TryInto<T>,
sourcefn unique_saturated_into(self) -> T
fn unique_saturated_into(self) -> T
Consume self to return an equivalent value of T
.