Trait sp_runtime::FixedPointNumber[][src]

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

    pub const DIV: Self::Inner;
    pub const SIGNED: bool;

    pub fn from_inner(int: Self::Inner) -> Self;
pub fn into_inner(self) -> Self::Inner; pub fn accuracy() -> Self::Inner { ... }
pub fn saturating_from_integer<N>(int: N) -> Self
    where
        N: FixedPointOperand
, { ... }
pub fn checked_from_integer(int: Self::Inner) -> Option<Self> { ... }
pub fn saturating_from_rational<N, D>(n: N, d: D) -> Self
    where
        D: FixedPointOperand,
        N: FixedPointOperand
, { ... }
pub fn checked_from_rational<N, D>(n: N, d: D) -> Option<Self>
    where
        D: FixedPointOperand,
        N: FixedPointOperand
, { ... }
pub fn checked_mul_int<N>(self, n: N) -> Option<N>
    where
        N: FixedPointOperand
, { ... }
pub fn saturating_mul_int<N>(self, n: N) -> N
    where
        N: FixedPointOperand
, { ... }
pub fn checked_div_int<N>(self, d: N) -> Option<N>
    where
        N: FixedPointOperand
, { ... }
pub fn saturating_div_int<N>(self, d: N) -> N
    where
        N: FixedPointOperand
, { ... }
pub fn saturating_mul_acc_int<N>(self, n: N) -> N
    where
        N: FixedPointOperand
, { ... }
pub fn saturating_abs(self) -> Self { ... }
pub fn reciprocal(self) -> Option<Self> { ... }
pub fn zero() -> Self { ... }
pub fn is_zero(&self) -> bool { ... }
pub fn one() -> Self { ... }
pub fn is_one(&self) -> bool { ... }
pub fn is_positive(self) -> bool { ... }
pub fn is_negative(self) -> bool { ... }
pub fn trunc(self) -> Self { ... }
pub fn frac(self) -> Self { ... }
pub fn ceil(self) -> Self { ... }
pub fn floor(self) -> Self { ... }
pub fn round(self) -> Self { ... } }

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.

Associated Types

type Inner: FixedPointOperand + Debug + One + CheckedMul + CheckedDiv[src]

The underlying data type used for this fixed point number.

Loading content...

Associated Constants

pub const DIV: Self::Inner[src]

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

pub const SIGNED: bool[src]

Indicates if this fixed point implementation is signed or not.

Loading content...

Required methods

pub fn from_inner(int: Self::Inner) -> Self[src]

Builds this type from an integer number.

pub fn into_inner(self) -> Self::Inner[src]

Consumes self and returns the inner raw value.

Loading content...

Provided methods

pub fn accuracy() -> Self::Inner[src]

Precision of this fixed point implementation.

pub fn saturating_from_integer<N>(int: N) -> Self where
    N: FixedPointOperand
[src]

Creates self from an integer number int.

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

pub fn checked_from_integer(int: Self::Inner) -> Option<Self>[src]

Creates self from an integer number int.

Returns None if int exceeds accuracy.

pub fn saturating_from_rational<N, D>(n: N, d: D) -> Self where
    D: FixedPointOperand,
    N: FixedPointOperand
[src]

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.

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

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

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

pub fn checked_mul_int<N>(self, n: N) -> Option<N> where
    N: FixedPointOperand
[src]

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

Returns None if the result does not fit in N.

pub fn saturating_mul_int<N>(self, n: N) -> N where
    N: FixedPointOperand
[src]

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

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

pub fn checked_div_int<N>(self, d: N) -> Option<N> where
    N: FixedPointOperand
[src]

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

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

pub fn saturating_div_int<N>(self, d: N) -> N where
    N: FixedPointOperand
[src]

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.

pub fn saturating_mul_acc_int<N>(self, n: N) -> N where
    N: FixedPointOperand
[src]

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.

pub fn saturating_abs(self) -> Self[src]

Saturating absolute value.

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

pub fn reciprocal(self) -> Option<Self>[src]

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

Returns None if self = 0.

pub fn zero() -> Self[src]

Returns zero.

pub fn is_zero(&self) -> bool[src]

Checks if the number is zero.

pub fn one() -> Self[src]

Returns one.

pub fn is_one(&self) -> bool[src]

Checks if the number is one.

pub fn is_positive(self) -> bool[src]

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

pub fn is_negative(self) -> bool[src]

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

pub fn trunc(self) -> Self[src]

Returns the integer part.

pub fn frac(self) -> Self[src]

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.

pub fn ceil(self) -> Self[src]

Returns the smallest integer greater than or equal to a number.

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

pub fn floor(self) -> Self[src]

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

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

pub fn round(self) -> Self[src]

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.

Loading content...

Implementors

impl FixedPointNumber for FixedI64[src]

impl FixedPointNumber for FixedI128[src]

impl FixedPointNumber for FixedU128[src]

Loading content...