[][src]Struct sp_arithmetic::Fixed128

pub struct Fixed128(_);

A signed fixed-point number. Can hold any value in the range [-170_141_183_460_469_231_731, 170_141_183_460_469_231_731] with fixed-point accuracy of 10 ** 18.

Methods

impl Fixed128[src]

pub fn from_natural(int: i128) -> Self[src]

Create self from a natural number.

Note that this might be lossy.

pub const fn accuracy() -> i128[src]

Accuracy of Fixed128.

pub const fn from_parts(parts: i128) -> Self[src]

Raw constructor. Equal to parts / DIV.

pub fn from_rational<N: UniqueSaturatedInto<i128>>(n: N, d: NonZeroI128) -> Self[src]

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

Note that this might be lossy. Only use this if you are sure that n * DIV can fit into an i128.

pub fn deconstruct(self) -> i128[src]

Consume self and return the inner raw i128 value.

Note this is a low level function, as the returned value is represented with accuracy.

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

Takes the reciprocal(inverse) of Fixed128, 1/x

pub fn checked_add(&self, rhs: &Self) -> Option<Self>[src]

Checked add. Same semantic to num_traits::CheckedAdd.

pub fn checked_sub(&self, rhs: &Self) -> Option<Self>[src]

Checked sub. Same semantic to num_traits::CheckedSub.

pub fn checked_mul(&self, rhs: &Self) -> Option<Self>[src]

Checked mul. Same semantic to num_traits::CheckedMul.

pub fn checked_div(&self, rhs: &Self) -> Option<Self>[src]

Checked div. Same semantic to num_traits::CheckedDiv.

pub fn checked_mul_int<N>(&self, other: &N) -> Option<N> where
    N: Copy + TryFrom<i128> + TryInto<i128>, 
[src]

Checked mul for int type N.

pub fn saturating_mul_int<N>(&self, other: &N) -> N where
    N: Copy + TryFrom<i128> + TryInto<i128> + Bounded
[src]

Checked mul for int type N.

pub fn checked_div_int<N>(&self, other: &N) -> Option<N> where
    N: Copy + TryFrom<i128> + TryInto<i128>, 
[src]

Checked div for int type N.

pub fn zero() -> Self[src]

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

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

Saturating absolute value. Returning MAX if parts == i128::MIN instead of overflowing.

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

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

pub fn saturated_multiply_accumulate<N>(self, int: N) -> N where
    N: TryFrom<u128> + From<u64> + UniqueSaturatedInto<u64> + Bounded + Clone + Saturating + Rem<N, Output = N> + Div<N, Output = N> + Mul<N, Output = N> + Add<N, Output = N>, 
[src]

Performs a saturated multiply and accumulate by unsigned number.

Returns a saturated int + (self * int).

Trait Implementations

impl Add<Fixed128> for Fixed128[src]

Note that this is a standard, potentially-panicking, implementation. Use Saturating trait for safe addition.

type Output = Self

The resulting type after applying the + operator.

impl Bounded for Fixed128[src]

impl Clone for Fixed128[src]

impl Copy for Fixed128[src]

impl Debug for Fixed128[src]

impl Decode for Fixed128[src]

impl Default for Fixed128[src]

impl<'de> Deserialize<'de> for Fixed128[src]

impl Encode for Fixed128[src]

impl EncodeLike<Fixed128> for Fixed128[src]

impl Eq for Fixed128[src]

impl<P: PerThing> From<P> for Fixed128[src]

impl Ord for Fixed128[src]

impl PartialEq<Fixed128> for Fixed128[src]

impl PartialOrd<Fixed128> for Fixed128[src]

impl Saturating for Fixed128[src]

impl Serialize for Fixed128[src]

impl StructuralEq for Fixed128[src]

impl StructuralPartialEq for Fixed128[src]

impl Sub<Fixed128> for Fixed128[src]

Note that this is a standard, potentially-panicking, implementation. Use Saturating trait for safe subtraction.

type Output = Self

The resulting type after applying the - operator.

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<S> Codec for S where
    S: Encode + Decode
[src]

impl<T, X> Decode for X where
    T: Decode + Into<X>,
    X: WrapperTypeDecode<Wrapped = T>, 
[src]

impl<T> DecodeAll for T where
    T: Decode
[src]

impl<T> DeserializeOwned for T where
    T: for<'de> Deserialize<'de>, 
[src]

impl<T, X> Encode for X where
    T: Encode + ?Sized,
    X: WrapperTypeEncode<Target = T>, 
[src]

impl<'_, '_, T> EncodeLike<&'_ &'_ T> for T where
    T: Encode
[src]

impl<'_, T> EncodeLike<&'_ T> for T where
    T: Encode
[src]

impl<'_, T> EncodeLike<&'_ mut T> for T where
    T: Encode
[src]

impl<T> EncodeLike<Arc<T>> for T where
    T: Encode
[src]

impl<T> EncodeLike<Box<T>> for T where
    T: Encode
[src]

impl<'a, T> EncodeLike<Cow<'a, T>> for T where
    T: Encode + ToOwned
[src]

impl<T> EncodeLike<Rc<T>> for T where
    T: Encode
[src]

impl<T> From<T> for T[src]

impl<S> FullCodec for S where
    S: Decode + FullEncode
[src]

impl<S> FullEncode for S where
    S: Encode + EncodeLike<S>, 
[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> KeyedVec for T where
    T: Codec
[src]

impl<T> SaturatedConversion for T[src]

impl<T> Saturating for T where
    T: Clone + Bounded + One + CheckedMul + Saturating
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T, S> UniqueSaturatedFrom<T> for S where
    S: TryFrom<T> + Bounded
[src]

impl<T, S> UniqueSaturatedInto<T> for S where
    S: TryInto<T>,
    T: Bounded
[src]

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,