Struct sp_arithmetic::rational::Rational128
source · pub struct Rational128(/* private fields */);
Expand description
A wrapper for any rational number with a 128 bit numerator and denominator.
Implementations§
source§impl 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) -> Option<Self>
pub fn to_den(self, den: u128) -> Option<Self>
Convert self
to a similar rational number where denominator is the given den
.
This only returns if the result is accurate. None
is returned if the result cannot be
accurately calculated.
sourcepub fn lcm(&self, other: &Self) -> Option<u128>
pub fn lcm(&self, other: &Self) -> Option<u128>
Get the least common divisor of self
and other
.
This only returns if the result is accurate. None
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§
source§impl Bounded for Rational128
impl Bounded for Rational128
source§impl Clone for Rational128
impl Clone for Rational128
source§fn clone(&self) -> Rational128
fn clone(&self) -> Rational128
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for Rational128
impl Debug for Rational128
source§impl Default for Rational128
impl Default for Rational128
source§fn default() -> Rational128
fn default() -> Rational128
source§impl From<Rational128> for RationalInfinite
impl From<Rational128> for RationalInfinite
source§fn from(t: Rational128) -> Self
fn from(t: Rational128) -> Self
source§impl Ord for Rational128
impl Ord for Rational128
source§impl PartialEq for Rational128
impl PartialEq for Rational128
source§impl PartialOrd for Rational128
impl PartialOrd for Rational128
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read moreimpl 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§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> LowerBounded for Twhere
T: Bounded,
impl<T> LowerBounded for Twhere
T: Bounded,
source§impl<T> SaturatedConversion for T
impl<T> SaturatedConversion for T
source§fn saturated_from<T>(t: T) -> Selfwhere
Self: UniqueSaturatedFrom<T>,
fn saturated_from<T>(t: T) -> Selfwhere
Self: UniqueSaturatedFrom<T>,
source§fn saturated_into<T>(self) -> Twhere
Self: UniqueSaturatedInto<T>,
fn saturated_into<T>(self) -> Twhere
Self: UniqueSaturatedInto<T>,
T
. Read moresource§impl<T, S> UniqueSaturatedFrom<T> for S
impl<T, S> UniqueSaturatedFrom<T> for S
source§fn unique_saturated_from(t: T) -> S
fn unique_saturated_from(t: T) -> S
T
into an equivalent instance of Self
.source§impl<T, S> UniqueSaturatedInto<T> for S
impl<T, S> UniqueSaturatedInto<T> for S
source§fn unique_saturated_into(self) -> T
fn unique_saturated_into(self) -> T
T
.