Struct sp_runtime::Rational128
source · [−]pub struct Rational128(_, _);
Expand description
Re-export top-level arithmetic stuff. A wrapper for any rational number with a 128 bit numerator and denominator.
Implementations
sourceimpl Rational128
impl Rational128
Re-export top-level arithmetic stuff.
sourcepub fn zero() -> Rational128
pub fn zero() -> Rational128
Zero.
sourcepub fn one() -> Rational128
pub fn one() -> Rational128
One
sourcepub fn from(n: u128, d: u128) -> Rational128
pub fn from(n: u128, d: u128) -> Rational128
Build from a raw n/d
.
sourcepub fn from_unchecked(n: u128, d: u128) -> Rational128
pub fn from_unchecked(n: u128, d: u128) -> Rational128
Build from a raw n/d
. This could lead to / 0 if not properly handled.
sourcepub fn to_den(self, den: u128) -> Result<Rational128, &'static str>
pub fn to_den(self, den: u128) -> Result<Rational128, &'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: &Rational128) -> Result<u128, &'static str>
pub fn lcm(&self, other: &Rational128) -> 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: Rational128) -> Rational128
pub fn lazy_saturating_add(self, other: Rational128) -> Rational128
A saturating add that assumes self
and other
have the same denominator.
sourcepub fn lazy_saturating_sub(self, other: Rational128) -> Rational128
pub fn lazy_saturating_sub(self, other: Rational128) -> Rational128
A saturating subtraction that assumes self
and other
have the same denominator.
sourcepub fn checked_add(
self,
other: Rational128
) -> Result<Rational128, &'static str>
pub fn checked_add(
self,
other: Rational128
) -> Result<Rational128, &'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: Rational128
) -> Result<Rational128, &'static str>
pub fn checked_sub(
self,
other: Rational128
) -> Result<Rational128, &'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
sourcepub fn min_value() -> Rational128
pub fn min_value() -> Rational128
returns the smallest finite number this type can represent
sourcepub fn max_value() -> Rational128
pub fn max_value() -> Rational128
returns the largest finite number this type can represent
sourceimpl Clone for Rational128
impl Clone for Rational128
sourcepub fn clone(&self) -> Rational128
pub 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
sourcepub fn default() -> Rational128
pub fn default() -> Rational128
Returns the “default value” for a type. Read more
sourceimpl<T> From<T> for Rational128 where
T: Into<u128>,
impl<T> From<T> for Rational128 where
T: Into<u128>,
sourcepub fn from(t: T) -> Rational128
pub fn from(t: T) -> Rational128
Performs the conversion.
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
sourcepub fn partial_cmp(&self, other: &Rational128) -> Option<Ordering>
pub fn partial_cmp(&self, other: &Rational128) -> 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> CheckedConversion for T
impl<T> CheckedConversion for T
sourcefn checked_from<T>(t: T) -> Option<Self> where
Self: TryFrom<T>,
fn checked_from<T>(t: T) -> Option<Self> where
Self: TryFrom<T>,
Convert from a value of T
into an equivalent instance of Option<Self>
. Read more
sourcefn checked_into<T>(self) -> Option<T> where
Self: TryInto<T>,
fn checked_into<T>(self) -> Option<T> where
Self: TryInto<T>,
Consume self to return Some
equivalent value of Option<T>
. Read more
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Instruments this type with the provided Span
, returning an
Instrumented
wrapper. Read more
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
sourceimpl<T, Outer> IsWrappedBy<Outer> for T where
Outer: AsRef<T> + AsMut<T> + From<T>,
T: From<Outer>,
impl<T, Outer> IsWrappedBy<Outer> for T where
Outer: AsRef<T> + AsMut<T> + From<T>,
T: From<Outer>,
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<S, T> UncheckedInto<T> for S where
T: UncheckedFrom<S>,
impl<S, T> UncheckedInto<T> for S where
T: UncheckedFrom<S>,
sourcepub fn unchecked_into(self) -> T
pub fn unchecked_into(self) -> T
The counterpart to unchecked_from
.
sourceimpl<T, S> UniqueSaturatedFrom<T> for S where
S: TryFrom<T> + Bounded,
impl<T, S> UniqueSaturatedFrom<T> for S where
S: TryFrom<T> + Bounded,
sourcepub fn unique_saturated_from(t: T) -> S
pub fn unique_saturated_from(t: T) -> S
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>,
sourcepub fn unique_saturated_into(self) -> T
pub fn unique_saturated_into(self) -> T
Consume self to return an equivalent value of T
.