mz_repr::adt::numeric

Type Alias NumericAgg

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

Source

pub fn zero() -> Decimal<N>

Constructs a decimal number with N / 3 digits of precision representing the number 0.

Source

pub fn infinity() -> Decimal<N>

Constructs a decimal number representing positive infinity.

Source

pub fn nan() -> Decimal<N>

Constructs a decimal number representing a non-signaling NaN.

Source

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_digits(&self) -> Vec<u8>

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

Source

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.

Source

pub fn coefficient<T>(&mut self) -> Result<T, InvalidCoefficientError>
where T: TryFrom<Decimal<N>>,

Returns the value’s coefficient as T or errors if not possible.

All primitive ints are valid for T.

Source

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.

Source

pub fn exponent(&self) -> i32

Computes the exponent of the number.

Source

pub fn set_exponent(&mut self, exponent: i32)

Sets self’s exponent to the provided value.

Source

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

Reports whether the number is positive or negative infinity.

Source

pub fn is_nan(&self) -> bool

Reports whether the number is a NaN.

Source

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.

Source

pub fn is_quiet_nan(&self) -> bool

Reports whether the number is a quiet NaN.

Source

pub fn is_signaling_nan(&self) -> bool

Reports whether the number is a signaling NaN.

Source

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.

Source

pub fn is_zero(&self) -> bool

Reports whether the number is positive or negative zero.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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
Source

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.

Source

pub fn trim(&mut self)

Removes insignificant trailing zeros from a number, unconditionally, and stores the modified value in self.

Trait Implementations§

Source§

impl Dec<NUMERIC_AGG_WIDTH_USIZE> for NumericAgg

Source§

impl<const M: usize, const N: usize> Add<Decimal<M>> for Decimal<N>

Source§

fn add(self, rhs: Decimal<M>) -> Decimal<N>

Note that this clones self to generate the output. For a non-cloning method, use Context::<N>::add.

Source§

type Output = Decimal<N>

The resulting type after applying the + operator.
Source§

impl<const M: usize, const N: usize> AddAssign<Decimal<M>> for Decimal<N>

Source§

fn add_assign(&mut self, rhs: Decimal<M>)

Performs the += operation. Read more
Source§

impl<const N: usize> Clone for Decimal<N>

Source§

fn clone(&self) -> Decimal<N>

Returns a copy of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<const N: usize> Debug for Decimal<N>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl<const N: usize> Default for Decimal<N>

Source§

fn default() -> Decimal<N>

Returns the “default value” for a type. Read more
Source§

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

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<const N: usize> Display for Decimal<N>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl<const M: usize, const N: usize> Div<Decimal<M>> for Decimal<N>

Source§

fn div(self, rhs: Decimal<M>) -> Decimal<N>

Note that this clones self to generate the output. For a non-cloning method, use Context::<N>::div.

Source§

type Output = Decimal<N>

The resulting type after applying the / operator.
Source§

impl<const M: usize, const N: usize> DivAssign<Decimal<M>> for Decimal<N>

Source§

fn div_assign(&mut self, rhs: Decimal<M>)

Performs the /= operation. Read more
Source§

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

Source§

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

Converts to this type from the input type.
Source§

impl<const N: usize> From<Decimal32> for Decimal<N>

Source§

fn from(n: Decimal32) -> Decimal<N>

Converts to this type from the input type.
Source§

impl<const N: usize> From<Decimal64> for Decimal<N>

Source§

fn from(n: Decimal64) -> Decimal<N>

Converts to this type from the input type.
Source§

impl<const N: usize> From<f32> for Decimal<N>

Source§

fn from(n: f32) -> Decimal<N>

Converts to this type from the input type.
Source§

impl<const N: usize> From<f64> for Decimal<N>

Source§

fn from(n: f64) -> Decimal<N>

Converts to this type from the input type.
Source§

impl<const N: usize> From<i16> for Decimal<N>

Source§

fn from(n: i16) -> Decimal<N>

Converts to this type from the input type.
Source§

impl<const N: usize> From<i32> for Decimal<N>

Source§

fn from(n: i32) -> Decimal<N>

Converts to this type from the input type.
Source§

impl<const N: usize> From<i64> for Decimal<N>

Source§

fn from(n: i64) -> Decimal<N>

Converts to this type from the input type.
Source§

impl<const N: usize> From<i8> for Decimal<N>

Source§

fn from(n: i8) -> Decimal<N>

Converts to this type from the input type.
Source§

impl<const N: usize> From<isize> for Decimal<N>

Source§

fn from(n: isize) -> Decimal<N>

Converts to this type from the input type.
Source§

impl<const N: usize> From<u16> for Decimal<N>

Source§

fn from(n: u16) -> Decimal<N>

Converts to this type from the input type.
Source§

impl<const N: usize> From<u32> for Decimal<N>

Source§

fn from(n: u32) -> Decimal<N>

Converts to this type from the input type.
Source§

impl<const N: usize> From<u64> for Decimal<N>

Source§

fn from(n: u64) -> Decimal<N>

Converts to this type from the input type.
Source§

impl<const N: usize> From<u8> for Decimal<N>

Source§

fn from(n: u8) -> Decimal<N>

Converts to this type from the input type.
Source§

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

Source§

fn from(n: usize) -> Decimal<N>

Converts to this type from the input type.
Source§

impl<const N: usize> FromStr for Decimal<N>

Source§

type Err = ParseDecimalError

The associated error which can be returned from parsing.
Source§

fn from_str(s: &str) -> Result<Decimal<N>, ParseDecimalError>

Parses a string s to return a value of this type. Read more
Source§

impl<const M: usize, const N: usize> Mul<Decimal<M>> for Decimal<N>

Source§

fn mul(self, rhs: Decimal<M>) -> Decimal<N>

Note that this clones self to generate the output. For a non-cloning method, use Context::<N>::mul.

Source§

type Output = Decimal<N>

The resulting type after applying the * operator.
Source§

impl<const N: usize, const L: usize, const M: usize> MulAdd<Decimal<L>, Decimal<M>> for Decimal<N>

Source§

type Output = Decimal<N>

The resulting type after applying the fused multiply-add.
Source§

fn mul_add( self, a: Decimal<L>, b: Decimal<M>, ) -> <Decimal<N> as MulAdd<Decimal<L>, Decimal<M>>>::Output

Performs the fused multiply-add operation (self * a) + b
Source§

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

Performs the fused multiply-add assignment operation *self = (*self * a) + b
Source§

impl<const M: usize, const N: usize> MulAssign<Decimal<M>> for Decimal<N>

Source§

fn mul_assign(&mut self, rhs: Decimal<M>)

Performs the *= operation. Read more
Source§

impl<const N: usize> Neg for Decimal<N>

Source§

fn neg(self) -> Decimal<N>

Note that this clones self to generate the negative value. For a non-cloning method, use Context::<N>::neg.

Source§

type Output = Decimal<N>

The resulting type after applying the - operator.
Source§

impl<const N: usize> PartialEq for Decimal<N>

Source§

fn eq(&self, other: &Decimal<N>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<const N: usize> PartialOrd for Decimal<N>

Source§

fn partial_cmp(&self, other: &Decimal<N>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

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

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

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

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

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

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<const N: usize, const M: usize> Pow<Decimal<M>> for Decimal<N>

Source§

type Output = Decimal<N>

The result after applying the operator.
Source§

fn pow(self, rhs: Decimal<M>) -> <Decimal<N> as Pow<Decimal<M>>>::Output

Returns self to the power rhs. Read more
Source§

impl<'a, const M: usize, const N: usize> Product<&'a Decimal<M>> for Decimal<N>

Source§

fn product<I>(iter: I) -> Decimal<N>
where I: Iterator<Item = &'a Decimal<M>>,

Takes an iterator and generates Self from the elements by multiplying the items.
Source§

impl<const M: usize, const N: usize> Product<Decimal<M>> for Decimal<N>

Source§

fn product<I>(iter: I) -> Decimal<N>
where I: Iterator<Item = Decimal<M>>,

Takes an iterator and generates Self from the elements by multiplying the items.
Source§

impl<const M: usize, const N: usize> Rem<Decimal<M>> for Decimal<N>

Source§

fn rem(self, rhs: Decimal<M>) -> Decimal<N>

Note that this clones self to generate the output. For a non-cloning method, use Context::<N>::rem.

Source§

type Output = Decimal<N>

The resulting type after applying the % operator.
Source§

impl<const M: usize, const N: usize> RemAssign<Decimal<M>> for Decimal<N>

Source§

fn rem_assign(&mut self, rhs: Decimal<M>)

Performs the %= operation. Read more
Source§

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,

Serialize this value into the given Serde serializer. Read more
Source§

impl<const M: usize, const N: usize> Sub<Decimal<M>> for Decimal<N>

Source§

fn sub(self, rhs: Decimal<M>) -> Decimal<N>

Note that this clones self to generate the output. For a non-cloning method, use Context::<N>::sub.

Source§

type Output = Decimal<N>

The resulting type after applying the - operator.
Source§

impl<const M: usize, const N: usize> SubAssign<Decimal<M>> for Decimal<N>

Source§

fn sub_assign(&mut self, rhs: Decimal<M>)

Performs the -= operation. Read more
Source§

impl<'a, const M: usize, const N: usize> Sum<&'a Decimal<M>> for Decimal<N>

Source§

fn sum<I>(iter: I) -> Decimal<N>
where I: Iterator<Item = &'a Decimal<M>>,

Takes an iterator and generates Self from the elements by “summing up” the items.
Source§

impl<const M: usize, const N: usize> Sum<Decimal<M>> for Decimal<N>

Source§

fn sum<I>(iter: I) -> Decimal<N>
where I: Iterator<Item = Decimal<M>>,

Takes an iterator and generates Self from the elements by “summing up” the items.
Source§

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§

type Error = TryIntoDecimalError

The type returned in the event of a conversion error.
Source§

fn try_from(n: i128) -> Result<Decimal<N>, <Decimal<N> as TryFrom<i128>>::Error>

Performs the conversion.
Source§

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.

Source§

type Error = TryIntoDecimalError

The type returned in the event of a conversion error.
Source§

fn try_from(n: u128) -> Result<Decimal<N>, <Decimal<N> as TryFrom<u128>>::Error>

Performs the conversion.
Source§

impl<const N: usize> Zero for Decimal<N>

Source§

fn zero() -> Decimal<N>

Returns the additive identity element of Self, 0. Read more
Source§

fn is_zero(&self) -> bool

Returns true if self is equal to the additive identity.
Source§

fn set_zero(&mut self)

Sets self to the additive identity element of Self, 0.
Source§

impl<const N: usize> Copy for Decimal<N>