Struct dec::Decimal128
source · 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
§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
§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
§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
§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
§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
§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
§type Output = Decimal128
type Output = Decimal128
*
operator.source§fn mul(self, rhs: Decimal128) -> Decimal128
fn mul(self, rhs: Decimal128) -> Decimal128
*
operation. Read moresource§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
§type Output = Decimal128
type Output = Decimal128
-
operator.source§fn neg(self) -> Decimal128
fn neg(self) -> Decimal128
-
operation. Read moresource§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
§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
§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
§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
§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.impl Copy for Decimal128
Auto Trait Implementations§
impl Freeze for Decimal128
impl RefUnwindSafe for Decimal128
impl Send for Decimal128
impl Sync for Decimal128
impl Unpin for Decimal128
impl UnwindSafe for Decimal128
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)source§impl<T> CloneToUninit for Twhere
T: Copy,
impl<T> CloneToUninit for Twhere
T: Copy,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)