Struct dec::Decimal64

source ·
pub struct Decimal64 { /* private fields */ }
Expand description

A 64-bit decimal floating-point number.

Additional operations are defined as methods on the Context type.

For convenience, Decimal64 overloads many of the standard Rust operators. For example, you can use the standard + operator to add two values together:

use dec::Decimal64;
let a = Decimal64::from(1);
let b = Decimal64::from(2);
assert_eq!(a + b, Decimal64::from(3));

These overloaded operators implicitly construct a single-use default context, which has some performance overhead. For maximum performance when performing operations in bulk, use a long-lived context that you construct yourself.

Implementations§

source§

impl Decimal64

source

pub const NAN: Decimal64 = _

The value that represents Not-a-Number (NaN).

source

pub const ZERO: Decimal64 = _

The value that represents zero.

source

pub const ONE: Decimal64 = _

The value that represents one.

source

pub fn from_le_bytes(bytes: [u8; 8]) -> Decimal64

Creates a number from its representation as a little-endian byte array.

source

pub fn from_be_bytes(bytes: [u8; 8]) -> Decimal64

Creates a number from its representation as a big-endian byte array.

source

pub const fn from_ne_bytes(bytes: [u8; 8]) -> Decimal64

Creates a number from its representation as a byte array in the native endianness of the target platform.

source

pub fn to_le_bytes(&self) -> [u8; 8]

Returns the memory representation of the number as a byte array in little-endian order.

source

pub fn to_be_bytes(&self) -> [u8; 8]

Returns the memory representation of the number as a byte array in big-endian order.

source

pub fn to_ne_bytes(&self) -> [u8; 8]

Returns the memory representation of the number as a byte array in the native endianness of the target platform.

source

pub fn class(&self) -> Class

Classifies the number.

source

pub fn digits(&self) -> u32

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.

source

pub fn coefficient(&self) -> i64

Computes the coefficient of the number.

If the number is a special value (i.e., NaN or infinity), returns zero.

source

pub fn coefficient_digits(&self) -> [u8; 16]

Returns the individual digits of the coefficient in 8-bit, unpacked binary-coded decimal format.

source

pub fn exponent(&self) -> i32

Computes the exponent of the number.

source

pub fn canonical(self) -> Decimal64

Returns an equivalent number whose encoding is guaranteed to be canonical.

source

pub fn is_canonical(&self) -> bool

Reports whether the encoding of the number is canonical.

source

pub fn is_finite(&self) -> bool

Reports whether the number is finite.

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

source

pub fn is_infinite(&self) -> bool

Reports whether the number is positive or negative infinity.

source

pub fn is_integer(&self) -> bool

Reports whether the number is an integer.

An integer is a decimal number that is finite and has an exponent of zero.

source

pub fn is_logical(&self) -> bool

Reports whether the number is a valid argument for logical operations.

A number is a valid argument for logical operations if it is a nonnegative integer where each digit is either zero or one.

source

pub fn is_nan(&self) -> bool

Reports whether the number is a NaN.

source

pub fn is_negative(&self) -> bool

Reports whether the number is less than zero and not a NaN.

source

pub fn is_normal(&self) -> bool

Reports whether the number is normal.

A normal number is finite, non-zero, and not subnormal.

source

pub fn is_positive(&self) -> bool

Reports whether the number is greater than zero and not a NaN.

source

pub fn is_signaling_nan(&self) -> bool

Reports whether the number is a signaling NaN.

source

pub fn is_signed(&self) -> bool

Reports whether the number has a sign of 1.

Note that zeros and NaNs may have a sign of 1.

source

pub fn is_subnormal(&self) -> bool

Reports whether the number is subnormal.

A subnormal number is finite, non-zero, and has magnitude less than 10emin.

source

pub fn is_zero(&self) -> bool

Reports whether the number is positive or negative zero.

source

pub fn quantum_matches(&self, rhs: &Decimal64) -> bool

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.

source

pub fn total_cmp(&self, rhs: &Decimal64) -> Ordering

Determines the ordering of this number relative to rhs, using the total order predicate defined in IEEE 754-2008.

For a brief description of the ordering, consult f32::total_cmp.

source

pub fn to_standard_notation_string(&self) -> String

Returns a string of the number in standard notation, i.e. guaranteed to not be scientific notation.

Trait Implementations§

source§

impl Add<OrderedDecimal<Decimal64>> for Decimal64

§

type Output = Decimal64

The resulting type after applying the + operator.
source§

fn add(self, other: OrderedDecimal<Decimal64>) -> Self

Performs the + operation. Read more
source§

impl Add for Decimal64

§

type Output = Decimal64

The resulting type after applying the + operator.
source§

fn add(self, rhs: Decimal64) -> Decimal64

Performs the + operation. Read more
source§

impl AddAssign for Decimal64

source§

fn add_assign(&mut self, rhs: Decimal64)

Performs the += operation. Read more
source§

impl Clone for Decimal64

source§

fn clone(&self) -> Decimal64

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Decimal64

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for Decimal64

source§

fn default() -> Decimal64

Returns the “default value” for a type. Read more
source§

impl Display for Decimal64

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Div<OrderedDecimal<Decimal64>> for Decimal64

§

type Output = Decimal64

The resulting type after applying the / operator.
source§

fn div(self, other: OrderedDecimal<Decimal64>) -> Self

Performs the / operation. Read more
source§

impl Div for Decimal64

§

type Output = Decimal64

The resulting type after applying the / operator.
source§

fn div(self, rhs: Decimal64) -> Decimal64

Performs the / operation. Read more
source§

impl DivAssign for Decimal64

source§

fn div_assign(&mut self, rhs: Decimal64)

Performs the /= operation. Read more
source§

impl From<Decimal32> for Decimal64

source§

fn from(d32: Decimal32) -> Decimal64

Converts to this type from the input type.
source§

impl<const N: usize> From<Decimal64> for Decimal<N>

source§

fn from(n: Decimal64) -> Decimal<N>

Converts to this type from the input type.
source§

impl From<Decimal64> for Decimal128

source§

fn from(d64: Decimal64) -> Decimal128

Converts to this type from the input type.
source§

impl<D> From<Decimal64> for OrderedDecimal<D>
where D: From<Decimal64>,

source§

fn from(n: Decimal64) -> OrderedDecimal<D>

Converts to this type from the input type.
source§

impl From<i32> for Decimal64

source§

fn from(n: i32) -> Decimal64

Converts to this type from the input type.
source§

impl From<u32> for Decimal64

source§

fn from(n: u32) -> Decimal64

Converts to this type from the input type.
source§

impl FromStr for Decimal64

§

type Err = ParseDecimalError

The associated error which can be returned from parsing.
source§

fn from_str(s: &str) -> Result<Decimal64, ParseDecimalError>

Parses a string s to return a value of this type. Read more
source§

impl Mul<OrderedDecimal<Decimal64>> for Decimal64

§

type Output = Decimal64

The resulting type after applying the * operator.
source§

fn mul(self, other: OrderedDecimal<Decimal64>) -> Self

Performs the * operation. Read more
source§

impl Mul for Decimal64

§

type Output = Decimal64

The resulting type after applying the * operator.
source§

fn mul(self, rhs: Decimal64) -> Decimal64

Performs the * operation. Read more
source§

impl MulAssign for Decimal64

source§

fn mul_assign(&mut self, rhs: Decimal64)

Performs the *= operation. Read more
source§

impl Neg for Decimal64

§

type Output = Decimal64

The resulting type after applying the - operator.
source§

fn neg(self) -> Decimal64

Performs the unary - operation. Read more
source§

impl PartialEq for Decimal64

source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialOrd for Decimal64

source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl<'a> Product<&'a Decimal64> for Decimal64

source§

fn product<I>(iter: I) -> Self
where I: Iterator<Item = &'a Decimal64>,

Takes an iterator and generates Self from the elements by multiplying the items.
source§

impl Product for Decimal64

source§

fn product<I>(iter: I) -> Self
where I: Iterator<Item = Decimal64>,

Takes an iterator and generates Self from the elements by multiplying the items.
source§

impl Rem<OrderedDecimal<Decimal64>> for Decimal64

§

type Output = Decimal64

The resulting type after applying the % operator.
source§

fn rem(self, other: OrderedDecimal<Decimal64>) -> Self

Performs the % operation. Read more
source§

impl Rem for Decimal64

§

type Output = Decimal64

The resulting type after applying the % operator.
source§

fn rem(self, rhs: Decimal64) -> Decimal64

Performs the % operation. Read more
source§

impl RemAssign for Decimal64

source§

fn rem_assign(&mut self, rhs: Decimal64)

Performs the %= operation. Read more
source§

impl Sub<OrderedDecimal<Decimal64>> for Decimal64

§

type Output = Decimal64

The resulting type after applying the - operator.
source§

fn sub(self, other: OrderedDecimal<Decimal64>) -> Self

Performs the - operation. Read more
source§

impl Sub for Decimal64

§

type Output = Decimal64

The resulting type after applying the - operator.
source§

fn sub(self, rhs: Decimal64) -> Decimal64

Performs the - operation. Read more
source§

impl SubAssign for Decimal64

source§

fn sub_assign(&mut self, rhs: Decimal64)

Performs the -= operation. Read more
source§

impl<'a> Sum<&'a Decimal64> for Decimal64

source§

fn sum<I>(iter: I) -> Self
where I: Iterator<Item = &'a Decimal64>,

Takes an iterator and generates Self from the elements by “summing up” the items.
source§

impl Sum for Decimal64

source§

fn sum<I>(iter: I) -> Self
where I: Iterator<Item = Decimal64>,

Takes an iterator and generates Self from the elements by “summing up” the items.
source§

impl Copy for Decimal64

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> CloneToUninit for T
where T: Clone,

source§

default unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

impl<T> CloneToUninit for T
where T: Copy,

source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

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

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.