Struct sp_arithmetic::rational::Rational128 [−][src]
pub struct Rational128(_, _);
A wrapper for any rational number with a 128 bit numerator and denominator.
Implementations
impl Rational128[src]
impl Rational128[src]pub fn zero() -> Self[src]
Zero.
pub fn one() -> Self[src]
One
pub fn is_zero(&self) -> bool[src]
If it is zero or not
pub fn from(n: u128, d: u128) -> Self[src]
Build from a raw n/d.
pub fn from_unchecked(n: u128, d: u128) -> Self[src]
Build from a raw n/d. This could lead to / 0 if not properly handled.
pub fn n(&self) -> u128[src]
Return the numerator.
pub fn d(&self) -> u128[src]
Return the denominator.
pub fn to_den(self, den: u128) -> Result<Self, &'static str>[src]
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.
pub fn lcm(&self, other: &Self) -> Result<u128, &'static str>[src]
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.
pub fn lazy_saturating_add(self, other: Self) -> Self[src]
A saturating add that assumes self and other have the same denominator.
pub fn lazy_saturating_sub(self, other: Self) -> Self[src]
A saturating subtraction that assumes self and other have the same denominator.
pub fn checked_add(self, other: Self) -> Result<Self, &'static str>[src]
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.
pub fn checked_sub(self, other: Self) -> Result<Self, &'static str>[src]
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
impl Clone for Rational128[src]
impl Clone for Rational128[src]fn clone(&self) -> Rational128[src]
pub fn clone_from(&mut self, source: &Self)1.0.0[src]
impl Default for Rational128[src]
impl Default for Rational128[src]fn default() -> Rational128[src]
impl From<Rational128> for RationalInfinite[src]
impl From<Rational128> for RationalInfinite[src]fn from(t: Rational128) -> Self[src]
impl Ord for Rational128[src]
impl Ord for Rational128[src]impl PartialEq<Rational128> for Rational128[src]
impl PartialEq<Rational128> for Rational128[src]impl PartialOrd<Rational128> for Rational128[src]
impl PartialOrd<Rational128> for Rational128[src]impl Copy for Rational128[src]
impl Eq for Rational128[src]
impl StructuralEq for Rational128[src]
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
impl<T> SaturatedConversion for T[src]
impl<T> SaturatedConversion for T[src]fn saturated_from<T>(t: T) -> Self where
Self: UniqueSaturatedFrom<T>, [src]
Self: UniqueSaturatedFrom<T>,
fn saturated_into<T>(self) -> T where
Self: UniqueSaturatedInto<T>, [src]
Self: UniqueSaturatedInto<T>,
impl<T, S> UniqueSaturatedFrom<T> for S where
S: TryFrom<T> + Bounded, [src]
impl<T, S> UniqueSaturatedFrom<T> for S where
S: TryFrom<T> + Bounded, [src]pub fn unique_saturated_from(T) -> S[src]
impl<T, S> UniqueSaturatedInto<T> for S where
T: Bounded,
S: TryInto<T>, [src]
impl<T, S> UniqueSaturatedInto<T> for S where
T: Bounded,
S: TryInto<T>, [src]