pub struct Perquintill(/* private fields */);
Expand description
Re-export top-level arithmetic stuff. A fixed point representation of a number in the range [0, 1].
Parts per Quintillion
Implementations§
Source§impl Perquintill
impl Perquintill
Sourcepub const fn from_parts(parts: u64) -> Perquintill
pub const fn from_parts(parts: u64) -> Perquintill
From an explicitly defined number of parts per maximum of the type.
Sourcepub const fn from_percent(x: u64) -> Perquintill
pub const fn from_percent(x: u64) -> Perquintill
Converts a percent into Self
. Equal to x / 100
.
This can be created at compile time.
Sourcepub const fn one() -> Perquintill
pub const fn one() -> Perquintill
See PerThing::one
Sourcepub fn is_one(&self) -> bool
pub fn is_one(&self) -> bool
See PerThing::is_one
.
Sourcepub const fn zero() -> Perquintill
pub const fn zero() -> Perquintill
See PerThing::zero
.
Sourcepub fn is_zero(&self) -> bool
pub fn is_zero(&self) -> bool
See PerThing::is_zero
.
Sourcepub const fn deconstruct(self) -> u64
pub const fn deconstruct(self) -> u64
Sourcepub fn square(self) -> Perquintill
pub fn square(self) -> Perquintill
See PerThing::square
.
Sourcepub fn from_fraction(x: f64) -> Perquintill
pub fn from_fraction(x: f64) -> Perquintill
Sourcepub fn from_rational_approximation<N>(p: N, q: N) -> Perquintill
pub fn from_rational_approximation<N>(p: N, q: N) -> Perquintill
Sourcepub fn mul_floor<N>(self, b: N) -> N
pub fn mul_floor<N>(self, b: N) -> N
See PerThing::mul_floor
.
Sourcepub fn mul_ceil<N>(self, b: N) -> N
pub fn mul_ceil<N>(self, b: N) -> N
See PerThing::mul_ceil
.
Sourcepub fn saturating_reciprocal_mul<N>(self, b: N) -> N
pub fn saturating_reciprocal_mul<N>(self, b: N) -> N
Sourcepub fn saturating_reciprocal_mul_floor<N>(self, b: N) -> N
pub fn saturating_reciprocal_mul_floor<N>(self, b: N) -> N
Sourcepub fn saturating_reciprocal_mul_ceil<N>(self, b: N) -> N
pub fn saturating_reciprocal_mul_ceil<N>(self, b: N) -> N
Source§impl Perquintill
impl Perquintill
Sourcepub const fn from_perthousand(x: u64) -> Perquintill
pub const fn from_perthousand(x: u64) -> Perquintill
Converts a percent into Self
. Equal to x / 1000
.
This can be created at compile time.
Trait Implementations§
Source§impl Bounded for Perquintill
impl Bounded for Perquintill
Source§fn min_value() -> Perquintill
fn min_value() -> Perquintill
Source§fn max_value() -> Perquintill
fn max_value() -> Perquintill
Source§impl Clone for Perquintill
impl Clone for Perquintill
Source§fn clone(&self) -> Perquintill
fn clone(&self) -> Perquintill
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl CompactAs for Perquintill
Implementation makes any compact encoding of PerThing::Inner
valid,
when decoding it will saturate up to PerThing::ACCURACY
.
impl CompactAs for Perquintill
Implementation makes any compact encoding of PerThing::Inner
valid,
when decoding it will saturate up to PerThing::ACCURACY
.
Source§fn decode_from(x: <Perquintill as CompactAs>::As) -> Result<Perquintill, Error>
fn decode_from(x: <Perquintill as CompactAs>::As) -> Result<Perquintill, Error>
Self
from the compact-decoded type.Source§impl Debug for Perquintill
impl Debug for Perquintill
Source§impl Decode for Perquintill
impl Decode for Perquintill
Source§impl Default for Perquintill
impl Default for Perquintill
Source§fn default() -> Perquintill
fn default() -> Perquintill
Source§impl<'de> Deserialize<'de> for Perquintill
impl<'de> Deserialize<'de> for Perquintill
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<Perquintill, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<Perquintill, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Source§impl Div for Perquintill
impl Div for Perquintill
Source§type Output = Perquintill
type Output = Perquintill
/
operator.Source§fn div(self, rhs: Perquintill) -> <Perquintill as Div>::Output
fn div(self, rhs: Perquintill) -> <Perquintill as Div>::Output
/
operation. Read moreSource§impl Encode for Perquintill
impl Encode for Perquintill
Source§fn encode_to<__CodecOutputEdqy>(
&self,
__codec_dest_edqy: &mut __CodecOutputEdqy,
)
fn encode_to<__CodecOutputEdqy>( &self, __codec_dest_edqy: &mut __CodecOutputEdqy, )
Source§fn using_encoded<R, F>(&self, f: F) -> R
fn using_encoded<R, F>(&self, f: F) -> R
Source§fn size_hint(&self) -> usize
fn size_hint(&self) -> usize
Source§fn encoded_size(&self) -> usize
fn encoded_size(&self) -> usize
Source§impl From<Compact<Perquintill>> for Perquintill
impl From<Compact<Perquintill>> for Perquintill
Source§fn from(x: Compact<Perquintill>) -> Perquintill
fn from(x: Compact<Perquintill>) -> Perquintill
Source§impl<N> Mul<N> for Perquintill
Non-overflow multiplication.
impl<N> Mul<N> for Perquintill
Non-overflow multiplication.
This is tailored to be used with a balance type.
Source§impl Ord for Perquintill
impl Ord for Perquintill
Source§fn cmp(&self, other: &Perquintill) -> Ordering
fn cmp(&self, other: &Perquintill) -> 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 Perquintill
impl PartialEq for Perquintill
Source§impl PartialOrd for Perquintill
impl PartialOrd for Perquintill
Source§impl PerThing for Perquintill
impl PerThing for Perquintill
Source§fn deconstruct(self) -> <Perquintill as PerThing>::Inner
fn deconstruct(self) -> <Perquintill as PerThing>::Inner
Consume self and return the number of parts per thing.
Source§fn from_parts(parts: <Perquintill as PerThing>::Inner) -> Perquintill
fn from_parts(parts: <Perquintill as PerThing>::Inner) -> Perquintill
Build this type from a number of parts per thing.
Source§fn from_fraction(x: f64) -> Perquintill
fn from_fraction(x: f64) -> Perquintill
NOTE: saturate to 0 or 1 if x is beyond [0, 1]
Source§const ACCURACY: <Perquintill as PerThing>::Inner = {transmute(0x0de0b6b3a7640000): <arithmetic::Perquintill as arithmetic::PerThing>::Inner}
const ACCURACY: <Perquintill as PerThing>::Inner = {transmute(0x0de0b6b3a7640000): <arithmetic::Perquintill as arithmetic::PerThing>::Inner}
Source§type Upper = u128
type Upper = u128
Self::Inner
, used to avoid overflow in some computations.
It must be able to compute ACCURACY^2
.Source§fn from_rational_approximation<N>(p: N, q: N) -> Perquintill
fn from_rational_approximation<N>(p: N, q: N) -> Perquintill
p/q
into a per-thing fraction. This will never overflow. Read moreSource§fn from_percent(x: Self::Inner) -> Self
fn from_percent(x: Self::Inner) -> Self
Self::from_parts(x * Self::ACCURACY / 100)
but more accurate and can cope with potential type overflows.Source§fn mul_floor<N>(self, b: N) -> N
fn mul_floor<N>(self, b: N) -> N
Mul
rounds to the
nearest whole number. Read moreSource§fn mul_ceil<N>(self, b: N) -> N
fn mul_ceil<N>(self, b: N) -> N
Mul
rounds to the nearest whole number. Read moreSource§fn saturating_reciprocal_mul<N>(self, b: N) -> N
fn saturating_reciprocal_mul<N>(self, b: N) -> N
self
. The result is rounded to the
nearest whole number and saturates at the numeric bounds instead of overflowing. Read moreSource§fn saturating_reciprocal_mul_floor<N>(self, b: N) -> N
fn saturating_reciprocal_mul_floor<N>(self, b: N) -> N
self
. The result is rounded down to the
nearest whole number and saturates at the numeric bounds instead of overflowing. Read moreSource§fn saturating_reciprocal_mul_ceil<N>(self, b: N) -> N
fn saturating_reciprocal_mul_ceil<N>(self, b: N) -> N
self
. The result is rounded up to the
nearest whole number and saturates at the numeric bounds instead of overflowing. Read moreSource§impl Saturating for Perquintill
impl Saturating for Perquintill
Source§fn saturating_add(self, rhs: Perquintill) -> Perquintill
fn saturating_add(self, rhs: Perquintill) -> Perquintill
Saturating addition. Compute self + rhs
, saturating at the numeric bounds instead of
overflowing. This operation is lossless if it does not saturate.
Source§fn saturating_sub(self, rhs: Perquintill) -> Perquintill
fn saturating_sub(self, rhs: Perquintill) -> Perquintill
Saturating subtraction. Compute self - rhs
, saturating at the numeric bounds instead of
overflowing. This operation is lossless if it does not saturate.
Source§fn saturating_mul(self, rhs: Perquintill) -> Perquintill
fn saturating_mul(self, rhs: Perquintill) -> Perquintill
Saturating multiply. Compute self * rhs
, saturating at the numeric bounds instead of
overflowing. This operation is lossy.
Source§fn saturating_pow(self, exp: usize) -> Perquintill
fn saturating_pow(self, exp: usize) -> Perquintill
Saturating exponentiation. Computes self.pow(exp)
, saturating at the numeric
bounds instead of overflowing. This operation is lossy.
Source§impl Serialize for Perquintill
impl Serialize for Perquintill
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
impl Copy for Perquintill
impl EncodeLike for Perquintill
impl Eq for Perquintill
impl StructuralPartialEq for Perquintill
Auto Trait Implementations§
impl Freeze for Perquintill
impl RefUnwindSafe for Perquintill
impl Send for Perquintill
impl Sync for Perquintill
impl Unpin for Perquintill
impl UnwindSafe for Perquintill
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<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> DecodeLimit for Twhere
T: Decode,
impl<T> DecodeLimit for Twhere
T: Decode,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
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
.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> HasCompact for T
impl<T> HasCompact for T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§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
.