[][src]Trait sp_arithmetic::PerThing

pub trait PerThing: Sized + Saturating + Copy {
    type Inner: BaseArithmetic + Copy;

    const ACCURACY: Self::Inner;

    fn zero() -> Self;
fn is_zero(&self) -> bool;
fn one() -> Self;
fn deconstruct(self) -> Self::Inner;
fn from_parts(parts: Self::Inner) -> Self;
fn from_percent(x: Self::Inner) -> Self;
fn square(self) -> Self;
fn from_fraction(x: f64) -> Self;
fn from_rational_approximation<N>(p: N, q: N) -> Self
    where
        N: Clone + Ord + From<Self::Inner> + TryInto<Self::Inner> + Div<N, Output = N>
; }

Something that implements a fixed point ration with an arbitrary granularity X, as parts per X.

Associated Types

type Inner: BaseArithmetic + Copy

The data type used to build this per-thingy.

Loading content...

Associated Constants

const ACCURACY: Self::Inner

accuracy of this type

Loading content...

Required methods

fn zero() -> Self

NoThing

fn is_zero(&self) -> bool

true if this is nothing.

fn one() -> Self

Everything.

fn deconstruct(self) -> Self::Inner

Consume self and deconstruct into a raw numeric type.

fn from_parts(parts: Self::Inner) -> Self

From an explicitly defined number of parts per maximum of the type.

fn from_percent(x: Self::Inner) -> Self

Converts a percent into Self. Equal to x / 100.

fn square(self) -> Self

Return the product of multiplication of this value by itself.

fn from_fraction(x: f64) -> Self

Converts a fraction into Self.

fn from_rational_approximation<N>(p: N, q: N) -> Self where
    N: Clone + Ord + From<Self::Inner> + TryInto<Self::Inner> + Div<N, Output = N>, 

Approximate the fraction p/q into a per-thing fraction. This will never overflow.

The computation of this approximation is performed in the generic type N. Given M as the data type that can hold the maximum value of this per-thing (e.g. u32 for perbill), this can only work if N == M or N: From<M> + TryInto<M>.

Loading content...

Implementors

impl PerThing for Perbill[src]

type Inner = u32

const ACCURACY: Self::Inner[src]

The accuracy of this type.

fn zero() -> Self[src]

Nothing.

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

true if this is nothing.

fn one() -> Self[src]

Everything.

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

Consume self and deconstruct into a raw numeric type.

fn from_parts(parts: Self::Inner) -> Self[src]

From an explicitly defined number of parts per maximum of the type.

fn from_percent(x: Self::Inner) -> Self[src]

Converts a percent into Self. Equal to x / 100.

fn square(self) -> Self[src]

Return the product of multiplication of this value by itself.

fn from_fraction(x: f64) -> Self[src]

Converts a fraction into Self.

fn from_rational_approximation<N>(p: N, q: N) -> Self where
    N: Clone + Ord + From<Self::Inner> + TryInto<Self::Inner> + Div<N, Output = N>, 
[src]

Approximate the fraction p/q into a per-thing fraction. This will never overflow.

The computation of this approximation is performed in the generic type N. Given M as the data type that can hold the maximum value of this per-thing (e.g. u32 for perbill), this can only work if N == M or N: From<M> + TryInto<M>.

impl PerThing for Percent[src]

type Inner = u8

const ACCURACY: Self::Inner[src]

The accuracy of this type.

fn zero() -> Self[src]

Nothing.

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

true if this is nothing.

fn one() -> Self[src]

Everything.

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

Consume self and deconstruct into a raw numeric type.

fn from_parts(parts: Self::Inner) -> Self[src]

From an explicitly defined number of parts per maximum of the type.

fn from_percent(x: Self::Inner) -> Self[src]

Converts a percent into Self. Equal to x / 100.

fn square(self) -> Self[src]

Return the product of multiplication of this value by itself.

fn from_fraction(x: f64) -> Self[src]

Converts a fraction into Self.

fn from_rational_approximation<N>(p: N, q: N) -> Self where
    N: Clone + Ord + From<Self::Inner> + TryInto<Self::Inner> + Div<N, Output = N>, 
[src]

Approximate the fraction p/q into a per-thing fraction. This will never overflow.

The computation of this approximation is performed in the generic type N. Given M as the data type that can hold the maximum value of this per-thing (e.g. u32 for perbill), this can only work if N == M or N: From<M> + TryInto<M>.

impl PerThing for Permill[src]

type Inner = u32

const ACCURACY: Self::Inner[src]

The accuracy of this type.

fn zero() -> Self[src]

Nothing.

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

true if this is nothing.

fn one() -> Self[src]

Everything.

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

Consume self and deconstruct into a raw numeric type.

fn from_parts(parts: Self::Inner) -> Self[src]

From an explicitly defined number of parts per maximum of the type.

fn from_percent(x: Self::Inner) -> Self[src]

Converts a percent into Self. Equal to x / 100.

fn square(self) -> Self[src]

Return the product of multiplication of this value by itself.

fn from_fraction(x: f64) -> Self[src]

Converts a fraction into Self.

fn from_rational_approximation<N>(p: N, q: N) -> Self where
    N: Clone + Ord + From<Self::Inner> + TryInto<Self::Inner> + Div<N, Output = N>, 
[src]

Approximate the fraction p/q into a per-thing fraction. This will never overflow.

The computation of this approximation is performed in the generic type N. Given M as the data type that can hold the maximum value of this per-thing (e.g. u32 for perbill), this can only work if N == M or N: From<M> + TryInto<M>.

impl PerThing for Perquintill[src]

type Inner = u64

const ACCURACY: Self::Inner[src]

The accuracy of this type.

fn zero() -> Self[src]

Nothing.

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

true if this is nothing.

fn one() -> Self[src]

Everything.

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

Consume self and deconstruct into a raw numeric type.

fn from_parts(parts: Self::Inner) -> Self[src]

From an explicitly defined number of parts per maximum of the type.

fn from_percent(x: Self::Inner) -> Self[src]

Converts a percent into Self. Equal to x / 100.

fn square(self) -> Self[src]

Return the product of multiplication of this value by itself.

fn from_fraction(x: f64) -> Self[src]

Converts a fraction into Self.

fn from_rational_approximation<N>(p: N, q: N) -> Self where
    N: Clone + Ord + From<Self::Inner> + TryInto<Self::Inner> + Div<N, Output = N>, 
[src]

Approximate the fraction p/q into a per-thing fraction. This will never overflow.

The computation of this approximation is performed in the generic type N. Given M as the data type that can hold the maximum value of this per-thing (e.g. u32 for perbill), this can only work if N == M or N: From<M> + TryInto<M>.

Loading content...