Struct sp_runtime::Rational128
source · pub struct Rational128(/* private fields */);
Expand description
Re-export top-level arithmetic stuff. A wrapper for any rational number with a 128 bit numerator and denominator.
Implementations§
source§impl Rational128
impl Rational128
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) -> Option<Rational128>
pub fn to_den(self, den: u128) -> Option<Rational128>
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: &Rational128) -> Option<u128>
pub fn lcm(&self, other: &Rational128) -> 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: 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§
source§impl Bounded for Rational128
impl Bounded for Rational128
source§fn min_value() -> Rational128
fn min_value() -> Rational128
source§fn max_value() -> Rational128
fn max_value() -> 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<T> From<T> for Rational128
impl<T> From<T> for Rational128
source§fn from(t: T) -> Rational128
fn from(t: T) -> Rational128
source§impl Ord for Rational128
impl Ord for Rational128
source§fn cmp(&self, other: &Rational128) -> Ordering
fn cmp(&self, other: &Rational128) -> Ordering
1.21.0 · source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
source§impl PartialEq for Rational128
impl PartialEq for Rational128
source§fn eq(&self, other: &Rational128) -> bool
fn eq(&self, other: &Rational128) -> bool
self
and other
values to be equal, and is used
by ==
.source§impl PartialOrd for Rational128
impl PartialOrd for Rational128
source§fn partial_cmp(&self, other: &Rational128) -> Option<Ordering>
fn partial_cmp(&self, other: &Rational128) -> Option<Ordering>
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> CheckedConversion for T
impl<T> CheckedConversion for T
source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T, Outer> IsWrappedBy<Outer> for T
impl<T, Outer> IsWrappedBy<Outer> for 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<S, T> UncheckedInto<T> for Swhere
T: UncheckedFrom<S>,
impl<S, T> UncheckedInto<T> for Swhere
T: UncheckedFrom<S>,
source§fn unchecked_into(self) -> T
fn unchecked_into(self) -> T
unchecked_from
.source§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
.