Struct dec::Decimal[][src]

#[repr(C)]pub struct Decimal<const N: usize> { /* fields omitted */ }
This is supported on crate feature arbitrary-precision only.

An arbitrary-precision decimal number.

The maximum number of digits that can be stored in the number is specified by N * 3. For example, a value of type Decimal<3> has space for nine decimal digits. This somewhat odd design is due to limitations of constant generic parameters in Rust. The intention is to someday make N correspond directly to the number of digits of precision.

N must be at least 12 and no greater than 999,999,999, though typically the stack size implies a smaller maximum for N. Due to limitations with constant generics it is not yet possible to enforce these restrictions at compile time, so they are checked at runtime.

Implementations

impl<const N: usize> Decimal<N>[src]

pub fn zero() -> Decimal<N>[src]

Constructs a decimal number with N / 3 digits of precision representing the number 0.

pub fn digits(&self) -> u32[src]

Computes the number of significant digits in the number.

If the number is zero or infinite, returns 1. If the number is a NaN, returns the number of digits in the payload.

pub fn exponent(&self) -> i32[src]

Computes the exponent of the number.

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

Reports whether the number is finite.

A finite number is one that is neither infinite nor a NaN.

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

Reports whether the number is positive or negative infinity.

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

Reports whether the number is a NaN.

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

Reports whether the number is negative.

A negative number is either negative zero, less than zero, or NaN with a sign of one. This corresponds to Decimal128::is_signed, not Decimal128::is_negative.

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

Reports whether the number is a quiet NaN.

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

Reports whether the number is a signaling NaN.

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

Reports whether the number has a special value.

A special value is either infinity or NaN. This is the inverse of Decimal::is_finite.

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

Reports whether the number is positive or negative zero.

pub fn quantum_matches(&self, rhs: &Decimal<N>) -> bool[src]

Reports whether the quantum of the number matches the quantum of rhs.

Quantums are considered to match if the numbers have the same exponent, are both NaNs, or both infinite.

pub fn to_decimal32(&self) -> Decimal32[src]

Converts this decimal to a 32-bit decimal float.

The result may be inexact. Use Context::<Decimal32>::from_decimal to observe exceptional conditions.

pub fn to_decimal64(&self) -> Decimal64[src]

Converts this decimal to a 64-bit decimal float.

The result may be inexact. Use Context::<Decimal64>::from_decimal to observe exceptional conditions.

pub fn to_decimal128(&self) -> Decimal128[src]

Converts this decimal to a 128-bit decimal float.

The result may be inexact. Use Context::<Decimal128>::from_decimal to observe exceptional conditions.

pub fn to_raw_parts(&self) -> (u32, i32, u8, [u16; N])[src]

Returns the raw parts of this decimal.

The meaning of these parts are unspecified and subject to change.

Trait Implementations

impl<const N: usize> Clone for Decimal<N>[src]

impl<const N: usize> Debug for Decimal<N>[src]

impl<const N: usize> Default for Decimal<N>[src]

impl<const N: usize> Display for Decimal<N>[src]

impl<const N: usize> From<Decimal128> for Decimal<N>[src]

impl<const N: usize> From<Decimal32> for Decimal<N>[src]

impl<const N: usize> From<Decimal64> for Decimal<N>[src]

impl<const N: usize> FromStr for Decimal<N>[src]

type Err = ParseDecimalError

The associated error which can be returned from parsing.

Auto Trait Implementations

impl<const N: usize> RefUnwindSafe for Decimal<N>

impl<const N: usize> Send for Decimal<N>

impl<const N: usize> Sync for Decimal<N>

impl<const N: usize> Unpin for Decimal<N>

impl<const N: usize> UnwindSafe for Decimal<N>

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> From<T> for T[src]

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

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.