# Struct dec::Decimal128

source · [−]`#[repr(transparent)]pub struct Decimal128 { /* private fields */ }`

## Expand description

A 128-bit decimal floating-point number.

Additional operations are defined as methods on the `Context`

type.

For convenience, `Decimal128`

overloads many of the standard Rust operators.
For example, you can use the standard `+`

operator to add two values
together:

```
use dec::Decimal128;
let a = Decimal128::from(1);
let b = Decimal128::from(2);
assert_eq!(a + b, Decimal128::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 Decimal128

### impl Decimal128

source#### pub const NAN: Decimal128 = _

#### pub const NAN: Decimal128 = _

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

source#### pub const ZERO: Decimal128 = _

#### pub const ZERO: Decimal128 = _

The value that represents zero.

source#### pub const ONE: Decimal128 = _

#### pub const ONE: Decimal128 = _

The value that represents one.

source#### pub fn from_le_bytes(bytes: [u8; 16]) -> Decimal128

#### pub fn from_le_bytes(bytes: [u8; 16]) -> Decimal128

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

source#### pub fn from_be_bytes(bytes: [u8; 16]) -> Decimal128

#### pub fn from_be_bytes(bytes: [u8; 16]) -> Decimal128

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

source#### pub const fn from_ne_bytes(bytes: [u8; 16]) -> Decimal128

#### pub const fn from_ne_bytes(bytes: [u8; 16]) -> Decimal128

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; 16]

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

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

source#### pub fn to_be_bytes(&self) -> [u8; 16]

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

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

source#### pub fn to_ne_bytes(&self) -> [u8; 16]

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

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

source#### pub fn digits(&self) -> u32

#### 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) -> i128

#### pub fn coefficient(&self) -> i128

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; 34]

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

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

source#### pub fn canonical(self) -> Decimal128

#### pub fn canonical(self) -> Decimal128

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

source#### pub fn is_canonical(&self) -> bool

#### pub fn is_canonical(&self) -> bool

Reports whether the encoding of the number is canonical.

source#### pub fn is_finite(&self) -> bool

#### 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

#### pub fn is_infinite(&self) -> bool

Reports whether the number is positive or negative infinity.

source#### pub fn is_integer(&self) -> bool

#### 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

#### 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_negative(&self) -> bool

#### 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

#### 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

#### 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

#### pub fn is_signaling_nan(&self) -> bool

Reports whether the number is a signaling NaN.

source#### pub fn is_signed(&self) -> bool

#### 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

#### pub fn is_subnormal(&self) -> bool

Reports whether the number is subnormal.

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

source#### pub fn quantum_matches(&self, rhs: &Decimal128) -> bool

#### pub fn quantum_matches(&self, rhs: &Decimal128) -> 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: &Decimal128) -> Ordering

#### pub fn total_cmp(&self, rhs: &Decimal128) -> 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

#### 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<Decimal128> for Decimal128

### impl Add<Decimal128> for Decimal128

#### type Output = Decimal128

#### type Output = Decimal128

`+`

operator.source#### fn add(self, rhs: Decimal128) -> Decimal128

#### fn add(self, rhs: Decimal128) -> Decimal128

`+`

operation. Read moresource### impl Add<OrderedDecimal<Decimal128>> for Decimal128

### impl Add<OrderedDecimal<Decimal128>> for Decimal128

#### type Output = Decimal128

#### type Output = Decimal128

`+`

operator.source#### fn add(self, other: OrderedDecimal<Decimal128>) -> Self

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

`+`

operation. Read moresource### impl AddAssign<Decimal128> for Decimal128

### impl AddAssign<Decimal128> for Decimal128

source#### fn add_assign(&mut self, rhs: Decimal128)

#### fn add_assign(&mut self, rhs: Decimal128)

`+=`

operation. Read moresource### impl Clone for Decimal128

### impl Clone for Decimal128

source#### fn clone(&self) -> Decimal128

#### fn clone(&self) -> Decimal128

1.0.0 · source#### fn clone_from(&mut self, source: &Self)

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

`source`

. Read moresource### impl Debug for Decimal128

### impl Debug for Decimal128

source### impl Default for Decimal128

### impl Default for Decimal128

source#### fn default() -> Decimal128

#### fn default() -> Decimal128

source### impl Display for Decimal128

### impl Display for Decimal128

source### impl Div<Decimal128> for Decimal128

### impl Div<Decimal128> for Decimal128

#### type Output = Decimal128

#### type Output = Decimal128

`/`

operator.source#### fn div(self, rhs: Decimal128) -> Decimal128

#### fn div(self, rhs: Decimal128) -> Decimal128

`/`

operation. Read moresource### impl Div<OrderedDecimal<Decimal128>> for Decimal128

### impl Div<OrderedDecimal<Decimal128>> for Decimal128

#### type Output = Decimal128

#### type Output = Decimal128

`/`

operator.source#### fn div(self, other: OrderedDecimal<Decimal128>) -> Self

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

`/`

operation. Read moresource### impl DivAssign<Decimal128> for Decimal128

### impl DivAssign<Decimal128> for Decimal128

source#### fn div_assign(&mut self, rhs: Decimal128)

#### fn div_assign(&mut self, rhs: Decimal128)

`/=`

operation. Read moresource### impl<const N: usize> From<Decimal128> for Decimal<N>

### impl<const N: usize> From<Decimal128> for Decimal<N>

source#### fn from(n: Decimal128) -> Decimal<N>

#### fn from(n: Decimal128) -> Decimal<N>

source### impl<D> From<Decimal128> for OrderedDecimal<D>where

D: From<Decimal128>,

### impl<D> From<Decimal128> for OrderedDecimal<D>where

D: From<Decimal128>,

source#### fn from(n: Decimal128) -> OrderedDecimal<D>

#### fn from(n: Decimal128) -> OrderedDecimal<D>

source### impl From<Decimal32> for Decimal128

### impl From<Decimal32> for Decimal128

source#### fn from(d32: Decimal32) -> Decimal128

#### fn from(d32: Decimal32) -> Decimal128

source### impl From<Decimal64> for Decimal128

### impl From<Decimal64> for Decimal128

source#### fn from(d64: Decimal64) -> Decimal128

#### fn from(d64: Decimal64) -> Decimal128

source### impl From<i32> for Decimal128

### impl From<i32> for Decimal128

source#### fn from(n: i32) -> Decimal128

#### fn from(n: i32) -> Decimal128

source### impl From<i64> for Decimal128

### impl From<i64> for Decimal128

source#### fn from(n: i64) -> Decimal128

#### fn from(n: i64) -> Decimal128

source### impl From<u32> for Decimal128

### impl From<u32> for Decimal128

source#### fn from(n: u32) -> Decimal128

#### fn from(n: u32) -> Decimal128

source### impl From<u64> for Decimal128

### impl From<u64> for Decimal128

source#### fn from(n: u64) -> Decimal128

#### fn from(n: u64) -> Decimal128

source### impl FromStr for Decimal128

### impl FromStr for Decimal128

#### type Err = ParseDecimalError

#### type Err = ParseDecimalError

source#### fn from_str(s: &str) -> Result<Decimal128, ParseDecimalError>

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

`s`

to return a value of this type. Read moresource### impl Mul<Decimal128> for Decimal128

### impl Mul<Decimal128> for Decimal128

#### type Output = Decimal128

#### type Output = Decimal128

`*`

operator.source#### fn mul(self, rhs: Decimal128) -> Decimal128

#### fn mul(self, rhs: Decimal128) -> Decimal128

`*`

operation. Read moresource### impl Mul<OrderedDecimal<Decimal128>> for Decimal128

### impl Mul<OrderedDecimal<Decimal128>> for Decimal128

#### type Output = Decimal128

#### type Output = Decimal128

`*`

operator.source#### fn mul(self, other: OrderedDecimal<Decimal128>) -> Self

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

`*`

operation. Read moresource### impl MulAssign<Decimal128> for Decimal128

### impl MulAssign<Decimal128> for Decimal128

source#### fn mul_assign(&mut self, rhs: Decimal128)

#### fn mul_assign(&mut self, rhs: Decimal128)

`*=`

operation. Read moresource### impl Neg for Decimal128

### impl Neg for Decimal128

#### type Output = Decimal128

#### type Output = Decimal128

`-`

operator.source#### fn neg(self) -> Decimal128

#### fn neg(self) -> Decimal128

`-`

operation. Read moresource### impl PartialEq<Decimal128> for Decimal128

### impl PartialEq<Decimal128> for Decimal128

source### impl PartialOrd<Decimal128> for Decimal128

### impl PartialOrd<Decimal128> for Decimal128

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

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

1.0.0 · source#### fn le(&self, other: &Rhs) -> bool

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

`self`

and `other`

) and is used by the `<=`

operator. Read moresource### impl<'a> Product<&'a Decimal128> for Decimal128

### impl<'a> Product<&'a Decimal128> for Decimal128

source#### fn product<I>(iter: I) -> Selfwhere

I: Iterator<Item = &'a Decimal128>,

#### fn product<I>(iter: I) -> Selfwhere

I: Iterator<Item = &'a Decimal128>,

`Self`

from the elements by
multiplying the items. Read moresource### impl Product<Decimal128> for Decimal128

### impl Product<Decimal128> for Decimal128

source#### fn product<I>(iter: I) -> Selfwhere

I: Iterator<Item = Decimal128>,

#### fn product<I>(iter: I) -> Selfwhere

I: Iterator<Item = Decimal128>,

`Self`

from the elements by
multiplying the items. Read moresource### impl Rem<Decimal128> for Decimal128

### impl Rem<Decimal128> for Decimal128

#### type Output = Decimal128

#### type Output = Decimal128

`%`

operator.source#### fn rem(self, rhs: Decimal128) -> Decimal128

#### fn rem(self, rhs: Decimal128) -> Decimal128

`%`

operation. Read moresource### impl Rem<OrderedDecimal<Decimal128>> for Decimal128

### impl Rem<OrderedDecimal<Decimal128>> for Decimal128

#### type Output = Decimal128

#### type Output = Decimal128

`%`

operator.source#### fn rem(self, other: OrderedDecimal<Decimal128>) -> Self

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

`%`

operation. Read moresource### impl RemAssign<Decimal128> for Decimal128

### impl RemAssign<Decimal128> for Decimal128

source#### fn rem_assign(&mut self, rhs: Decimal128)

#### fn rem_assign(&mut self, rhs: Decimal128)

`%=`

operation. Read moresource### impl Sub<Decimal128> for Decimal128

### impl Sub<Decimal128> for Decimal128

#### type Output = Decimal128

#### type Output = Decimal128

`-`

operator.source#### fn sub(self, rhs: Decimal128) -> Decimal128

#### fn sub(self, rhs: Decimal128) -> Decimal128

`-`

operation. Read moresource### impl Sub<OrderedDecimal<Decimal128>> for Decimal128

### impl Sub<OrderedDecimal<Decimal128>> for Decimal128

#### type Output = Decimal128

#### type Output = Decimal128

`-`

operator.source#### fn sub(self, other: OrderedDecimal<Decimal128>) -> Self

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

`-`

operation. Read moresource### impl SubAssign<Decimal128> for Decimal128

### impl SubAssign<Decimal128> for Decimal128

source#### fn sub_assign(&mut self, rhs: Decimal128)

#### fn sub_assign(&mut self, rhs: Decimal128)

`-=`

operation. Read moresource### impl<'a> Sum<&'a Decimal128> for Decimal128

### impl<'a> Sum<&'a Decimal128> for Decimal128

source#### fn sum<I>(iter: I) -> Selfwhere

I: Iterator<Item = &'a Decimal128>,

#### fn sum<I>(iter: I) -> Selfwhere

I: Iterator<Item = &'a Decimal128>,

`Self`

from the elements by
“summing up” the items. Read moresource### impl Sum<Decimal128> for Decimal128

### impl Sum<Decimal128> for Decimal128

source#### fn sum<I>(iter: I) -> Selfwhere

I: Iterator<Item = Decimal128>,

#### fn sum<I>(iter: I) -> Selfwhere

I: Iterator<Item = Decimal128>,

`Self`

from the elements by
“summing up” the items. Read more