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
impl Decimal64
sourcepub fn from_le_bytes(bytes: [u8; 8]) -> Decimal64
pub fn from_le_bytes(bytes: [u8; 8]) -> Decimal64
Creates a number from its representation as a little-endian byte array.
sourcepub fn from_be_bytes(bytes: [u8; 8]) -> Decimal64
pub fn from_be_bytes(bytes: [u8; 8]) -> Decimal64
Creates a number from its representation as a big-endian byte array.
sourcepub const fn from_ne_bytes(bytes: [u8; 8]) -> Decimal64
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.
sourcepub fn to_le_bytes(&self) -> [u8; 8]
pub fn to_le_bytes(&self) -> [u8; 8]
Returns the memory representation of the number as a byte array in little-endian order.
sourcepub fn to_be_bytes(&self) -> [u8; 8]
pub fn to_be_bytes(&self) -> [u8; 8]
Returns the memory representation of the number as a byte array in big-endian order.
sourcepub fn to_ne_bytes(&self) -> [u8; 8]
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.
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) -> i64
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.
sourcepub fn coefficient_digits(&self) -> [u8; 16]
pub fn coefficient_digits(&self) -> [u8; 16]
Returns the individual digits of the coefficient in 8-bit, unpacked binary-coded decimal format.
sourcepub fn canonical(self) -> Decimal64
pub fn canonical(self) -> Decimal64
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: &Decimal64) -> bool
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.
sourcepub fn total_cmp(&self, rhs: &Decimal64) -> Ordering
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
.
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 AddAssign for Decimal64
impl AddAssign for Decimal64
source§fn add_assign(&mut self, rhs: Decimal64)
fn add_assign(&mut self, rhs: Decimal64)
+=
operation. Read moresource§impl DivAssign for Decimal64
impl DivAssign for Decimal64
source§fn div_assign(&mut self, rhs: Decimal64)
fn div_assign(&mut self, rhs: Decimal64)
/=
operation. Read moresource§impl From<Decimal64> for Decimal128
impl From<Decimal64> for Decimal128
source§fn from(d64: Decimal64) -> Decimal128
fn from(d64: Decimal64) -> Decimal128
source§impl<D> From<Decimal64> for OrderedDecimal<D>
impl<D> From<Decimal64> for OrderedDecimal<D>
source§fn from(n: Decimal64) -> OrderedDecimal<D>
fn from(n: Decimal64) -> OrderedDecimal<D>
source§impl MulAssign for Decimal64
impl MulAssign for Decimal64
source§fn mul_assign(&mut self, rhs: Decimal64)
fn mul_assign(&mut self, rhs: Decimal64)
*=
operation. Read moresource§impl PartialEq for Decimal64
impl PartialEq for Decimal64
source§impl PartialOrd for Decimal64
impl PartialOrd for Decimal64
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 RemAssign for Decimal64
impl RemAssign for Decimal64
source§fn rem_assign(&mut self, rhs: Decimal64)
fn rem_assign(&mut self, rhs: Decimal64)
%=
operation. Read moresource§impl SubAssign for Decimal64
impl SubAssign for Decimal64
source§fn sub_assign(&mut self, rhs: Decimal64)
fn sub_assign(&mut self, rhs: Decimal64)
-=
operation. Read more