Skip to main content

Module decimal

Module decimal 

Source
Expand description

Core utilities for handling decimal numbers in financial calculations.

Constants§

DIV_DEFAULT_SCALE
Scale applied to banker’s-rounding divisions in d_div.
ONE_DAY
Represents the daily interest rate factor used for financial calculations, approximately equivalent to 1/252 (a standard value for the number of trading days in a year).

Traits§

DecimalStats
Defines statistical operations for collections of decimal values.

Functions§

d_add
Checked Decimal addition with operand-preserving overflow reporting.
d_div
Checked Decimal division with banker’s rounding at scale 28.
d_exp
Checked e^x with underflow flushed to zero.
d_exp_f64
Exponential evaluated in f64, for the per-step walk kernels (#860).
d_ln
Checked natural logarithm.
d_ln_f64
Natural logarithm evaluated in f64, for the numeric kernels (#857).
d_mul
Checked Decimal multiplication with operand-preserving overflow reporting.
d_powd
Checked base^exponent.
d_product_iter
Checked product over any IntoIterator of Decimal values.
d_sqrt
Checked square root.
d_sqrt_f64
Square root evaluated in f64, for the per-step walk kernels (#860).
d_sub
Checked Decimal subtraction with operand-preserving overflow reporting.
d_sum
Checked sum over a slice of Decimal values.
d_sum_iter
Checked sum over any IntoIterator of Decimal values.
decimal_normal_sample
Draws a standard normal sample from the thread-local RNG, as a Decimal.
decimal_normal_sample_with
Draws a standard normal sample from rng, as a Decimal.
decimal_to_f64
Converts a Decimal to the f64 nearest to it (ties to even).
decimal_uniform_sample_with
Draws a uniform sample on [0, 1) from rng, as a Decimal.
f64_to_decimal
Converts an f64 floating-point number to a Decimal.
finite_decimal
Attempts to convert a finite f64 into a Decimal.
p_sqrt
Checked square root of a Positive, routed through d_sqrt so that no production path reaches the panicking upstream sqrt that Positive::checked_sqrt still wraps (#588).