pub trait FixedPointNumber: Sized + Copy + Default + Debug + Saturating + Bounded + Eq + PartialEq<Self> + Ord + PartialOrd<Self> + CheckedSub + CheckedAdd + CheckedMul + CheckedDiv + Add<Self> + Sub<Self> + Div<Self> + Mul<Self> + Zero + One {
    type Inner: Debug + One + CheckedMul + CheckedDiv + FixedPointOperand;

    const DIV: Self::Inner;
    const SIGNED: bool;
Show 22 methods // Required methods fn from_inner(int: Self::Inner) -> Self; fn into_inner(self) -> Self::Inner; // Provided methods fn accuracy() -> Self::Inner { ... } fn saturating_from_integer<N>(int: N) -> Self where N: FixedPointOperand { ... } fn checked_from_integer<N>(int: N) -> Option<Self> where N: Into<Self::Inner> { ... } fn saturating_from_rational<N, D>(n: N, d: D) -> Self where N: FixedPointOperand, D: FixedPointOperand { ... } fn checked_from_rational<N, D>(n: N, d: D) -> Option<Self> where N: FixedPointOperand, D: FixedPointOperand { ... } fn checked_mul_int<N>(self, n: N) -> Option<N> where N: FixedPointOperand { ... } fn saturating_mul_int<N>(self, n: N) -> N where N: FixedPointOperand { ... } fn checked_div_int<N>(self, d: N) -> Option<N> where N: FixedPointOperand { ... } fn saturating_div_int<N>(self, d: N) -> N where N: FixedPointOperand { ... } fn saturating_mul_acc_int<N>(self, n: N) -> N where N: FixedPointOperand { ... } 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

Re-export top-level arithmetic stuff. 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 Types§

source

type Inner: Debug + One + CheckedMul + CheckedDiv + FixedPointOperand

The underlying data type used for this fixed point number.

Required Associated Constants§

source

const DIV: Self::Inner

Precision of this fixed point implementation. It should be a power of 10.

source

const SIGNED: bool

Indicates if this fixed point implementation is signed or not.

Required Methods§

source

fn from_inner(int: Self::Inner) -> Self

Builds this type from an integer number.

source

fn into_inner(self) -> Self::Inner

Consumes self and returns the inner raw value.

Provided Methods§

source

fn accuracy() -> Self::Inner

Precision of this fixed point implementation.

source

fn saturating_from_integer<N>(int: N) -> Selfwhere N: FixedPointOperand,

Creates self from an integer number int.

Returns Self::max or Self::min if int exceeds accuracy.

source

fn checked_from_integer<N>(int: N) -> Option<Self>where N: Into<Self::Inner>,

Creates self from an integer number int.

Returns None if int exceeds accuracy.

source

fn saturating_from_rational<N, D>(n: N, d: D) -> Selfwhere N: FixedPointOperand, D: FixedPointOperand,

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.

source

fn checked_from_rational<N, D>(n: N, d: D) -> Option<Self>where N: FixedPointOperand, D: FixedPointOperand,

Creates self from a rational number. Equal to n / d.

Returns None if d == 0 or n / d exceeds accuracy.

source

fn checked_mul_int<N>(self, n: N) -> Option<N>where N: FixedPointOperand,

Checked multiplication for integer type N. Equal to self * n.

Returns None if the result does not fit in N.

source

fn saturating_mul_int<N>(self, n: N) -> Nwhere N: FixedPointOperand,

Saturating multiplication for integer type N. Equal to self * n.

Returns N::min or N::max if the result does not fit in N.

source

fn checked_div_int<N>(self, d: N) -> Option<N>where N: FixedPointOperand,

Checked division for integer type N. Equal to self / d.

Returns None if the result does not fit in N or d == 0.

source

fn saturating_div_int<N>(self, d: N) -> Nwhere N: FixedPointOperand,

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.

source

fn saturating_mul_acc_int<N>(self, n: N) -> Nwhere N: FixedPointOperand,

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.

source

fn saturating_abs(self) -> Self

Saturating absolute value.

Returns Self::max if self == Self::min.

source

fn reciprocal(self) -> Option<Self>

Takes the reciprocal (inverse). Equal to 1 / self.

Returns None if self = 0.

source

fn is_one(&self) -> bool

Checks if the number is one.

source

fn is_positive(self) -> bool

Returns true if self is positive and false if the number is zero or negative.

source

fn is_negative(self) -> bool

Returns true if self is negative and false if the number is zero or positive.

source

fn trunc(self) -> Self

Returns the integer part.

source

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.

source

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.

source

fn floor(self) -> Self

Returns the largest integer less than or equal to a number.

Saturates to Self::min (truncated) if the result does not fit.

source

fn round(self) -> Self

Returns the number rounded to the nearest integer. Rounds half-way cases away from 0.0.

Saturates to Self::min or Self::max (truncated) if the result does not fit.

Implementors§

source§

impl FixedPointNumber for FixedI64

§

type Inner = i64

source§

const DIV: <FixedI64 as FixedPointNumber>::Inner = {transmute(0x000000003b9aca00): <sp_arithmetic::FixedI64 as sp_arithmetic::FixedPointNumber>::Inner}

source§

const SIGNED: bool = true

source§

impl FixedPointNumber for FixedI128

§

type Inner = i128

source§

const DIV: <FixedI128 as FixedPointNumber>::Inner = {transmute(0x00000000000000000de0b6b3a7640000): <sp_arithmetic::FixedI128 as sp_arithmetic::FixedPointNumber>::Inner}

source§

const SIGNED: bool = true

source§

impl FixedPointNumber for FixedU64

§

type Inner = u64

source§

const DIV: <FixedU64 as FixedPointNumber>::Inner = {transmute(0x000000003b9aca00): <sp_arithmetic::FixedU64 as sp_arithmetic::FixedPointNumber>::Inner}

source§

const SIGNED: bool = false

source§

impl FixedPointNumber for FixedU128

§

type Inner = u128

source§

const DIV: <FixedU128 as FixedPointNumber>::Inner = {transmute(0x00000000000000000de0b6b3a7640000): <sp_arithmetic::FixedU128 as sp_arithmetic::FixedPointNumber>::Inner}

source§

const SIGNED: bool = false