pub struct PerU16(/* private fields */);Expand description
A fixed point representation of a number in the range [0, 1].
Parts per 65535
Implementations§
Source§impl PerU16
impl PerU16
Sourcepub const fn from_parts(parts: u16) -> Self
pub const fn from_parts(parts: u16) -> Self
From an explicitly defined number of parts per maximum of the type.
Sourcepub const fn from_percent(x: u16) -> Self
pub const fn from_percent(x: u16) -> Self
Converts a percent into Self. Equal to x / 100.
This can be created at compile time.
Sourcepub const fn one() -> Self
pub const fn one() -> Self
See PerThing::one
Sourcepub fn is_one(&self) -> bool
pub fn is_one(&self) -> bool
See PerThing::is_one.
Sourcepub const fn zero() -> Self
pub const fn zero() -> Self
See PerThing::zero.
Sourcepub fn is_zero(&self) -> bool
pub fn is_zero(&self) -> bool
See PerThing::is_zero.
Sourcepub const fn deconstruct(self) -> u16
pub const fn deconstruct(self) -> u16
Sourcepub fn square(self) -> Self
pub fn square(self) -> Self
See PerThing::square.
Sourcepub fn from_fraction(x: f64) -> Self
pub fn from_fraction(x: f64) -> Self
Sourcepub fn from_rational_approximation<N>(p: N, q: N) -> Self
pub fn from_rational_approximation<N>(p: N, q: N) -> Self
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
Trait Implementations§
Source§impl CompactAs for PerU16
Implementation makes any compact encoding of PerThing::Inner valid,
when decoding it will saturate up to PerThing::ACCURACY.
impl CompactAs for PerU16
Implementation makes any compact encoding of PerThing::Inner valid,
when decoding it will saturate up to PerThing::ACCURACY.
Source§impl Decode for PerU16
impl Decode for PerU16
Source§impl<'de> Deserialize<'de> for PerU16
impl<'de> Deserialize<'de> for PerU16
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl Encode for PerU16
impl Encode for PerU16
Source§fn encode_to<__CodecOutputEdqy: Output + ?Sized>(
&self,
__codec_dest_edqy: &mut __CodecOutputEdqy,
)
fn encode_to<__CodecOutputEdqy: Output + ?Sized>( &self, __codec_dest_edqy: &mut __CodecOutputEdqy, )
Source§fn using_encoded<R, F: FnOnce(&[u8]) -> R>(&self, f: F) -> R
fn using_encoded<R, F: FnOnce(&[u8]) -> R>(&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<N> Mul<N> for PerU16
Non-overflow multiplication.
impl<N> Mul<N> for PerU16
Non-overflow multiplication.
This is tailored to be used with a balance type.
Source§impl Ord for PerU16
impl Ord for PerU16
Source§impl PartialOrd for PerU16
impl PartialOrd for PerU16
Source§impl PerThing for PerU16
impl PerThing for PerU16
Source§fn deconstruct(self) -> Self::Inner
fn deconstruct(self) -> Self::Inner
Consume self and return the number of parts per thing.
Source§fn from_parts(parts: Self::Inner) -> Self
fn from_parts(parts: Self::Inner) -> Self
Build this type from a number of parts per thing.
Source§fn from_fraction(x: f64) -> Self
fn from_fraction(x: f64) -> Self
NOTE: saturate to 0 or 1 if x is beyond [0, 1]
Source§const ACCURACY: Self::Inner = {transmute(0xffff): <per_things::PerU16 as per_things::PerThing>::Inner}
const ACCURACY: Self::Inner = {transmute(0xffff): <per_things::PerU16 as per_things::PerThing>::Inner}
Source§type Upper = u32
type Upper = u32
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) -> Self
fn from_rational_approximation<N>(p: N, q: N) -> Self
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 PerU16
impl Saturating for PerU16
Source§fn saturating_add(self, rhs: Self) -> Self
fn saturating_add(self, rhs: Self) -> Self
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: Self) -> Self
fn saturating_sub(self, rhs: Self) -> Self
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: Self) -> Self
fn saturating_mul(self, rhs: Self) -> Self
Saturating multiply. Compute self * rhs, saturating at the numeric bounds instead of
overflowing. This operation is lossy.
Source§fn saturating_pow(self, exp: usize) -> Self
fn saturating_pow(self, exp: usize) -> Self
Saturating exponentiation. Computes self.pow(exp), saturating at the numeric
bounds instead of overflowing. This operation is lossy.
impl Copy for PerU16
impl EncodeLike for PerU16
impl Eq for PerU16
impl StructuralPartialEq for PerU16
Auto Trait Implementations§
impl Freeze for PerU16
impl RefUnwindSafe for PerU16
impl Send for PerU16
impl Sync for PerU16
impl Unpin for PerU16
impl UnwindSafe for PerU16
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> 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> HasCompact for T
impl<T> HasCompact 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<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.