[][src]Struct fixnum::FixedPoint

pub struct FixedPoint<I, P> { /* fields omitted */ }

Abstraction over fixed point numbers of arbitrary (but only compile-time specified) size and precision.

The internal representation is a fixed point decimal number, an integer value pre-multiplied by 10 ^ PRECISION, where PRECISION is a compile-time-defined decimal places count.

Maximal possible value: MAX = (2 ^ (BITS_COUNT - 1) - 1) / 10 ^ PRECISION Maximal possible calculation error: ERROR_MAX = 0.5 / (10 ^ PRECISION)

E.g. for i64 with 9 decimal places:

MAX = (2 ^ (64 - 1) - 1) / 1e9 = 9223372036.854775807 ~ 9.2e9
ERROR_MAX = 0.5 / 1e9 = 5e-10

Implementations

impl<I, P> FixedPoint<I, P>[src]

pub const fn from_bits(raw: I) -> Self[src]

pub const fn as_bits(&self) -> &I[src]

impl<P: Precision> FixedPoint<i16, P>[src]

pub const PRECISION: i32[src]

pub const EPSILON: Self[src]

impl<P: Precision> FixedPoint<i16, P>[src]

pub fn recip(
    self,
    mode: RoundMode
) -> Result<FixedPoint<i16, P>, ArithmeticError>
[src]

pub fn cneg(self) -> Result<FixedPoint<i16, P>, ArithmeticError>[src]

Checked negation. Returns Err on overflow (you can't negate MIN value).

pub fn half_sum(
    a: FixedPoint<i16, P>,
    b: FixedPoint<i16, P>
) -> FixedPoint<i16, P>
[src]

pub fn integral(self, mode: RoundMode) -> i16[src]

pub fn round_towards_zero_by(
    self,
    precision: FixedPoint<i16, P>
) -> FixedPoint<i16, P>
[src]

pub fn next_power_of_ten(self) -> Result<FixedPoint<i16, P>, ArithmeticError>[src]

pub fn rounding_from_f64(
    value: f64
) -> Result<FixedPoint<i16, P>, ArithmeticError>
[src]

pub fn to_f64(self) -> f64[src]

pub fn rounding_to_i64(self) -> i64[src]

impl<P: Precision> FixedPoint<i16, P>[src]

pub fn from_decimal(
    mantissa: i16,
    exponent: i32
) -> Result<FixedPoint<i16, P>, FromDecimalError>
[src]

impl<P: Precision> FixedPoint<i32, P>[src]

pub const PRECISION: i32[src]

pub const EPSILON: Self[src]

impl<P: Precision> FixedPoint<i32, P>[src]

pub fn recip(
    self,
    mode: RoundMode
) -> Result<FixedPoint<i32, P>, ArithmeticError>
[src]

pub fn cneg(self) -> Result<FixedPoint<i32, P>, ArithmeticError>[src]

Checked negation. Returns Err on overflow (you can't negate MIN value).

pub fn half_sum(
    a: FixedPoint<i32, P>,
    b: FixedPoint<i32, P>
) -> FixedPoint<i32, P>
[src]

pub fn integral(self, mode: RoundMode) -> i32[src]

pub fn round_towards_zero_by(
    self,
    precision: FixedPoint<i32, P>
) -> FixedPoint<i32, P>
[src]

pub fn next_power_of_ten(self) -> Result<FixedPoint<i32, P>, ArithmeticError>[src]

pub fn rounding_from_f64(
    value: f64
) -> Result<FixedPoint<i32, P>, ArithmeticError>
[src]

pub fn to_f64(self) -> f64[src]

pub fn rounding_to_i64(self) -> i64[src]

impl<P: Precision> FixedPoint<i32, P>[src]

pub fn from_decimal(
    mantissa: i32,
    exponent: i32
) -> Result<FixedPoint<i32, P>, FromDecimalError>
[src]

impl<P: Precision> FixedPoint<i64, P>[src]

pub const PRECISION: i32[src]

pub const EPSILON: Self[src]

impl<P: Precision> FixedPoint<i64, P>[src]

pub fn recip(
    self,
    mode: RoundMode
) -> Result<FixedPoint<i64, P>, ArithmeticError>
[src]

pub fn cneg(self) -> Result<FixedPoint<i64, P>, ArithmeticError>[src]

Checked negation. Returns Err on overflow (you can't negate MIN value).

pub fn half_sum(
    a: FixedPoint<i64, P>,
    b: FixedPoint<i64, P>
) -> FixedPoint<i64, P>
[src]

pub fn integral(self, mode: RoundMode) -> i64[src]

pub fn round_towards_zero_by(
    self,
    precision: FixedPoint<i64, P>
) -> FixedPoint<i64, P>
[src]

pub fn next_power_of_ten(self) -> Result<FixedPoint<i64, P>, ArithmeticError>[src]

pub fn rounding_from_f64(
    value: f64
) -> Result<FixedPoint<i64, P>, ArithmeticError>
[src]

pub fn to_f64(self) -> f64[src]

pub fn rounding_to_i64(self) -> i64[src]

impl<P: Precision> FixedPoint<i64, P>[src]

pub fn from_decimal(
    mantissa: i64,
    exponent: i32
) -> Result<FixedPoint<i64, P>, FromDecimalError>
[src]

Trait Implementations

impl<P: Precision> CheckedAdd<FixedPoint<i16, P>> for FixedPoint<i16, P>[src]

type Output = FixedPoint<i16, P>

type Error = ArithmeticError

impl<P: Precision> CheckedAdd<FixedPoint<i32, P>> for FixedPoint<i32, P>[src]

type Output = FixedPoint<i32, P>

type Error = ArithmeticError

impl<P: Precision> CheckedAdd<FixedPoint<i64, P>> for FixedPoint<i64, P>[src]

type Output = FixedPoint<i64, P>

type Error = ArithmeticError

impl<P: Precision> CheckedMul<FixedPoint<i16, P>> for i16[src]

type Output = FixedPoint<i16, P>

type Error = ArithmeticError

impl<P: Precision> CheckedMul<FixedPoint<i32, P>> for i32[src]

type Output = FixedPoint<i32, P>

type Error = ArithmeticError

impl<P: Precision> CheckedMul<FixedPoint<i64, P>> for i64[src]

type Output = FixedPoint<i64, P>

type Error = ArithmeticError

impl<P: Precision> CheckedMul<i16> for FixedPoint<i16, P>[src]

type Output = FixedPoint<i16, P>

type Error = ArithmeticError

impl<P: Precision> CheckedMul<i32> for FixedPoint<i32, P>[src]

type Output = FixedPoint<i32, P>

type Error = ArithmeticError

impl<P: Precision> CheckedMul<i64> for FixedPoint<i64, P>[src]

type Output = FixedPoint<i64, P>

type Error = ArithmeticError

impl<P: Precision> CheckedSub<FixedPoint<i16, P>> for FixedPoint<i16, P>[src]

type Output = FixedPoint<i16, P>

type Error = ArithmeticError

impl<P: Precision> CheckedSub<FixedPoint<i32, P>> for FixedPoint<i32, P>[src]

type Output = FixedPoint<i32, P>

type Error = ArithmeticError

impl<P: Precision> CheckedSub<FixedPoint<i64, P>> for FixedPoint<i64, P>[src]

type Output = FixedPoint<i64, P>

type Error = ArithmeticError

impl<I: Clone, P: Clone> Clone for FixedPoint<I, P>[src]

impl<I: Copy, P: Copy> Copy for FixedPoint<I, P>[src]

impl<P: Precision> Debug for FixedPoint<i16, P>[src]

impl<P: Precision> Debug for FixedPoint<i32, P>[src]

impl<P: Precision> Debug for FixedPoint<i64, P>[src]

impl<I: Default, P: Default> Default for FixedPoint<I, P>[src]

impl<'de, I, P> Deserialize<'de> for FixedPoint<I, P> where
    I: Deserialize<'de>, 
[src]

impl<P: Precision> Display for FixedPoint<i16, P>[src]

impl<P: Precision> Display for FixedPoint<i32, P>[src]

impl<P: Precision> Display for FixedPoint<i64, P>[src]

impl<I: Eq, P: Eq> Eq for FixedPoint<I, P>[src]

impl<P: Precision> FromStr for FixedPoint<i16, P>[src]

type Err = ConvertError

The associated error which can be returned from parsing.

impl<P: Precision> FromStr for FixedPoint<i32, P>[src]

type Err = ConvertError

The associated error which can be returned from parsing.

impl<P: Precision> FromStr for FixedPoint<i64, P>[src]

type Err = ConvertError

The associated error which can be returned from parsing.

impl<I: Hash, P: Hash> Hash for FixedPoint<I, P>[src]

impl<P: Precision> Numeric for FixedPoint<i16, P>[src]

impl<P: Precision> Numeric for FixedPoint<i32, P>[src]

impl<P: Precision> Numeric for FixedPoint<i64, P>[src]

impl<I: Ord, P: Ord> Ord for FixedPoint<I, P>[src]

impl<I: PartialEq, P: PartialEq> PartialEq<FixedPoint<I, P>> for FixedPoint<I, P>[src]

impl<I: PartialOrd, P: PartialOrd> PartialOrd<FixedPoint<I, P>> for FixedPoint<I, P>[src]

impl<P: Precision> RoundingDiv<FixedPoint<i16, P>> for FixedPoint<i16, P>[src]

type Output = FixedPoint<i16, P>

type Error = ArithmeticError

impl<P: Precision> RoundingDiv<FixedPoint<i16, P>> for i16[src]

type Output = FixedPoint<i16, P>

type Error = ArithmeticError

impl<P: Precision> RoundingDiv<FixedPoint<i32, P>> for FixedPoint<i32, P>[src]

type Output = FixedPoint<i32, P>

type Error = ArithmeticError

impl<P: Precision> RoundingDiv<FixedPoint<i32, P>> for i32[src]

type Output = FixedPoint<i32, P>

type Error = ArithmeticError

impl<P: Precision> RoundingDiv<FixedPoint<i64, P>> for FixedPoint<i64, P>[src]

type Output = FixedPoint<i64, P>

type Error = ArithmeticError

impl<P: Precision> RoundingDiv<FixedPoint<i64, P>> for i64[src]

type Output = FixedPoint<i64, P>

type Error = ArithmeticError

impl<P: Precision> RoundingDiv<i16> for FixedPoint<i16, P>[src]

type Output = FixedPoint<i16, P>

type Error = ArithmeticError

impl<P: Precision> RoundingDiv<i32> for FixedPoint<i32, P>[src]

type Output = FixedPoint<i32, P>

type Error = ArithmeticError

impl<P: Precision> RoundingDiv<i64> for FixedPoint<i64, P>[src]

type Output = FixedPoint<i64, P>

type Error = ArithmeticError

impl<P: Precision> RoundingMul<FixedPoint<i16, P>> for FixedPoint<i16, P>[src]

type Output = FixedPoint<i16, P>

type Error = ArithmeticError

impl<P: Precision> RoundingMul<FixedPoint<i32, P>> for FixedPoint<i32, P>[src]

type Output = FixedPoint<i32, P>

type Error = ArithmeticError

impl<P: Precision> RoundingMul<FixedPoint<i64, P>> for FixedPoint<i64, P>[src]

type Output = FixedPoint<i64, P>

type Error = ArithmeticError

impl<I, P> Serialize for FixedPoint<I, P> where
    I: Serialize
[src]

impl<I, P> StructuralEq for FixedPoint<I, P>[src]

impl<I, P> StructuralPartialEq for FixedPoint<I, P>[src]

impl<P: Precision> TryFrom<i128> for FixedPoint<i16, P>[src]

type Error = ConvertError

The type returned in the event of a conversion error.

impl<P: Precision> TryFrom<i128> for FixedPoint<i32, P>[src]

type Error = ConvertError

The type returned in the event of a conversion error.

impl<P: Precision> TryFrom<i128> for FixedPoint<i64, P>[src]

type Error = ConvertError

The type returned in the event of a conversion error.

impl<P: Precision> TryFrom<i16> for FixedPoint<i16, P>[src]

type Error = ConvertError

The type returned in the event of a conversion error.

impl<P: Precision> TryFrom<i16> for FixedPoint<i32, P>[src]

type Error = ConvertError

The type returned in the event of a conversion error.

impl<P: Precision> TryFrom<i16> for FixedPoint<i64, P>[src]

type Error = ConvertError

The type returned in the event of a conversion error.

impl<P: Precision> TryFrom<i32> for FixedPoint<i16, P>[src]

type Error = ConvertError

The type returned in the event of a conversion error.

impl<P: Precision> TryFrom<i32> for FixedPoint<i32, P>[src]

type Error = ConvertError

The type returned in the event of a conversion error.

impl<P: Precision> TryFrom<i32> for FixedPoint<i64, P>[src]

type Error = ConvertError

The type returned in the event of a conversion error.

impl<P: Precision> TryFrom<i64> for FixedPoint<i16, P>[src]

type Error = ConvertError

The type returned in the event of a conversion error.

impl<P: Precision> TryFrom<i64> for FixedPoint<i32, P>[src]

type Error = ConvertError

The type returned in the event of a conversion error.

impl<P: Precision> TryFrom<i64> for FixedPoint<i64, P>[src]

type Error = ConvertError

The type returned in the event of a conversion error.

impl<P: Precision> TryFrom<i8> for FixedPoint<i16, P>[src]

type Error = ConvertError

The type returned in the event of a conversion error.

impl<P: Precision> TryFrom<i8> for FixedPoint<i32, P>[src]

type Error = ConvertError

The type returned in the event of a conversion error.

impl<P: Precision> TryFrom<i8> for FixedPoint<i64, P>[src]

type Error = ConvertError

The type returned in the event of a conversion error.

impl<P: Precision> TryFrom<isize> for FixedPoint<i16, P>[src]

type Error = ConvertError

The type returned in the event of a conversion error.

impl<P: Precision> TryFrom<isize> for FixedPoint<i32, P>[src]

type Error = ConvertError

The type returned in the event of a conversion error.

impl<P: Precision> TryFrom<isize> for FixedPoint<i64, P>[src]

type Error = ConvertError

The type returned in the event of a conversion error.

impl<P: Precision> TryFrom<u128> for FixedPoint<i16, P>[src]

type Error = ConvertError

The type returned in the event of a conversion error.

impl<P: Precision> TryFrom<u128> for FixedPoint<i32, P>[src]

type Error = ConvertError

The type returned in the event of a conversion error.

impl<P: Precision> TryFrom<u128> for FixedPoint<i64, P>[src]

type Error = ConvertError

The type returned in the event of a conversion error.

impl<P: Precision> TryFrom<u16> for FixedPoint<i16, P>[src]

type Error = ConvertError

The type returned in the event of a conversion error.

impl<P: Precision> TryFrom<u16> for FixedPoint<i32, P>[src]

type Error = ConvertError

The type returned in the event of a conversion error.

impl<P: Precision> TryFrom<u16> for FixedPoint<i64, P>[src]

type Error = ConvertError

The type returned in the event of a conversion error.

impl<P: Precision> TryFrom<u32> for FixedPoint<i16, P>[src]

type Error = ConvertError

The type returned in the event of a conversion error.

impl<P: Precision> TryFrom<u32> for FixedPoint<i32, P>[src]

type Error = ConvertError

The type returned in the event of a conversion error.

impl<P: Precision> TryFrom<u32> for FixedPoint<i64, P>[src]

type Error = ConvertError

The type returned in the event of a conversion error.

impl<P: Precision> TryFrom<u64> for FixedPoint<i16, P>[src]

type Error = ConvertError

The type returned in the event of a conversion error.

impl<P: Precision> TryFrom<u64> for FixedPoint<i32, P>[src]

type Error = ConvertError

The type returned in the event of a conversion error.

impl<P: Precision> TryFrom<u64> for FixedPoint<i64, P>[src]

type Error = ConvertError

The type returned in the event of a conversion error.

impl<P: Precision> TryFrom<u8> for FixedPoint<i16, P>[src]

type Error = ConvertError

The type returned in the event of a conversion error.

impl<P: Precision> TryFrom<u8> for FixedPoint<i32, P>[src]

type Error = ConvertError

The type returned in the event of a conversion error.

impl<P: Precision> TryFrom<u8> for FixedPoint<i64, P>[src]

type Error = ConvertError

The type returned in the event of a conversion error.

impl<P: Precision> TryFrom<usize> for FixedPoint<i16, P>[src]

type Error = ConvertError

The type returned in the event of a conversion error.

impl<P: Precision> TryFrom<usize> for FixedPoint<i32, P>[src]

type Error = ConvertError

The type returned in the event of a conversion error.

impl<P: Precision> TryFrom<usize> for FixedPoint<i64, P>[src]

type Error = ConvertError

The type returned in the event of a conversion error.

Auto Trait Implementations

impl<I, P> RefUnwindSafe for FixedPoint<I, P> where
    I: RefUnwindSafe,
    P: RefUnwindSafe
[src]

impl<I, P> Send for FixedPoint<I, P> where
    I: Send,
    P: Send
[src]

impl<I, P> Sync for FixedPoint<I, P> where
    I: Sync,
    P: Sync
[src]

impl<I, P> Unpin for FixedPoint<I, P> where
    I: Unpin,
    P: Unpin
[src]

impl<I, P> UnwindSafe for FixedPoint<I, P> where
    I: UnwindSafe,
    P: UnwindSafe
[src]

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<T> DeserializeOwned for T where
    T: for<'de> Deserialize<'de>, 
[src]

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

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

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

type Output = T

Should always be Self

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

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

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.