pub trait FixedPointNumber:
Sized
+ Copy
+ Default
+ Debug
+ Saturating
+ Bounded
+ Eq
+ PartialEq
+ Ord
+ PartialOrd
+ CheckedSub
+ CheckedAdd
+ CheckedMul
+ CheckedDiv
+ Add
+ Sub
+ Div
+ Mul
+ Zero
+ One {
type Inner: Debug + One + CheckedMul + CheckedDiv + FixedPointOperand;
const DIV: Self::Inner;
const SIGNED: bool;
Show 23 methods
// Required methods
fn from_inner(int: Self::Inner) -> Self;
fn into_inner(self) -> Self::Inner;
fn checked_sqrt(self) -> Option<Self>;
// Provided methods
fn accuracy() -> Self::Inner { ... }
fn saturating_from_integer<N: FixedPointOperand>(int: N) -> Self { ... }
fn checked_from_integer<N: Into<Self::Inner>>(int: N) -> Option<Self> { ... }
fn saturating_from_rational<N: FixedPointOperand, D: FixedPointOperand>(
n: N,
d: D,
) -> Self { ... }
fn checked_from_rational<N: FixedPointOperand, D: FixedPointOperand>(
n: N,
d: D,
) -> Option<Self> { ... }
fn checked_mul_int<N: FixedPointOperand>(self, n: N) -> Option<N> { ... }
fn saturating_mul_int<N: FixedPointOperand>(self, n: N) -> N { ... }
fn checked_div_int<N: FixedPointOperand>(self, d: N) -> Option<N> { ... }
fn saturating_div_int<N: FixedPointOperand>(self, d: N) -> N { ... }
fn saturating_mul_acc_int<N: FixedPointOperand>(self, n: N) -> N { ... }
fn saturating_abs(self) -> Self { ... }
fn reciprocal(self) -> Option<Self> { ... }
fn is_one(&self) -> bool { ... }
fn is_positive(self) -> bool { ... }
fn is_negative(self) -> bool { ... }
fn trunc(self) -> Self { ... }
fn frac(self) -> Self { ... }
fn ceil(self) -> Self { ... }
fn floor(self) -> Self { ... }
fn round(self) -> Self { ... }
}Expand description
Something that implements a decimal fixed point number.
The precision is given by Self::DIV, i.e. 1 / DIV can be represented.
Each type can store numbers from Self::Inner::min_value() / Self::DIV
to Self::Inner::max_value() / Self::DIV.
This is also referred to as the accuracy of the type in the documentation.
Required Associated Constants§
Required Associated Types§
Sourcetype Inner: Debug + One + CheckedMul + CheckedDiv + FixedPointOperand
type Inner: Debug + One + CheckedMul + CheckedDiv + FixedPointOperand
The underlying data type used for this fixed point number.
Required Methods§
Sourcefn from_inner(int: Self::Inner) -> Self
fn from_inner(int: Self::Inner) -> Self
Builds this type from an integer number.
Sourcefn into_inner(self) -> Self::Inner
fn into_inner(self) -> Self::Inner
Consumes self and returns the inner raw value.
Sourcefn checked_sqrt(self) -> Option<Self>
fn checked_sqrt(self) -> Option<Self>
Compute the square root. If it overflows or is negative, then None is returned.
Provided Methods§
Sourcefn saturating_from_integer<N: FixedPointOperand>(int: N) -> Self
fn saturating_from_integer<N: FixedPointOperand>(int: N) -> Self
Creates self from an integer number int.
Returns Self::max or Self::min if int exceeds accuracy.
Sourcefn checked_from_integer<N: Into<Self::Inner>>(int: N) -> Option<Self>
fn checked_from_integer<N: Into<Self::Inner>>(int: N) -> Option<Self>
Creates self from an integer number int.
Returns None if int exceeds accuracy.
Sourcefn saturating_from_rational<N: FixedPointOperand, D: FixedPointOperand>(
n: N,
d: D,
) -> Self
fn saturating_from_rational<N: FixedPointOperand, D: FixedPointOperand>( n: N, d: D, ) -> Self
Creates self from a rational number. Equal to n / d.
Panics if d = 0. Returns Self::max or Self::min if n / d exceeds accuracy.
Sourcefn checked_from_rational<N: FixedPointOperand, D: FixedPointOperand>(
n: N,
d: D,
) -> Option<Self>
fn checked_from_rational<N: FixedPointOperand, D: FixedPointOperand>( n: N, d: D, ) -> Option<Self>
Creates self from a rational number. Equal to n / d.
Returns None if d == 0 or n / d exceeds accuracy.
Sourcefn checked_mul_int<N: FixedPointOperand>(self, n: N) -> Option<N>
fn checked_mul_int<N: FixedPointOperand>(self, n: N) -> Option<N>
Checked multiplication for integer type N. Equal to self * n.
Returns None if the result does not fit in N.
Sourcefn saturating_mul_int<N: FixedPointOperand>(self, n: N) -> N
fn saturating_mul_int<N: FixedPointOperand>(self, n: N) -> N
Saturating multiplication for integer type N. Equal to self * n.
Returns N::min or N::max if the result does not fit in N.
Sourcefn checked_div_int<N: FixedPointOperand>(self, d: N) -> Option<N>
fn checked_div_int<N: FixedPointOperand>(self, d: N) -> Option<N>
Checked division for integer type N. Equal to self / d.
Returns None if the result does not fit in N or d == 0.
Sourcefn saturating_div_int<N: FixedPointOperand>(self, d: N) -> N
fn saturating_div_int<N: FixedPointOperand>(self, d: N) -> N
Saturating division for integer type N. Equal to self / d.
Panics if d == 0. Returns N::min or N::max if the result does not fit in N.
Sourcefn saturating_mul_acc_int<N: FixedPointOperand>(self, n: N) -> N
fn saturating_mul_acc_int<N: FixedPointOperand>(self, n: N) -> N
Saturating multiplication for integer type N, adding the result back.
Equal to self * n + n.
Returns N::min or N::max if the multiplication or final result does not fit in N.
Sourcefn saturating_abs(self) -> Self
fn saturating_abs(self) -> Self
Saturating absolute value.
Returns Self::max if self == Self::min.
Sourcefn reciprocal(self) -> Option<Self>
fn reciprocal(self) -> Option<Self>
Takes the reciprocal (inverse). Equal to 1 / self.
Returns None if self = 0.
Sourcefn is_positive(self) -> bool
fn is_positive(self) -> bool
Returns true if self is positive and false if the number is zero or negative.
Sourcefn is_negative(self) -> bool
fn is_negative(self) -> bool
Returns true if self is negative and false if the number is zero or positive.
Sourcefn frac(self) -> Self
fn frac(self) -> Self
Returns the fractional part.
Note: the returned fraction will be non-negative for negative numbers, except in the case where the integer part is zero.
Sourcefn ceil(self) -> Self
fn ceil(self) -> Self
Returns the smallest integer greater than or equal to a number.
Saturates to Self::max (truncated) if the result does not fit.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".