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
Sourcepub const NAN: Decimal128 = _
pub const NAN: Decimal128 = _
The value that represents Not-a-Number (NaN).
Sourcepub const ZERO: Decimal128 = _
pub const ZERO: Decimal128 = _
The value that represents zero.
Sourcepub const ONE: Decimal128 = _
pub const ONE: Decimal128 = _
The value that represents one.
Sourcepub 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.
Sourcepub 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.
Sourcepub 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.
Sourcepub 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.
Sourcepub 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.
Sourcepub 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.
Sourcepub 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.
Sourcepub 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.
Sourcepub 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.
Sourcepub fn canonical(self) -> Decimal128
pub fn canonical(self) -> Decimal128
Returns an equivalent number whose encoding is guaranteed to be canonical.
Sourcepub fn is_canonical(&self) -> bool
pub fn is_canonical(&self) -> bool
Reports whether the encoding of the number is canonical.
Sourcepub 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.
Sourcepub fn is_infinite(&self) -> bool
pub fn is_infinite(&self) -> bool
Reports whether the number is positive or negative infinity.
Sourcepub 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.
Sourcepub 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.
Sourcepub fn is_negative(&self) -> bool
pub fn is_negative(&self) -> bool
Reports whether the number is less than zero and not a NaN.
Sourcepub 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.
Sourcepub fn is_positive(&self) -> bool
pub fn is_positive(&self) -> bool
Reports whether the number is greater than zero and not a NaN.
Sourcepub fn is_signaling_nan(&self) -> bool
pub fn is_signaling_nan(&self) -> bool
Reports whether the number is a signaling NaN.
Sourcepub 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.
Sourcepub 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 10emin.
Sourcepub 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.
Sourcepub 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
.
Sourcepub 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<OrderedDecimal<Decimal128>> for Decimal128
impl Add<OrderedDecimal<Decimal128>> for Decimal128
Source§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 Add for Decimal128
impl Add for Decimal128
Source§type Output = Decimal128
type Output = Decimal128
+
operator.Source§fn add(self, rhs: Decimal128) -> Decimal128
fn add(self, rhs: Decimal128) -> Decimal128
+
operation. Read moreSource§impl AddAssign for Decimal128
impl AddAssign 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<OrderedDecimal<Decimal128>> for Decimal128
impl Div<OrderedDecimal<Decimal128>> for Decimal128
Source§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 Div for Decimal128
impl Div for Decimal128
Source§type Output = Decimal128
type Output = Decimal128
/
operator.Source§fn div(self, rhs: Decimal128) -> Decimal128
fn div(self, rhs: Decimal128) -> Decimal128
/
operation. Read moreSource§impl DivAssign for Decimal128
impl DivAssign 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
Source§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<OrderedDecimal<Decimal128>> for Decimal128
impl Mul<OrderedDecimal<Decimal128>> for Decimal128
Source§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 Mul for Decimal128
impl Mul for Decimal128
Source§type Output = Decimal128
type Output = Decimal128
*
operator.Source§fn mul(self, rhs: Decimal128) -> Decimal128
fn mul(self, rhs: Decimal128) -> Decimal128
*
operation. Read moreSource§impl MulAdd for Decimal128
impl MulAdd for Decimal128
Source§impl MulAddAssign for Decimal128
impl MulAddAssign for Decimal128
Source§fn mul_add_assign(&mut self, a: Self, b: Self)
fn mul_add_assign(&mut self, a: Self, b: Self)
*self = (*self * a) + b
Source§impl MulAssign for Decimal128
impl MulAssign 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
Source§type Output = Decimal128
type Output = Decimal128
-
operator.Source§fn neg(self) -> Decimal128
fn neg(self) -> Decimal128
-
operation. Read moreSource§impl One for Decimal128
impl One for Decimal128
Source§impl PartialEq for Decimal128
impl PartialEq for Decimal128
Source§impl PartialOrd for Decimal128
impl PartialOrd for Decimal128
Source§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.Source§impl Product for Decimal128
impl Product 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.Source§impl Rem<OrderedDecimal<Decimal128>> for Decimal128
impl Rem<OrderedDecimal<Decimal128>> for Decimal128
Source§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 Rem for Decimal128
impl Rem for Decimal128
Source§type Output = Decimal128
type Output = Decimal128
%
operator.Source§fn rem(self, rhs: Decimal128) -> Decimal128
fn rem(self, rhs: Decimal128) -> Decimal128
%
operation. Read moreSource§impl RemAssign for Decimal128
impl RemAssign for Decimal128
Source§fn rem_assign(&mut self, rhs: Decimal128)
fn rem_assign(&mut self, rhs: Decimal128)
%=
operation. Read moreSource§impl Sub<OrderedDecimal<Decimal128>> for Decimal128
impl Sub<OrderedDecimal<Decimal128>> for Decimal128
Source§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 Sub for Decimal128
impl Sub for Decimal128
Source§type Output = Decimal128
type Output = Decimal128
-
operator.Source§fn sub(self, rhs: Decimal128) -> Decimal128
fn sub(self, rhs: Decimal128) -> Decimal128
-
operation. Read moreSource§impl SubAssign for Decimal128
impl SubAssign 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.Source§impl Sum for Decimal128
impl Sum 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.