Struct sp_runtime::Perquintill
source · [−]pub struct Perquintill(_);
Expand description
Re-export top-level arithmetic stuff. A fixed point representation of a number in the range [0, 1].
Parts per Quintillion
Implementations
Re-export top-level arithmetic stuff.
Converts a percent into Self
. Equal to x / 1000
.
This can be created at compile time.
Re-export top-level arithmetic stuff.
From an explicitly defined number of parts per maximum of the type.
Converts a percent into Self
. Equal to x / 100
.
This can be created at compile time.
See PerThing::one
See PerThing::is_one
.
See PerThing::zero
.
See PerThing::is_zero
.
See PerThing::square
.
See PerThing::from_float
.
pub fn from_rational_approximation<N>(p: N, q: N) -> Perquintill where
N: Clone + Ord + TryInto<u64> + TryInto<u128> + Div<N, Output = N> + Rem<N, Output = N> + Add<N, Output = N> + Unsigned,
u64: Into<N>,
👎 Deprecated: Use PerThing::from_rational
instead
pub fn from_rational_approximation<N>(p: N, q: N) -> Perquintill where
N: Clone + Ord + TryInto<u64> + TryInto<u128> + Div<N, Output = N> + Rem<N, Output = N> + Add<N, Output = N> + Unsigned,
u64: Into<N>,
Use PerThing::from_rational
instead
See PerThing::mul_floor
.
See PerThing::mul_ceil
.
pub fn saturating_reciprocal_mul<N>(self, b: N) -> N where
N: Clone + UniqueSaturatedInto<u64> + Rem<N, Output = N> + Div<N, Output = N> + Mul<N, Output = N> + Add<N, Output = N> + Saturating + Unsigned,
u64: Into<N>,
pub fn saturating_reciprocal_mul<N>(self, b: N) -> N where
N: Clone + UniqueSaturatedInto<u64> + Rem<N, Output = N> + Div<N, Output = N> + Mul<N, Output = N> + Add<N, Output = N> + Saturating + Unsigned,
u64: Into<N>,
pub fn saturating_reciprocal_mul_floor<N>(self, b: N) -> N where
N: Clone + UniqueSaturatedInto<u64> + Rem<N, Output = N> + Div<N, Output = N> + Mul<N, Output = N> + Add<N, Output = N> + Saturating + Unsigned,
u64: Into<N>,
pub fn saturating_reciprocal_mul_floor<N>(self, b: N) -> N where
N: Clone + UniqueSaturatedInto<u64> + Rem<N, Output = N> + Div<N, Output = N> + Mul<N, Output = N> + Add<N, Output = N> + Saturating + Unsigned,
u64: Into<N>,
pub fn saturating_reciprocal_mul_ceil<N>(self, b: N) -> N where
N: Clone + UniqueSaturatedInto<u64> + Rem<N, Output = N> + Div<N, Output = N> + Mul<N, Output = N> + Add<N, Output = N> + Saturating + Unsigned,
u64: Into<N>,
pub fn saturating_reciprocal_mul_ceil<N>(self, b: N) -> N where
N: Clone + UniqueSaturatedInto<u64> + Rem<N, Output = N> + Div<N, Output = N> + Mul<N, Output = N> + Add<N, Output = N> + Saturating + Unsigned,
u64: Into<N>,
Trait Implementations
type Output = Perquintill
type Output = Perquintill
The resulting type after applying the +
operator.
Performs the +
operation. Read more
returns the smallest finite number this type can represent
returns the largest finite number this type can represent
Adds two numbers, checking for overflow. If overflow happens, None
is
returned. Read more
Note
CheckedMul will never fail for PerThings.
Multiplies two numbers, checking for underflow or overflow. If underflow
or overflow happens, None
is returned. Read more
Subtracts two numbers, checking for underflow. If underflow happens,
None
is returned. Read more
Implementation makes any compact encoding of PerThing::Inner
valid,
when decoding it will saturate up to PerThing::ACCURACY
.
Returns the compact-encodable type.
Decode Self
from the compact-decoded type.
Returns the “default value” for a type. Read more
pub fn deserialize<__D>(
__deserializer: __D
) -> Result<Perquintill, <__D as Deserializer<'de>>::Error> where
__D: Deserializer<'de>,
pub fn deserialize<__D>(
__deserializer: __D
) -> Result<Perquintill, <__D as Deserializer<'de>>::Error> where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
type Output = Perquintill
type Output = Perquintill
The resulting type after applying the /
operator.
type Output = Perquintill
type Output = Perquintill
The resulting type after applying the /
operator.
Performs the /
operation. Read more
Performs the conversion.
Non-overflow multiplication.
This is tailored to be used with a balance type.
type Output = Perquintill
type Output = Perquintill
The resulting type after applying the *
operator.
Performs the *
operation. Read more
This method tests for self
and other
values to be equal, and is used
by ==
. Read more
This method tests for !=
.
This method returns an ordering between self
and other
values if one exists. Read more
This method tests less than (for self
and other
) and is used by the <
operator. Read more
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
Consume self and return the number of parts per thing.
Build this type from a number of parts per thing.
NOTE: saturate to 0 or 1 if x is beyond [0, 1]
A data type larger than Self::Inner
, used to avoid overflow in some computations.
It must be able to compute ACCURACY^2
. Read more
The accuracy of this type.
pub fn from_rational<N>(p: N, q: N) -> Perquintill where
N: Clone + Ord + TryInto<<Perquintill as PerThing>::Inner> + TryInto<<Perquintill as PerThing>::Upper> + Div<N, Output = N> + Rem<N, Output = N> + Add<N, Output = N> + Unsigned + Zero + One,
<Perquintill as PerThing>::Inner: Into<N>,
pub fn from_rational<N>(p: N, q: N) -> Perquintill where
N: Clone + Ord + TryInto<<Perquintill as PerThing>::Inner> + TryInto<<Perquintill as PerThing>::Upper> + Div<N, Output = N> + Rem<N, Output = N> + Add<N, Output = N> + Unsigned + Zero + One,
<Perquintill as PerThing>::Inner: Into<N>,
Approximate the fraction p/q
into a per-thing fraction. This will never overflow. Read more
Build this type from a percent. Equivalent to Self::from_parts(x * Self::ACCURACY / 100)
but more accurate and can cope with potential type overflows. Read more
Return the part left when self
is saturating-subtracted from Self::one()
.
Multiplication that always rounds down to a whole number. The standard Mul
rounds to the
nearest whole number. Read more
Multiplication that always rounds the result up to a whole number. The standard Mul
rounds to the nearest whole number. Read more
fn saturating_reciprocal_mul<N>(self, b: N) -> N where
N: Clone + UniqueSaturatedInto<Self::Inner> + Rem<N, Output = N> + Div<N, Output = N> + Mul<N, Output = N> + Add<N, Output = N> + Saturating + Unsigned,
Self::Inner: Into<N>,
fn saturating_reciprocal_mul<N>(self, b: N) -> N where
N: Clone + UniqueSaturatedInto<Self::Inner> + Rem<N, Output = N> + Div<N, Output = N> + Mul<N, Output = N> + Add<N, Output = N> + Saturating + Unsigned,
Self::Inner: Into<N>,
Saturating multiplication by the reciprocal of self
. The result is rounded to the
nearest whole number and saturates at the numeric bounds instead of overflowing. Read more
fn saturating_reciprocal_mul_floor<N>(self, b: N) -> N where
N: Clone + UniqueSaturatedInto<Self::Inner> + Rem<N, Output = N> + Div<N, Output = N> + Mul<N, Output = N> + Add<N, Output = N> + Saturating + Unsigned,
Self::Inner: Into<N>,
fn saturating_reciprocal_mul_floor<N>(self, b: N) -> N where
N: Clone + UniqueSaturatedInto<Self::Inner> + Rem<N, Output = N> + Div<N, Output = N> + Mul<N, Output = N> + Add<N, Output = N> + Saturating + Unsigned,
Self::Inner: Into<N>,
Saturating multiplication by the reciprocal of self
. The result is rounded down to the
nearest whole number and saturates at the numeric bounds instead of overflowing. Read more
fn saturating_reciprocal_mul_ceil<N>(self, b: N) -> N where
N: Clone + UniqueSaturatedInto<Self::Inner> + Rem<N, Output = N> + Div<N, Output = N> + Mul<N, Output = N> + Add<N, Output = N> + Saturating + Unsigned,
Self::Inner: Into<N>,
fn saturating_reciprocal_mul_ceil<N>(self, b: N) -> N where
N: Clone + UniqueSaturatedInto<Self::Inner> + Rem<N, Output = N> + Div<N, Output = N> + Mul<N, Output = N> + Add<N, Output = N> + Saturating + Unsigned,
Self::Inner: Into<N>,
Saturating multiplication by the reciprocal of self
. The result is rounded up to the
nearest whole number and saturates at the numeric bounds instead of overflowing. Read more
Use from_float instead
Same as Self::from_float
.
Use from_rational instead
Same as Self::from_rational
.
type Output = Perquintill
type Output = Perquintill
The result after applying the operator.
Saturating addition. Compute self + rhs
, saturating at the numeric bounds instead of
overflowing. This operation is lossless if it does not saturate.
Saturating subtraction. Compute self - rhs
, saturating at the numeric bounds instead of
overflowing. This operation is lossless if it does not saturate.
Saturating multiply. Compute self * rhs
, saturating at the numeric bounds instead of
overflowing. This operation is lossy.
Saturating exponentiation. Computes self.pow(exp)
, saturating at the numeric
bounds instead of overflowing. This operation is lossy.
Increment self by one, saturating.
Decrement self by one, saturating at zero.
Increment self by some amount
, saturating.
Decrement self by some amount
, saturating at zero.
Saturating addition. Computes self + other
, saturating at the relevant high or low boundary of
the type. Read more
Saturating subtraction. Computes self - other
, saturating at the relevant high or low boundary of
the type. Read more
pub fn serialize<__S>(
&self,
__serializer: __S
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error> where
__S: Serializer,
pub fn serialize<__S>(
&self,
__serializer: __S
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error> where
__S: Serializer,
Serialize this value into the given Serde serializer. Read more
type Output = Perquintill
type Output = Perquintill
The resulting type after applying the -
operator.
Performs the -
operation. Read more
Auto Trait Implementations
impl RefUnwindSafe for Perquintill
impl Send for Perquintill
impl Sync for Perquintill
impl Unpin for Perquintill
impl UnwindSafe for Perquintill
Blanket Implementations
Mutably borrows from an owned value. Read more
pub fn into_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>ⓘimpl<W> Write for Box<W, Global> where
W: Write + ?Sized, impl<R> Read for Box<R, Global> where
R: Read + ?Sized, impl<I, A> Iterator for Box<I, A> where
I: Iterator + ?Sized,
A: Allocator, type Item = <I as Iterator>::Item;impl<F, A> Future for Box<F, A> where
F: Future + Unpin + ?Sized,
A: Allocator + 'static, type Output = <F as Future>::Output;
pub fn into_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>ⓘimpl<W> Write for Box<W, Global> where
W: Write + ?Sized, impl<R> Read for Box<R, Global> where
R: Read + ?Sized, impl<I, A> Iterator for Box<I, A> where
I: Iterator + ?Sized,
A: Allocator, type Item = <I as Iterator>::Item;impl<F, A> Future for Box<F, A> where
F: Future + Unpin + ?Sized,
A: Allocator + 'static, type Output = <F as Future>::Output;
impl<W> Write for Box<W, Global> where
W: Write + ?Sized, impl<R> Read for Box<R, Global> where
R: Read + ?Sized, impl<I, A> Iterator for Box<I, A> where
I: Iterator + ?Sized,
A: Allocator, type Item = <I as Iterator>::Item;impl<F, A> Future for Box<F, A> where
F: Future + Unpin + ?Sized,
A: Allocator + 'static, type Output = <F as Future>::Output;
Convert Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
. Read more
Convert Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
. Read more
Convert &Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s. Read more
Convert &mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s. Read more
impl<T> HasCompact for T where
T: 'static,
Compact<T>: for<'a> EncodeAsRef<'a, T>,
Compact<T>: Decode,
Compact<T>: From<T>,
Compact<T>: Into<T>,
impl<T> HasCompact for T where
T: 'static,
Compact<T>: for<'a> EncodeAsRef<'a, T>,
Compact<T>: Decode,
Compact<T>: From<T>,
Compact<T>: Into<T>,
The counterpart to unchecked_from
.
Convert from a value of T
into an equivalent instance of Self
.
Consume self to return an equivalent value of T
.
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more