pub type NumericAgg = Decimal<NUMERIC_AGG_WIDTH_USIZE>;
Expand description
A double-width version of Numeric
for use in aggregations.
Aliased Type§
struct NumericAgg { /* private fields */ }
Implementations
Source§impl<const N: usize> Decimal<N>
impl<const N: usize> Decimal<N>
Sourcepub fn zero() -> Decimal<N>
pub fn zero() -> Decimal<N>
Constructs a decimal number with N / 3
digits of precision
representing the number 0.
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_digits(&self) -> Vec<u8> ⓘ
pub fn coefficient_digits(&self) -> Vec<u8> ⓘ
Returns the individual digits of the coefficient in 8-bit, unpacked binary-coded decimal format.
Sourcepub fn coefficient_units(&self) -> &[u16]
pub fn coefficient_units(&self) -> &[u16]
Returns the digits of the coefficient in [decNumberUnit
][dnu] format,
which is a vector of u16
, with element number representing
decnumber_sys::DECDPUN
digits of the coefficient.
The result is ordered with the least significant digits at index 0.
Sourcepub fn coefficient<T>(&mut self) -> Result<T, InvalidCoefficientError>
pub fn coefficient<T>(&mut self) -> Result<T, InvalidCoefficientError>
Returns the value’s coefficient as T
or errors if not possible.
All primitive ints are valid for T
.
Sourcepub fn digits_to_lsu_elements_len(digits: u32) -> usize
pub fn digits_to_lsu_elements_len(digits: u32) -> usize
Returns the number of elements required in the lsu
to represent some
number of digits.
This function is public and accepts a u32
instead of a Decimal
to
aid in recomposing (Self::from_raw_parts
) values.
Sourcepub fn set_exponent(&mut self, exponent: i32)
pub fn set_exponent(&mut self, exponent: i32)
Sets self
’s exponent to the provided value.
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_negative(&self) -> bool
pub fn is_negative(&self) -> bool
Reports whether the number is negative.
A negative number is either negative zero, less than zero, or NaN
with a sign of one. This corresponds to Decimal128::is_signed
, not
Decimal128::is_negative
.
Sourcepub fn is_quiet_nan(&self) -> bool
pub fn is_quiet_nan(&self) -> bool
Reports whether the number is a quiet 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_special(&self) -> bool
pub fn is_special(&self) -> bool
Reports whether the number has a special value.
A special value is either infinity or NaN. This is the inverse of
Decimal::is_finite
.
Sourcepub fn quantum_matches(&self, rhs: &Decimal<N>) -> bool
pub fn quantum_matches(&self, rhs: &Decimal<N>) -> 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 to_decimal32(&self) -> Decimal32
pub fn to_decimal32(&self) -> Decimal32
Converts this decimal to a 32-bit decimal float.
The result may be inexact. Use Context::<Decimal32>::from_decimal
to observe exceptional conditions.
Sourcepub fn to_decimal64(&self) -> Decimal64
pub fn to_decimal64(&self) -> Decimal64
Converts this decimal to a 64-bit decimal float.
The result may be inexact. Use Context::<Decimal64>::from_decimal
to observe exceptional conditions.
Sourcepub fn to_decimal128(&self) -> Decimal128
pub fn to_decimal128(&self) -> Decimal128
Converts this decimal to a 128-bit decimal float.
The result may be inexact. Use Context::<Decimal128>::from_decimal
to observe exceptional conditions.
Sourcepub fn to_raw_parts(&self) -> (u32, i32, u8, [u16; N])
pub fn to_raw_parts(&self) -> (u32, i32, u8, [u16; N])
Returns the raw parts of this decimal.
The meaning of these parts are unspecified and subject to change. The
only guarantee is that these parts can be supplied as arguments to the
Decimal::from_raw_parts
to produce a decimal equivalent to the
original.
Sourcepub fn from_raw_parts(
digits: u32,
exponent: i32,
bits: u8,
lsu: [u16; N],
) -> Decimal<N>
pub fn from_raw_parts( digits: u32, exponent: i32, bits: u8, lsu: [u16; N], ) -> Decimal<N>
Returns a Decimal::<N>
with the supplied raw parts, which should be
generated using Decimal::to_raw_parts
.
Sourcepub fn to_packed_bcd(&mut self) -> Option<(Vec<u8>, i32)>
pub fn to_packed_bcd(&mut self) -> Option<(Vec<u8>, i32)>
Returns self
as a Packed Decimal number, including its scale
(i.e. its negated exponent) or None
for special values.
Sourcepub fn from_packed_bcd(
bcd: &[u8],
scale: i32,
) -> Result<Decimal<N>, FromBcdError>
pub fn from_packed_bcd( bcd: &[u8], scale: i32, ) -> Result<Decimal<N>, FromBcdError>
Takes Packed Decimal values and their scales (generated by
Self::to_packed_bcd
) and returns a Decimal
.
§Errors
bcd
contains more digits than the coefficient permits- The adjusted exponent is out of range
- No sign nibble was found
- A sign nibble was found before the final nibble
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 Dec<NUMERIC_AGG_WIDTH_USIZE> for NumericAgg
impl Dec<NUMERIC_AGG_WIDTH_USIZE> for NumericAgg
const TWOS_COMPLEMENT_BYTE_WIDTH: usize = 33usize
fn context() -> Context<NumericAgg>
fn u128_splitter() -> &'static NumericAgg
Source§impl<const M: usize, const N: usize> AddAssign<Decimal<M>> for Decimal<N>
impl<const M: usize, const N: usize> AddAssign<Decimal<M>> for Decimal<N>
Source§fn add_assign(&mut self, rhs: Decimal<M>)
fn add_assign(&mut self, rhs: Decimal<M>)
+=
operation. Read moreSource§impl<'de, const N: usize> Deserialize<'de> for Decimal<N>
impl<'de, const N: usize> Deserialize<'de> for Decimal<N>
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<Decimal<N>, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<Decimal<N>, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Source§impl<const M: usize, const N: usize> DivAssign<Decimal<M>> for Decimal<N>
impl<const M: usize, const N: usize> DivAssign<Decimal<M>> for Decimal<N>
Source§fn div_assign(&mut self, rhs: Decimal<M>)
fn div_assign(&mut self, rhs: Decimal<M>)
/=
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<const N: usize, const L: usize, const M: usize> MulAdd<Decimal<L>, Decimal<M>> for Decimal<N>
impl<const N: usize, const L: usize, const M: usize> MulAdd<Decimal<L>, Decimal<M>> for Decimal<N>
Source§impl<const N: usize, const L: usize, const M: usize> MulAddAssign<Decimal<L>, Decimal<M>> for Decimal<N>
impl<const N: usize, const L: usize, const M: usize> MulAddAssign<Decimal<L>, Decimal<M>> for Decimal<N>
Source§fn mul_add_assign(&mut self, a: Decimal<L>, b: Decimal<M>)
fn mul_add_assign(&mut self, a: Decimal<L>, b: Decimal<M>)
*self = (*self * a) + b
Source§impl<const M: usize, const N: usize> MulAssign<Decimal<M>> for Decimal<N>
impl<const M: usize, const N: usize> MulAssign<Decimal<M>> for Decimal<N>
Source§fn mul_assign(&mut self, rhs: Decimal<M>)
fn mul_assign(&mut self, rhs: Decimal<M>)
*=
operation. Read moreSource§impl<const N: usize> PartialOrd for Decimal<N>
impl<const N: usize> PartialOrd for Decimal<N>
Source§impl<const M: usize, const N: usize> RemAssign<Decimal<M>> for Decimal<N>
impl<const M: usize, const N: usize> RemAssign<Decimal<M>> for Decimal<N>
Source§fn rem_assign(&mut self, rhs: Decimal<M>)
fn rem_assign(&mut self, rhs: Decimal<M>)
%=
operation. Read moreSource§impl<const N: usize> Serialize for Decimal<N>
impl<const N: usize> Serialize for Decimal<N>
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
Source§impl<const M: usize, const N: usize> SubAssign<Decimal<M>> for Decimal<N>
impl<const M: usize, const N: usize> SubAssign<Decimal<M>> for Decimal<N>
Source§fn sub_assign(&mut self, rhs: Decimal<M>)
fn sub_assign(&mut self, rhs: Decimal<M>)
-=
operation. Read moreSource§impl<const N: usize> TryFrom<i128> for Decimal<N>
impl<const N: usize> TryFrom<i128> for Decimal<N>
Generates a Decimal
from an i128
or fails if the result would be
imprecise, e.g. has more than N*3
digits of precision.
For an infallible version of this function, see
Context<Decimal<N>>::from_i128
.
Source§impl<const N: usize> TryFrom<u128> for Decimal<N>
impl<const N: usize> TryFrom<u128> for Decimal<N>
Generates a Decimal
from a u128
or fails if the result would be
imprecise, e.g. has more than N*3
digits of precision.
For an infallible version of this function, see
Context<Decimal<N>>::from_u128
.