#[repr(transparent)]pub struct D38<const SCALE: u32>(pub i128);Expand description
Scaled fixed-point decimal with 128-bit storage.
SCALE is the base-10 exponent. A logical value v is stored as
v * 10^SCALE in the underlying i128. For example, with SCALE = 12
the number 1.5 is stored as i128(1_500_000_000_000).
§Precision
N/A: type definition, no arithmetic performed.
§Determinism
All arithmetic is integer arithmetic on i128. The same inputs produce
the same bit-pattern on every platform.
§Equality and ordering
Hash, Eq, and Ord are derived from i128. Two D38<S> values
are equal if and only if their underlying i128 fields are bit-equal.
This works because the scale is fixed at compile time – each logical
value has exactly one representation.
§Const-generic scale
The const generic allows scale variants (D38<9>, D38<6>, etc.)
as trivial type aliases without duplicating any method implementations.
Mixed-scale arithmetic is deliberately not provided; callers convert
explicitly.
Tuple Fields§
§0: i128Implementations§
Source§impl<const SCALE: u32> D38<SCALE>
impl<const SCALE: u32> D38<SCALE>
Sourcepub fn mul_with(self, rhs: Self, mode: RoundingMode) -> Self
pub fn mul_with(self, rhs: Self, mode: RoundingMode) -> Self
Multiply two values of the same scale, rounding the
scale-narrowing divide by 10^SCALE according to mode.
The default Mul operator delegates to this with the
crate-default rounding mode; call mul_with directly when
you need a non-default rounding rule (e.g.
HalfAwayFromZero for commercial rounding, Floor/Ceiling
for one-sided bracketing).
§Panics
Panics in debug builds when the rescaled quotient overflows
i128. Wraps two’s-complement in release builds.
§Precision
Strict: integer-only arithmetic. Within 0.5 ULP for the half-* family; directed rounding otherwise.
Sourcepub fn div_with(self, rhs: Self, mode: RoundingMode) -> Self
pub fn div_with(self, rhs: Self, mode: RoundingMode) -> Self
Divide two values of the same scale, rounding the final
divide step according to mode.
The default Div operator delegates to this with the
crate-default rounding mode.
§Panics
Panics on division by zero (matching i128 /). Panics in debug
builds when the quotient overflows i128; wraps in release.
§Precision
Strict: integer-only arithmetic. Within 0.5 ULP for the half-* family; directed rounding otherwise.
Source§impl<const SCALE: u32> D38<SCALE>
impl<const SCALE: u32> D38<SCALE>
Sourcepub const EPSILON: Self
pub const EPSILON: Self
Smallest representable positive value: 1 LSB = 10^-SCALE.
Provided as an analogue to f64::EPSILON for generic numeric code.
Note that this differs from the f64 definition (“difference between
1.0 and the next-larger f64”): for D38 the LSB is uniform across
the entire representable range.
§Precision
N/A: constant value, no arithmetic performed.
Sourcepub const MIN_POSITIVE: Self
pub const MIN_POSITIVE: Self
Smallest positive value (equal to Self::EPSILON).
Provided as an analogue to f64::MIN_POSITIVE for generic numeric
code. Unlike f64, D38 has no subnormals, so MIN_POSITIVE
and EPSILON are the same value.
§Precision
N/A: constant value, no arithmetic performed.
Source§impl<const SCALE: u32> D38<SCALE>
impl<const SCALE: u32> D38<SCALE>
Sourcepub const SCALE: u32 = SCALE
pub const SCALE: u32 = SCALE
The decimal scale of this type, equal to the SCALE
const-generic parameter. One LSB of storage represents
10^-SCALE. Use in type-level / const contexts; prefer
Self::scale when an instance is in hand.
Sourcepub const ZERO: Self
pub const ZERO: Self
The additive identity. Stored as zero bits.
§Precision
N/A: constant value, no arithmetic performed.
Sourcepub const ONE: Self
pub const ONE: Self
The multiplicative identity. Stored as 10^SCALE bits.
§Precision
N/A: constant value, no arithmetic performed.
Sourcepub const MAX: Self
pub const MAX: Self
The largest representable value: the storage type’s MAX.
Arithmetic that overflows this bound panics in debug builds and wraps in release builds.
Sourcepub const MIN: Self
pub const MIN: Self
The smallest representable value: the storage type’s MIN.
Mirror of Self::MAX. Note that -MIN panics in debug
builds because two’s-complement MIN has no positive
counterpart.
Sourcepub const fn from_bits(raw: i128) -> Self
pub const fn from_bits(raw: i128) -> Self
Constructs from a raw storage bit pattern.
The integer is interpreted directly as the internal storage:
raw represents the logical value raw * 10^(-SCALE). This
is the inverse of Self::to_bits.
§Precision
Strict: all arithmetic is integer-only; result is bit-exact.
Sourcepub const fn to_bits(self) -> i128
pub const fn to_bits(self) -> i128
Returns the raw storage value.
The returned integer encodes the logical value
self * 10^SCALE. This is the inverse of Self::from_bits.
§Precision
Strict: all arithmetic is integer-only; result is bit-exact.
Sourcepub const fn multiplier() -> i128
pub const fn multiplier() -> i128
Returns 10^SCALE, the factor that converts a logical
integer value to its storage representation. Equals the
bit pattern of Self::ONE.
§Precision
Strict: all arithmetic is integer-only; result is bit-exact.
§Overflow
10^SCALE overflows the storage type at SCALE > MAX_SCALE.
Calling with an overflowing scale panics at compile time
when the const item is evaluated.
Source§impl<const SCALE: u32> D38<SCALE>
impl<const SCALE: u32> D38<SCALE>
Sourcepub const fn unsigned_shr(self, n: u32) -> Self
pub const fn unsigned_shr(self, n: u32) -> Self
Logical (zero-fill) right shift of the raw storage by n
bits. Unlike the arithmetic Shr operator, the vacated
high bits are always zero regardless of sign.
Sourcepub const fn rotate_left(self, n: u32) -> Self
pub const fn rotate_left(self, n: u32) -> Self
Rotate the raw storage left by n bits.
Sourcepub const fn rotate_right(self, n: u32) -> Self
pub const fn rotate_right(self, n: u32) -> Self
Rotate the raw storage right by n bits.
Sourcepub const fn leading_zeros(self) -> u32
pub const fn leading_zeros(self) -> u32
Number of leading zero bits in the raw storage.
Sourcepub const fn trailing_zeros(self) -> u32
pub const fn trailing_zeros(self) -> u32
Number of trailing zero bits in the raw storage.
Sourcepub const fn count_ones(self) -> u32
pub const fn count_ones(self) -> u32
Population count of the raw storage.
Sourcepub const fn count_zeros(self) -> u32
pub const fn count_zeros(self) -> u32
Number of zero bits in the raw storage.
Sourcepub const fn is_power_of_two(self) -> bool
pub const fn is_power_of_two(self) -> bool
true if the raw storage, viewed as unsigned, is a power
of two.
Sourcepub const fn next_power_of_two(self) -> Self
pub const fn next_power_of_two(self) -> Self
Smallest power of two >= the raw storage viewed as unsigned. Panics in debug builds on overflow.
Source§impl<const SCALE: u32> D38<SCALE>
impl<const SCALE: u32> D38<SCALE>
Sourcepub fn div_euclid(self, rhs: Self) -> Self
pub fn div_euclid(self, rhs: Self) -> Self
Euclidean division: the quotient as an integer multiple of
ONE, chosen so the remainder is non-negative. Panics on
rhs == ZERO.
Sourcepub fn rem_euclid(self, rhs: Self) -> Self
pub fn rem_euclid(self, rhs: Self) -> Self
Euclidean remainder: self - rhs * self.div_euclid(rhs),
always non-negative when rhs != ZERO. Both operands
share the scale, so no rescaling is needed. Panics on
rhs == ZERO.
Sourcepub fn abs_diff(self, rhs: Self) -> Self
pub fn abs_diff(self, rhs: Self) -> Self
Absolute difference |self - rhs|. Computed as
max - min so the subtraction is always non-negative.
Sourcepub fn midpoint(self, rhs: Self) -> Self
pub fn midpoint(self, rhs: Self) -> Self
Midpoint of self and rhs without intermediate
overflow, rounding toward negative infinity. Uses the
branch-free (a & b) + ((a ^ b) >> 1) identity, which is
overflow-free and storage-agnostic.
Sourcepub const fn is_infinite(self) -> bool
pub const fn is_infinite(self) -> bool
Always false — a fixed-point decimal has no infinity.
Source§impl<const SCALE: u32> D38<SCALE>
impl<const SCALE: u32> D38<SCALE>
Sourcepub fn div_floor(self, rhs: Self) -> Self
pub fn div_floor(self, rhs: Self) -> Self
Floor-rounded division: floor(self / rhs) as an integer
multiple of ONE. Panics on rhs == ZERO.
Inlined rather than using i128::div_floor, which is
still unstable for signed types.
Source§impl<const SCALE: u32> D38<SCALE>
impl<const SCALE: u32> D38<SCALE>
Sourcepub fn from_f64(value: f64) -> Self
pub fn from_f64(value: f64) -> Self
Constructs from an f64 using the crate default rounding
mode (HalfToEven, or whichever a rounding-* Cargo
feature selects). NaN -> ZERO, +Infinity -> MAX,
-Infinity -> MIN, out-of-range -> saturate by sign.
Sourcepub fn from_f64_with(value: f64, mode: RoundingMode) -> Self
pub fn from_f64_with(value: f64, mode: RoundingMode) -> Self
Constructs from an f64 using the supplied rounding
mode. Saturation policy as in Self::from_f64.
Source§impl<const SCALE: u32> D38<SCALE>
impl<const SCALE: u32> D38<SCALE>
Sourcepub fn from_int(value: i64) -> Self
pub fn from_int(value: i64) -> Self
Constructs from an integer at the widest supported source,
scaling by 10^SCALE. Overflow follows Rust’s default
integer arithmetic (debug panic, release wrap).
Sourcepub fn to_int(self) -> i64
pub fn to_int(self) -> i64
Converts to i64 using the crate default rounding mode.
Saturates to i64::MAX / i64::MIN when the integer part
of the rounded value falls outside i64’s range.
Sourcepub fn to_int_with(self, mode: RoundingMode) -> i64
pub fn to_int_with(self, mode: RoundingMode) -> i64
Converts to i64 using the supplied rounding mode for the
fractional discard step. Saturates to i64::MAX /
i64::MIN when the rounded integer is out of i64 range.
Source§impl<const SCALE: u32> D38<SCALE>
impl<const SCALE: u32> D38<SCALE>
Sourcepub const fn abs(self) -> Self
pub const fn abs(self) -> Self
Returns the absolute value of self.
Note: abs(MIN) overflows (because |MIN| has no positive
counterpart in two’s complement). Debug builds panic;
release builds wrap.
Sourcepub fn signum(self) -> Self
pub fn signum(self) -> Self
Returns the sign of self encoded as a scaled Self:
-ONE, ZERO, or +ONE.
Sourcepub const fn is_positive(self) -> bool
pub const fn is_positive(self) -> bool
Returns true if self is strictly greater than zero.
Sourcepub const fn is_negative(self) -> bool
pub const fn is_negative(self) -> bool
Returns true if self is strictly less than zero.
Source§impl<const SCALE: u32> D38<SCALE>
impl<const SCALE: u32> D38<SCALE>
Source§impl<const SCALE: u32> D38<SCALE>
impl<const SCALE: u32> D38<SCALE>
Source§impl<const SCALE: u32> D38<SCALE>
impl<const SCALE: u32> D38<SCALE>
Sourcepub const fn checked_add(self, rhs: Self) -> Option<Self>
pub const fn checked_add(self, rhs: Self) -> Option<Self>
Checked addition. Some(self + rhs), or None if the
sum would overflow Self.
Sourcepub const fn wrapping_add(self, rhs: Self) -> Self
pub const fn wrapping_add(self, rhs: Self) -> Self
Wrapping addition. self + rhs modulo the storage
type’s MAX − MIN range.
Sourcepub const fn saturating_add(self, rhs: Self) -> Self
pub const fn saturating_add(self, rhs: Self) -> Self
Sourcepub const fn overflowing_add(self, rhs: Self) -> (Self, bool)
pub const fn overflowing_add(self, rhs: Self) -> (Self, bool)
Overflowing addition. Returns (self.wrapping_add(rhs), overflowed).
Sourcepub const fn checked_sub(self, rhs: Self) -> Option<Self>
pub const fn checked_sub(self, rhs: Self) -> Option<Self>
Checked subtraction. Some(self - rhs), or None if
the difference would overflow Self.
Sourcepub const fn wrapping_sub(self, rhs: Self) -> Self
pub const fn wrapping_sub(self, rhs: Self) -> Self
Wrapping subtraction.
Sourcepub const fn saturating_sub(self, rhs: Self) -> Self
pub const fn saturating_sub(self, rhs: Self) -> Self
Sourcepub const fn overflowing_sub(self, rhs: Self) -> (Self, bool)
pub const fn overflowing_sub(self, rhs: Self) -> (Self, bool)
Overflowing subtraction. Returns
(self.wrapping_sub(rhs), overflowed).
Sourcepub const fn checked_neg(self) -> Option<Self>
pub const fn checked_neg(self) -> Option<Self>
Checked negation. Some(-self), or None when
self == Self::MIN (whose negation is unrepresentable
in two’s-complement).
Sourcepub const fn wrapping_neg(self) -> Self
pub const fn wrapping_neg(self) -> Self
Wrapping negation. Self::MIN.wrapping_neg() == Self::MIN
(same as i128::wrapping_neg).
Sourcepub const fn saturating_neg(self) -> Self
pub const fn saturating_neg(self) -> Self
Saturating negation. Self::MIN.saturating_neg() == Self::MAX.
Sourcepub const fn overflowing_neg(self) -> (Self, bool)
pub const fn overflowing_neg(self) -> (Self, bool)
Overflowing negation. Returns
(self.wrapping_neg(), overflowed); overflowed is
true only when self == Self::MIN.
Sourcepub const fn checked_rem(self, rhs: Self) -> Option<Self>
pub const fn checked_rem(self, rhs: Self) -> Option<Self>
Checked remainder. Some(self % rhs), or None if
rhs == 0 or the operation would overflow (the
pathological case Self::MIN % -ONE).
Sourcepub const fn wrapping_rem(self, rhs: Self) -> Self
pub const fn wrapping_rem(self, rhs: Self) -> Self
Wrapping remainder. Panics on divide-by-zero
(matches i128::wrapping_rem).
Sourcepub const fn overflowing_rem(self, rhs: Self) -> (Self, bool)
pub const fn overflowing_rem(self, rhs: Self) -> (Self, bool)
Overflowing remainder. Returns
(self.wrapping_rem(rhs), overflowed); overflowed
is true only at the Self::MIN % -ONE boundary.
Source§impl<const SCALE: u32> D38<SCALE>
impl<const SCALE: u32> D38<SCALE>
Sourcepub fn narrow(self) -> Result<D18<SCALE>, ConvertError>
pub fn narrow(self) -> Result<D18<SCALE>, ConvertError>
Demote to the previous storage tier (D18) at the same
SCALE. Returns Err(ConvertError::OutOfRange) if the value
doesn’t fit i64’s range at the given scale.
use decimal_scaled::D38s9;
let a = D38s9::from_int(1_000_000);
let b = a.narrow().unwrap();
assert_eq!(b.to_bits() as i128, a.to_bits());Source§impl<const SCALE: u32> D38<SCALE>
impl<const SCALE: u32> D38<SCALE>
Sourcepub fn from_num<T: ToPrimitive>(value: T) -> Self
pub fn from_num<T: ToPrimitive>(value: T) -> Self
Constructs a D38<SCALE> from any T: ToPrimitive, routing
through num_traits::NumCast. Never panics — out-of-range
inputs saturate.
§Precision
Lossy: involves f32 or f64 at some point when T is a float
type; result may lose precision. For integer T, the conversion
is Strict (integer-only, bit-exact).
§Saturation policy
- Float
NaNmaps toD38::ZERO. +Infinitymaps toD38::MAX.-Infinitymaps toD38::MIN.- Finite out-of-range positive maps to
D38::MAX. - Finite out-of-range negative maps to
D38::MIN. - Never panics.
§Examples
use decimal_scaled::D38s12;
assert_eq!(D38s12::from_num(42_i32), D38s12::from(42_i32));
assert_eq!(D38s12::from_num(f64::INFINITY), D38s12::MAX);
assert_eq!(D38s12::from_num(f64::NAN), D38s12::ZERO);Sourcepub fn to_num<T: NumCast + Bounded>(self) -> T
pub fn to_num<T: NumCast + Bounded>(self) -> T
Converts self to any T: NumCast + Bounded, routing through
num_traits::NumCast. Never panics — out-of-range targets
saturate to T::min_value() / T::max_value().
§Precision
Lossy: involves f32 or f64 at some point when T is a float
type; result may lose precision. For integer T, the conversion
is Strict (integer-only, bit-exact).
§Saturation policy
- In-range conversions return the cast value unchanged.
- Positive out-of-range maps to
Bounded::max_valueofT. - Negative out-of-range maps to
Bounded::min_valueofT. - Never panics.
§Examples
use decimal_scaled::D38s12;
assert_eq!(D38s12::from(42_i32).to_num::<i32>(), 42_i32);
assert_eq!(D38s12::MAX.to_num::<i32>(), i32::MAX);
assert_eq!(D38s12::MIN.to_num::<i32>(), i32::MIN);Source§impl<const SCALE: u32> D38<SCALE>
impl<const SCALE: u32> D38<SCALE>
Sourcepub fn ln_strict(self) -> Self
pub fn ln_strict(self) -> Self
Returns the natural logarithm (base e) of self.
§Algorithm
Range reduction x = 2^k * m with m ∈ [1, 2), then a Mercator
reduction x = 2^k * m with m ∈ [1, 2), then the
area-hyperbolic-tangent series
ln(m) = 2·artanh(t), t = (m-1)/(m+1) ∈ [0, 1/3],
artanh(t) = t + t³/3 + t⁵/5 + …, evaluated in a 256-bit
fixed-point intermediate at SCALE + 20 working digits. The 20
guard digits bound the total accumulated rounding error far
below 0.5 ULP of the output, so the result — k·ln(2) + ln(m),
rounded once at the end — is correctly rounded.
§Precision
Strict: integer-only, and correctly rounded — the result is within 0.5 ULP of the exact natural logarithm (IEEE-754 round-to-nearest).
§Panics
Panics if self <= 0, or if the result overflows the type’s
representable range (only possible for ln of a near-MAX
value at SCALE >= 37).
Always available, regardless of the strict feature. When
strict is enabled, the plain Self::ln delegates here.
Sourcepub fn ln(self) -> Self
pub fn ln(self) -> Self
Returns the natural logarithm (base e) of self.
With the strict feature enabled this is the integer-only
Self::ln_strict; without it, the f64-bridge form.
Sourcepub fn log_strict(self, base: Self) -> Self
pub fn log_strict(self, base: Self) -> Self
Returns the logarithm of self in the given base, computed
integer-only as ln(self) / ln(base) — both logarithms and the
division are carried in the wide guard-digit intermediate, so
the result is correctly rounded.
Always available, regardless of the strict feature.
§Panics
Panics if self <= 0 or base <= 0, or if base == 1
(division by ln(1) = 0).
Sourcepub fn log(self, base: Self) -> Self
pub fn log(self, base: Self) -> Self
Returns the logarithm of self in the given base.
With the strict feature enabled this is the integer-only
Self::log_strict; without it, the f64-bridge form.
Sourcepub fn log2_strict(self) -> Self
pub fn log2_strict(self) -> Self
Returns the base-2 logarithm of self, computed integer-only as
ln(self) / ln(2) in the wide guard-digit intermediate — the
result is correctly rounded.
Always available, regardless of the strict feature.
§Panics
Panics if self <= 0.
Sourcepub fn log2(self) -> Self
pub fn log2(self) -> Self
Returns the base-2 logarithm of self.
With the strict feature enabled this is the integer-only
Self::log2_strict; without it, the f64-bridge form.
Sourcepub fn log10_strict(self) -> Self
pub fn log10_strict(self) -> Self
Returns the base-10 logarithm of self, computed integer-only
as ln(self) / ln(10) in the wide guard-digit intermediate —
the result is correctly rounded.
Always available, regardless of the strict feature.
§Panics
Panics if self <= 0.
Sourcepub fn log10(self) -> Self
pub fn log10(self) -> Self
Returns the base-10 logarithm of self.
With the strict feature enabled this is the integer-only
Self::log10_strict; without it, the f64-bridge form.
Sourcepub fn exp_strict(self) -> Self
pub fn exp_strict(self) -> Self
Returns e^self (natural exponential).
§Algorithm
Range reduction x = k·ln(2) + s with k = round(x / ln 2) and
|s| ≤ ln(2)/2 ≈ 0.347, then the Taylor series
exp(s) = 1 + s + s²/2! + … evaluated in a 256-bit Fixed
intermediate at SCALE + 30 working digits. Reassembly is
exp(x) = 2^k · exp(s), applied as a shift on the working-scale
value before the final rounding, so the 2^k factor never
amplifies a rounding error. The result is rounded once,
half-to-even, back to SCALE.
§Precision
Strict: integer-only, and correctly rounded — the result is within 0.5 ULP of the exact exponential (IEEE-754 round-to-nearest).
§Panics
Panics if the result overflows the type’s representable range.
Sourcepub fn exp(self) -> Self
pub fn exp(self) -> Self
Returns e^self (natural exponential).
With the strict feature enabled this is the integer-only
Self::exp_strict; without it, the f64-bridge form.
Sourcepub fn exp2_strict(self) -> Self
pub fn exp2_strict(self) -> Self
Returns 2^self (base-2 exponential), computed integer-only as
exp(self · ln(2)) — the self · ln(2) product is formed in
the wide guard-digit intermediate (not at the type’s own scale),
so the result is correctly rounded.
Always available, regardless of the strict feature.
§Panics
Panics if the result overflows D38’s representable range.
Sourcepub fn exp2(self) -> Self
pub fn exp2(self) -> Self
Returns 2^self (base-2 exponential).
With the strict feature enabled this is the integer-only
Self::exp2_strict; without it, the f64-bridge form.
Source§impl<const SCALE: u32> D38<SCALE>
impl<const SCALE: u32> D38<SCALE>
Sourcepub fn ln_fast(self) -> Self
pub fn ln_fast(self) -> Self
Returns the natural logarithm (base e) of self.
§Precision
Lossy: converts to f64, calls f64::ln, converts back. f64::ln
returns -Infinity for 0.0 (saturates to D38::MIN) and NaN
for negative inputs (maps to D38::ZERO).
§Examples
use decimal_scaled::D38s12;
// ln(1) == 0 (f64::ln(1.0) == 0.0 exactly).
assert_eq!(D38s12::ONE.ln(), D38s12::ZERO);Sourcepub fn log_fast(self, base: Self) -> Self
pub fn log_fast(self, base: Self) -> Self
Returns the logarithm of self in the given base.
Implemented via a single f64::log(self_f64, base_f64) call, which
avoids the extra quantisation that would come from computing
ln(self) / ln(base) with two separate f64 round-trips.
§Precision
Lossy: involves f64 at some point; result may lose precision.
§Examples
use decimal_scaled::D38s12;
// log_2(8) is approximately 3 within f64 precision.
let eight = D38s12::from_int(8);
let two = D38s12::from_int(2);
let result = eight.log(two);Sourcepub fn log2_fast(self) -> Self
pub fn log2_fast(self) -> Self
Returns the base-2 logarithm of self.
§Precision
Lossy: involves f64 at some point; result may lose precision.
On IEEE-754 platforms, f64::log2 is exact for integer powers
of two (e.g. log2(8.0) == 3.0). Out-of-domain inputs follow
the same saturation policy as Self::ln.
§Examples
use decimal_scaled::D38s12;
// log2(1) == 0 (f64::log2(1.0) == 0.0 exactly).
assert_eq!(D38s12::ONE.log2(), D38s12::ZERO);Sourcepub fn log10_fast(self) -> Self
pub fn log10_fast(self) -> Self
Returns the base-10 logarithm of self.
§Precision
Lossy: involves f64 at some point; result may lose precision.
Out-of-domain inputs follow the same saturation policy as Self::ln.
§Examples
use decimal_scaled::D38s12;
// log10(1) == 0 (f64::log10(1.0) == 0.0 exactly).
assert_eq!(D38s12::ONE.log10(), D38s12::ZERO);Sourcepub fn exp_fast(self) -> Self
pub fn exp_fast(self) -> Self
Returns e^self (natural exponential).
§Precision
Lossy: involves f64 at some point; result may lose precision.
Large positive inputs overflow f64 to +Infinity, which saturates
to D38::MAX. Large negative inputs underflow to 0.0 in f64,
which maps to D38::ZERO.
§Examples
use decimal_scaled::D38s12;
// exp(0) == 1 (f64::exp(0.0) == 1.0 exactly).
assert_eq!(D38s12::ZERO.exp(), D38s12::ONE);Sourcepub fn exp2_fast(self) -> Self
pub fn exp2_fast(self) -> Self
Returns 2^self (base-2 exponential).
§Precision
Lossy: involves f64 at some point; result may lose precision.
Saturation behaviour is analogous to Self::exp but at different
magnitudes (inputs beyond approximately 1024 overflow to +Infinity).
§Examples
use decimal_scaled::D38s12;
// exp2(0) == 1 (f64::exp2(0.0) == 1.0 exactly).
assert_eq!(D38s12::ZERO.exp2(), D38s12::ONE);Source§impl<const SCALE: u32> D38<SCALE>
impl<const SCALE: u32> D38<SCALE>
Sourcepub const fn rescale<const TARGET_SCALE: u32>(self) -> D38<TARGET_SCALE>
pub const fn rescale<const TARGET_SCALE: u32>(self) -> D38<TARGET_SCALE>
Rescales to TARGET_SCALE using the crate’s default
rounding mode (HalfToEven, or whatever a
rounding-* Cargo feature selects).
Delegates to Self::rescale_with; see that method for
scale-up / scale-down semantics and the overflow policy.
Sourcepub const fn with_scale<const TARGET_SCALE: u32>(self) -> D38<TARGET_SCALE>
pub const fn with_scale<const TARGET_SCALE: u32>(self) -> D38<TARGET_SCALE>
Builder-style alias for Self::rescale.
Returns a new value at TARGET_SCALE using the crate’s
default rounding mode. Use Self::rescale_with when
you need to pass an explicit RoundingMode.
Sourcepub const fn rescale_with<const TARGET_SCALE: u32>(
self,
mode: RoundingMode,
) -> D38<TARGET_SCALE>
pub const fn rescale_with<const TARGET_SCALE: u32>( self, mode: RoundingMode, ) -> D38<TARGET_SCALE>
Rescales to TARGET_SCALE using the supplied rounding
mode.
TARGET_SCALE == SCALE: bit-identity.TARGET_SCALE > SCALE: scale-up multiplies by10^(TARGET - SCALE); lossless; panics on overflow.TARGET_SCALE < SCALE: scale-down divides by10^(SCALE - TARGET)with the requested rounding rule.
Source§impl<const SCALE: u32> D38<SCALE>
impl<const SCALE: u32> D38<SCALE>
Sourcepub fn checked_mul(self, rhs: Self) -> Option<Self>
pub fn checked_mul(self, rhs: Self) -> Option<Self>
Returns self * rhs, or None if the rescaled product does not
fit in i128.
The intermediate product is computed with 256-bit arithmetic and
cannot itself overflow. The only failure mode is a final i128
quotient that exceeds the storage range.
§Precision
Strict: the result is truncated (not rounded) toward zero during
the scale-restoring divide, identical to the default * operator.
§Examples
use decimal_scaled::D38s12;
let half = D38s12::from_bits(500_000_000_000); // 0.5
assert_eq!(half.checked_mul(half), Some(D38s12::from_bits(250_000_000_000)));
assert_eq!(D38s12::MAX.checked_mul(D38s12::from_bits(2_000_000_000_000)), None);Sourcepub fn wrapping_mul(self, rhs: Self) -> Self
pub fn wrapping_mul(self, rhs: Self) -> Self
Returns self * rhs with two’s-complement wrap when the rescaled
product does not fit in i128.
On overflow, falls back to (a.wrapping_mul(b)).wrapping_div(multiplier()).
The exact bit pattern of the wrapping result at extreme magnitudes
is an implementation detail; only the no-panic contract is guaranteed.
§Precision
Strict: truncates toward zero during the scale-restoring divide.
§Examples
use decimal_scaled::D38s12;
let half = D38s12::from_bits(500_000_000_000); // 0.5
assert_eq!(half.wrapping_mul(half), D38s12::from_bits(250_000_000_000));
// Overflow does not panic.
let _ = D38s12::MAX.wrapping_mul(D38s12::from_bits(2_000_000_000_000));Sourcepub fn saturating_mul(self, rhs: Self) -> Self
pub fn saturating_mul(self, rhs: Self) -> Self
Returns self * rhs, clamped to D38::MAX or D38::MIN on overflow.
The clamp direction is determined by the XOR of operand signs:
same-sign operands saturate to MAX; mixed-sign operands saturate
to MIN.
§Precision
Strict: truncates toward zero during the scale-restoring divide.
§Examples
use decimal_scaled::D38s12;
let two = D38s12::from_bits(2_000_000_000_000); // 2.0
assert_eq!(D38s12::MAX.saturating_mul(two), D38s12::MAX);
assert_eq!(D38s12::MAX.saturating_mul(-two), D38s12::MIN);Sourcepub fn overflowing_mul(self, rhs: Self) -> (Self, bool)
pub fn overflowing_mul(self, rhs: Self) -> (Self, bool)
Returns (self * rhs, did_overflow) where the value is the
wrapping result when overflow occurs.
§Precision
Strict: truncates toward zero during the scale-restoring divide.
§Examples
use decimal_scaled::D38s12;
let half = D38s12::from_bits(500_000_000_000); // 0.5
assert_eq!(half.overflowing_mul(half), (D38s12::from_bits(250_000_000_000), false));
let (_, ovf) = D38s12::MAX.overflowing_mul(D38s12::from_bits(2_000_000_000_000));
assert!(ovf);Sourcepub fn checked_div(self, rhs: Self) -> Option<Self>
pub fn checked_div(self, rhs: Self) -> Option<Self>
Returns self / rhs, or None on division by zero or if the
rescaled quotient does not fit in i128.
The only finite-operand overflow case is
D38::MIN / NEG_ONE (storage negation of i128::MIN overflows).
§Precision
Strict: the widening divide truncates toward zero, identical to
the default / operator.
§Examples
use decimal_scaled::D38s12;
let six = D38s12::from_bits(6_000_000_000_000); // 6.0
let two = D38s12::from_bits(2_000_000_000_000); // 2.0
assert_eq!(six.checked_div(two), Some(D38s12::from_bits(3_000_000_000_000)));
assert_eq!(D38s12::ONE.checked_div(D38s12::ZERO), None);Sourcepub fn wrapping_div(self, rhs: Self) -> Self
pub fn wrapping_div(self, rhs: Self) -> Self
Returns self / rhs with two’s-complement wrap when the rescaled
quotient does not fit in i128.
On overflow, falls back to
(a.wrapping_mul(multiplier())).wrapping_div(b).
§Precision
Strict: truncates toward zero.
§Panics
Panics on rhs == ZERO (matches i128::wrapping_div).
§Examples
use decimal_scaled::D38s12;
let six = D38s12::from_bits(6_000_000_000_000); // 6.0
let two = D38s12::from_bits(2_000_000_000_000); // 2.0
assert_eq!(six.wrapping_div(two), D38s12::from_bits(3_000_000_000_000));Sourcepub fn saturating_div(self, rhs: Self) -> Self
pub fn saturating_div(self, rhs: Self) -> Self
Returns self / rhs, clamped to D38::MAX or D38::MIN on
overflow.
The clamp direction is determined by the XOR of operand signs, because the scale multiplier is always positive.
§Precision
Strict: truncates toward zero.
§Panics
Panics on rhs == ZERO (matches i128::saturating_div).
§Examples
use decimal_scaled::D38s12;
let six = D38s12::from_bits(6_000_000_000_000); // 6.0
let two = D38s12::from_bits(2_000_000_000_000); // 2.0
assert_eq!(six.saturating_div(two), D38s12::from_bits(3_000_000_000_000));
// MAX / 0.5 overflows; both positive so clamp to MAX.
assert_eq!(D38s12::MAX.saturating_div(D38s12::from_bits(500_000_000_000)), D38s12::MAX);Sourcepub fn overflowing_div(self, rhs: Self) -> (Self, bool)
pub fn overflowing_div(self, rhs: Self) -> (Self, bool)
Returns (self / rhs, did_overflow) where the value is the
wrapping result when overflow occurs.
§Precision
Strict: truncates toward zero.
§Panics
Panics on rhs == ZERO (matches i128::overflowing_div).
§Examples
use decimal_scaled::D38s12;
let six = D38s12::from_bits(6_000_000_000_000); // 6.0
let two = D38s12::from_bits(2_000_000_000_000); // 2.0
assert_eq!(six.overflowing_div(two), (D38s12::from_bits(3_000_000_000_000), false));
let half = D38s12::from_bits(500_000_000_000); // 0.5
let (_, ovf) = D38s12::MAX.overflowing_div(half);
assert!(ovf);Source§impl<const SCALE: u32> D38<SCALE>
impl<const SCALE: u32> D38<SCALE>
Sourcepub fn pow(self, exp: u32) -> Self
pub fn pow(self, exp: u32) -> Self
Raises self to the power exp.
Uses square-and-multiply: walks the bits of exp from low to
high, squaring the base each step and accumulating when the
corresponding bit is set. Costs O(log exp) multiplications.
Each multiplication routes through the D38 Mul operator.
exp = 0 always returns ONE, even when self is ZERO
(matches i128::pow convention).
§Precision
Strict: all arithmetic is integer-only; result is bit-exact.
§Panics
In debug builds, panics on i128 overflow at any multiplication
step. In release builds, wraps two’s-complement. Matches
i128::pow and D38::Mul semantics.
Use Self::checked_pow, Self::wrapping_pow,
Self::saturating_pow, or Self::overflowing_pow for
explicit overflow control.
§Examples
use decimal_scaled::D38s12;
let two = D38s12::from_int(2);
assert_eq!(two.pow(10), D38s12::from_int(1024));
// exp = 0 returns ONE regardless of base.
assert_eq!(D38s12::ZERO.pow(0), D38s12::ONE);Sourcepub fn powi(self, exp: i32) -> Self
pub fn powi(self, exp: i32) -> Self
Raises self to the signed integer power exp.
For non-negative exp, equivalent to self.pow(exp as u32).
For negative exp, returns D38::ONE / self.pow(exp.unsigned_abs()),
i.e. the reciprocal of the positive-exponent form.
§Precision
Strict: all arithmetic is integer-only; result is bit-exact.
§Panics
- Overflow of
i128storage at any step in debug builds (matchesSelf::pow). - Division by zero when
self == ZEROandexp < 0.
§Examples
use decimal_scaled::D38s12;
let two = D38s12::from_int(2);
assert_eq!(two.powi(-1), D38s12::ONE / two);
assert_eq!(two.powi(0), D38s12::ONE);
assert_eq!(two.powi(3), D38s12::from_int(8));Sourcepub fn powf_strict(self, exp: D38<SCALE>) -> Self
pub fn powf_strict(self, exp: D38<SCALE>) -> Self
Raises self to the power exp (strict integer-only stub).
Converts both operands to f64, calls f64::powf, then converts
the result back. For integer exponents, prefer Self::pow or
Self::powi, which are bit-exact.
NaN results map to ZERO; infinities clamp to MAX or MIN,
following the saturate-vs-error policy of Self::from_f64.
§Precision
Strict: all arithmetic is integer-only; result is bit-exact.
§Examples
use decimal_scaled::D38s12;
let two = D38s12::from_int(2);
let three = D38s12::from_int(3);
// 2^3 = 8, within f64 precision.
assert!((two.powf(three).to_f64() - 8.0).abs() < 1e-9);Raises self to the power exp, computed integer-only as
exp(exp · ln(self)) — the ln, the · exp, and the exp all
run in the shared wide guard-digit intermediate, so the result
is correctly rounded (within 0.5 ULP).
Always available, regardless of the strict feature. When
strict is enabled, the plain Self::powf delegates here.
A zero or negative base saturates to ZERO (a negative base
with an arbitrary fractional exponent is not real-valued),
matching the f64-bridge NaN-to-ZERO policy.
Sourcepub fn powf(self, exp: D38<SCALE>) -> Self
pub fn powf(self, exp: D38<SCALE>) -> Self
Raises self to the power exp.
With the strict feature enabled this is the integer-only
Self::powf_strict; without it, the f64-bridge form.
Sourcepub fn sqrt_strict(self) -> Self
pub fn sqrt_strict(self) -> Self
Returns the square root of self (strict integer-only stub).
IEEE 754 mandates that f64::sqrt is correctly-rounded
(round-to-nearest, ties-to-even). Combined with the deterministic
to_f64 / from_f64 round-trip, this makes
D38::sqrt bit-deterministic: the same input produces the same
output bit-pattern on every IEEE-754-conformant platform.
Negative inputs produce a NaN from f64::sqrt, which
Self::from_f64 maps to ZERO per the saturate-vs-error
policy. No panic is raised for negative inputs.
§Precision
Strict: all arithmetic is integer-only; result is bit-exact.
§Examples
use decimal_scaled::D38s12;
assert_eq!(D38s12::ZERO.sqrt(), D38s12::ZERO);
// f64::sqrt(1.0) == 1.0 exactly, so the result is bit-exact.
assert_eq!(D38s12::ONE.sqrt(), D38s12::ONE);Sourcepub fn sqrt(self) -> Self
pub fn sqrt(self) -> Self
Returns the square root of self.
With the strict feature enabled this is the integer-only,
correctly-rounded Self::sqrt_strict; without it, the
f64-bridge form.
Sourcepub fn cbrt(self) -> Self
pub fn cbrt(self) -> Self
Returns the cube root of self.
With the strict feature enabled this is the integer-only
Self::cbrt_strict; without it, the f64-bridge form.
Sourcepub fn cbrt_strict(self) -> Self
pub fn cbrt_strict(self) -> Self
Cube root of self. Defined for all reals — the sign of the
input is preserved (cbrt(-8) = -2).
§Algorithm
For a D38<SCALE> with raw storage r, the raw storage of the
cube root is
round( cbrt(r / 10^SCALE) · 10^SCALE ) = round( cbrt(r · 10^(2·SCALE)) ).
r · 10^(2·SCALE) is formed exactly as a 384-bit value and its
integer cube root is computed exactly, so the result is the
exact cube root correctly rounded to the type’s last place
(within 0.5 ULP — the IEEE-754 round-to-nearest result).
§Precision
Strict: integer-only; correctly rounded.
Sourcepub fn hypot_strict(self, other: Self) -> Self
pub fn hypot_strict(self, other: Self) -> Self
Returns sqrt(self^2 + other^2) without intermediate overflow,
computed integer-only via the correctly-rounded
Self::sqrt_strict. Same scale-trick algorithm as the
f64-bridge Self::hypot; available in no_std.
Always available, regardless of the strict feature.
Sourcepub fn hypot(self, other: Self) -> Self
pub fn hypot(self, other: Self) -> Self
Returns sqrt(self^2 + other^2) without intermediate overflow.
With the strict feature enabled this is the integer-only
Self::hypot_strict; without it, the f64-bridge form.
Sourcepub fn checked_pow(self, exp: u32) -> Option<Self>
pub fn checked_pow(self, exp: u32) -> Option<Self>
Returns Some(self^exp), or None if any multiplication step
overflows i128.
Walks the same square-and-multiply as Self::pow but uses
mul_div_pow10 (which returns Option<i128>) at each step.
The first None short-circuits to a None return.
§Precision
Strict: all arithmetic is integer-only; result is bit-exact.
§Examples
use decimal_scaled::D38s12;
// MAX^2 overflows.
assert!(D38s12::MAX.checked_pow(2).is_none());
// Any power of ONE is ONE.
assert_eq!(D38s12::ONE.checked_pow(1_000_000), Some(D38s12::ONE));Sourcepub fn wrapping_pow(self, exp: u32) -> Self
pub fn wrapping_pow(self, exp: u32) -> Self
Returns self^exp, wrapping two’s-complement on overflow at
every multiplication step.
Follows the same square-and-multiply structure as Self::pow.
When a step overflows mul_div_pow10, the fallback is
wrapping_mul followed by wrapping_div of the scale
multiplier. The exact wrap pattern is deterministic and
reproducible but is not otherwise specified.
§Precision
Strict: all arithmetic is integer-only; result is bit-exact.
§Examples
use decimal_scaled::D38s12;
// ONE^N never overflows and returns ONE.
assert_eq!(D38s12::ONE.wrapping_pow(1_000_000), D38s12::ONE);
// MAX^2 wraps to a deterministic but unspecified value.
let _ = D38s12::MAX.wrapping_pow(2);Sourcepub fn saturating_pow(self, exp: u32) -> Self
pub fn saturating_pow(self, exp: u32) -> Self
Returns self^exp, clamping to D38::MAX or D38::MIN on
overflow at any step.
On the first step that overflows, the result is clamped based on
the sign of the mathematical result: positive overflows clamp to
MAX, negative overflows clamp to MIN. The sign of the result
is determined by self.signum() and whether exp is odd.
exp = 0 always returns ONE before entering the loop.
§Precision
Strict: all arithmetic is integer-only; result is bit-exact.
§Examples
use decimal_scaled::D38s12;
assert_eq!(D38s12::MAX.saturating_pow(2), D38s12::MAX);
assert_eq!(D38s12::ONE.saturating_pow(1_000_000), D38s12::ONE);Sourcepub fn overflowing_pow(self, exp: u32) -> (Self, bool)
pub fn overflowing_pow(self, exp: u32) -> (Self, bool)
Returns (self^exp, overflowed).
overflowed is true if any multiplication step overflowed
i128. The returned value is the wrapping form (matches
Self::wrapping_pow).
§Precision
Strict: all arithmetic is integer-only; result is bit-exact.
§Examples
use decimal_scaled::D38s12;
let (_value, overflowed) = D38s12::MAX.overflowing_pow(2);
assert!(overflowed);
let (value, overflowed) = D38s12::ONE.overflowing_pow(5);
assert!(!overflowed);
assert_eq!(value, D38s12::ONE);Source§impl<const SCALE: u32> D38<SCALE>
impl<const SCALE: u32> D38<SCALE>
Sourcepub fn powf_fast(self, exp: D38<SCALE>) -> Self
pub fn powf_fast(self, exp: D38<SCALE>) -> Self
Raises self to the power exp via the f64 bridge.
Converts both operands to f64, calls f64::powf, then converts
the result back. For integer exponents, prefer Self::pow or
Self::powi, which are bit-exact.
NaN results map to ZERO; infinities clamp to MAX or MIN,
following the saturate-vs-error policy of Self::from_f64.
§Precision
Lossy: involves f64 at some point; result may lose precision.
§Examples
use decimal_scaled::D38s12;
let two = D38s12::from_int(2);
let three = D38s12::from_int(3);
// 2^3 = 8, within f64 precision.
assert!((two.powf(three).to_f64() - 8.0).abs() < 1e-9);Sourcepub fn sqrt_fast(self) -> Self
pub fn sqrt_fast(self) -> Self
Returns the square root of self via the f64 bridge.
IEEE 754 mandates that f64::sqrt is correctly-rounded
(round-to-nearest, ties-to-even). Combined with the deterministic
to_f64 / from_f64 round-trip, this makes
D38::sqrt bit-deterministic: the same input produces the same
output bit-pattern on every IEEE-754-conformant platform.
Negative inputs produce a NaN from f64::sqrt, which
Self::from_f64 maps to ZERO per the saturate-vs-error
policy. No panic is raised for negative inputs.
§Precision
Lossy: involves f64 at some point; result may lose precision.
§Examples
use decimal_scaled::D38s12;
assert_eq!(D38s12::ZERO.sqrt(), D38s12::ZERO);
// f64::sqrt(1.0) == 1.0 exactly, so the result is bit-exact.
assert_eq!(D38s12::ONE.sqrt(), D38s12::ONE);Sourcepub fn cbrt_fast(self) -> Self
pub fn cbrt_fast(self) -> Self
Returns the cube root of self via the f64 bridge.
f64::cbrt is defined for the entire real line, including
negative inputs (cbrt(-8.0) == -2.0). The result is
bit-deterministic across IEEE-754-conformant platforms because
f64::cbrt is correctly-rounded.
§Precision
Lossy: involves f64 at some point; result may lose precision.
§Examples
use decimal_scaled::D38s12;
let neg_eight = D38s12::from_int(-8);
let result = neg_eight.cbrt();
assert!((result.to_f64() - (-2.0_f64)).abs() < 1e-9);Sourcepub fn hypot_fast(self, other: Self) -> Self
pub fn hypot_fast(self, other: Self) -> Self
Returns sqrt(self^2 + other^2) without intermediate overflow.
The naive form (self * self + other * other).sqrt() overflows
i128 once either operand approaches sqrt(D38::MAX). This
method uses the scale trick to avoid that:
hypot(a, b) = max(|a|, |b|) * sqrt(1 + (min(|a|, |b|) / max(|a|, |b|))^2)The min/max ratio is in [0, 1], so ratio^2 is also in
[0, 1] and cannot overflow. The outer multiply by large only
overflows when the true hypotenuse genuinely exceeds D38::MAX,
which matches f64::hypot’s contract.
Both inputs are absolute-valued before processing, so
hypot(-a, b) == hypot(a, b).
Edge cases: hypot(0, 0) == 0 (bit-exact via the early return);
hypot(0, x) ~= |x| and hypot(x, 0) ~= |x|.
§Precision
Lossy: involves f64 at some point; result may lose precision.
§Examples
use decimal_scaled::D38s12;
let three = D38s12::from_int(3);
let four = D38s12::from_int(4);
// Pythagorean triple: hypot(3, 4) ~= 5.
assert!((three.hypot(four).to_f64() - 5.0).abs() < 1e-9);Source§impl<const SCALE: u32> D38<SCALE>
impl<const SCALE: u32> D38<SCALE>
Sourcepub fn sin(self) -> Self
pub fn sin(self) -> Self
With strict this dispatches to Self::sin_strict; without
it, the f64-bridge form is used instead.
Sourcepub fn cos(self) -> Self
pub fn cos(self) -> Self
With strict this dispatches to Self::cos_strict; without
it, the f64-bridge form is used instead.
Sourcepub fn tan(self) -> Self
pub fn tan(self) -> Self
With strict this dispatches to Self::tan_strict; without
it, the f64-bridge form is used instead.
Sourcepub fn asin(self) -> Self
pub fn asin(self) -> Self
With strict this dispatches to Self::asin_strict; without
it, the f64-bridge form is used instead.
Sourcepub fn acos(self) -> Self
pub fn acos(self) -> Self
With strict this dispatches to Self::acos_strict; without
it, the f64-bridge form is used instead.
Sourcepub fn atan(self) -> Self
pub fn atan(self) -> Self
With strict this dispatches to Self::atan_strict; without
it, the f64-bridge form is used instead.
Sourcepub fn atan2(self, other: Self) -> Self
pub fn atan2(self, other: Self) -> Self
Four-quadrant arctangent of self (y) and other (x).
With strict this dispatches to Self::atan2_strict;
without it, the f64-bridge form is used instead.
Sourcepub fn sinh(self) -> Self
pub fn sinh(self) -> Self
With strict this dispatches to Self::sinh_strict; without
it, the f64-bridge form is used instead.
Sourcepub fn cosh(self) -> Self
pub fn cosh(self) -> Self
With strict this dispatches to Self::cosh_strict; without
it, the f64-bridge form is used instead.
Sourcepub fn tanh(self) -> Self
pub fn tanh(self) -> Self
With strict this dispatches to Self::tanh_strict; without
it, the f64-bridge form is used instead.
Sourcepub fn asinh(self) -> Self
pub fn asinh(self) -> Self
With strict this dispatches to Self::asinh_strict; without
it, the f64-bridge form is used instead.
Sourcepub fn acosh(self) -> Self
pub fn acosh(self) -> Self
With strict this dispatches to Self::acosh_strict; without
it, the f64-bridge form is used instead.
Sourcepub fn atanh(self) -> Self
pub fn atanh(self) -> Self
With strict this dispatches to Self::atanh_strict; without
it, the f64-bridge form is used instead.
Sourcepub fn to_degrees(self) -> Self
pub fn to_degrees(self) -> Self
With strict this dispatches to Self::to_degrees_strict; without
it, the f64-bridge form is used instead.
Sourcepub fn to_radians(self) -> Self
pub fn to_radians(self) -> Self
With strict this dispatches to Self::to_radians_strict; without
it, the f64-bridge form is used instead.
Sourcepub fn sin_strict(self) -> Self
pub fn sin_strict(self) -> Self
Sine of self (radians). Strict: integer-only and correctly
rounded — the result is within 0.5 ULP of the exact sine.
Sourcepub fn cos_strict(self) -> Self
pub fn cos_strict(self) -> Self
Cosine of self (radians). Strict: cos(x) = sin(x + π/2),
correctly rounded.
Sourcepub fn tan_strict(self) -> Self
pub fn tan_strict(self) -> Self
Tangent of self (radians). Strict: tan(x) = sin(x) / cos(x),
with the division carried in the wide intermediate so the result
is correctly rounded.
§Panics
Panics if cos(self) is zero (an odd multiple of π/2).
Sourcepub fn atan_strict(self) -> Self
pub fn atan_strict(self) -> Self
Arctangent of self, in radians, in (−π/2, π/2). Strict:
integer-only and correctly rounded.
Sourcepub fn asin_strict(self) -> Self
pub fn asin_strict(self) -> Self
Arcsine of self, in radians, in [−π/2, π/2]. Strict.
asin(x) = atan(x / √(1 − x²)); the endpoints ±1 map directly
to ±π/2.
§Panics
Panics if |self| > 1.
Sourcepub fn acos_strict(self) -> Self
pub fn acos_strict(self) -> Self
Arccosine of self, in radians, in [0, π]. Strict:
acos(x) = π/2 − asin(x), correctly rounded.
§Panics
Panics if |self| > 1.
Sourcepub fn atan2_strict(self, other: Self) -> Self
pub fn atan2_strict(self, other: Self) -> Self
Four-quadrant arctangent of self (y) and other (x), in
radians, in (−π, π]. Strict: integer-only and correctly
rounded.
Sourcepub fn sinh_strict(self) -> Self
pub fn sinh_strict(self) -> Self
Hyperbolic sine of self. Strict: sinh(x) = (eˣ − e⁻ˣ)/2,
composed in the wide intermediate from the correctly-rounded
exp, so the result is itself correctly rounded.
Sourcepub fn cosh_strict(self) -> Self
pub fn cosh_strict(self) -> Self
Hyperbolic cosine of self. Strict: cosh(x) = (eˣ + e⁻ˣ)/2,
correctly rounded.
Sourcepub fn tanh_strict(self) -> Self
pub fn tanh_strict(self) -> Self
Hyperbolic tangent of self. Strict: tanh(x) = sinh(x)/cosh(x)
with the division in the wide intermediate. cosh ≥ 1, so the
division never traps.
Sourcepub fn asinh_strict(self) -> Self
pub fn asinh_strict(self) -> Self
Inverse hyperbolic sine of self. Strict:
asinh(x) = sign · ln(|x| + √(x² + 1)), correctly rounded.
For |x| ≥ 1 the radicand is factored as
|x|·(1 + √(1 + 1/x²)) to keep x² from overflowing the wide
intermediate.
Sourcepub fn acosh_strict(self) -> Self
pub fn acosh_strict(self) -> Self
Inverse hyperbolic cosine of self. Strict:
acosh(x) = ln(x + √(x² − 1)), defined for x ≥ 1, correctly
rounded. For x ≥ 2 the radicand is factored as
x·(1 + √(1 − 1/x²)) to keep x² in range.
§Panics
Panics if self < 1.
Sourcepub fn atanh_strict(self) -> Self
pub fn atanh_strict(self) -> Self
Inverse hyperbolic tangent of self. Strict:
atanh(x) = ln((1 + x) / (1 − x)) / 2, defined for |x| < 1,
correctly rounded.
§Panics
Panics if |self| >= 1.
Sourcepub fn to_degrees_strict(self) -> Self
pub fn to_degrees_strict(self) -> Self
Convert radians to degrees: self · (180 / π). Strict: the
multiply and divide run in the wide intermediate, so the result
is correctly rounded.
Sourcepub fn to_radians_strict(self) -> Self
pub fn to_radians_strict(self) -> Self
Convert degrees to radians: self · (π / 180). Strict:
correctly rounded.
Source§impl<const SCALE: u32> D38<SCALE>
impl<const SCALE: u32> D38<SCALE>
Sourcepub fn tan_fast(self) -> Self
pub fn tan_fast(self) -> Self
Tangent of self, where self is in radians.
f64::tan returns very large magnitudes near odd multiples of
pi/2 and infinity at the limit. Inputs that drive the f64
result outside [D38::MIN, D38::MAX] saturate per
Self::from_f64.
§Precision
Lossy: involves f64 at some point; result may lose precision.
§Examples
use decimal_scaled::D38s12;
// tan(0) == 0 (bit-exact: f64::tan(0.0) == 0.0).
assert_eq!(D38s12::ZERO.tan(), D38s12::ZERO);Sourcepub fn asin_fast(self) -> Self
pub fn asin_fast(self) -> Self
Arcsine of self. Returns radians in [-pi/2, pi/2].
f64::asin returns NaN for inputs outside [-1, 1], which
Self::from_f64 maps to D38::ZERO.
§Precision
Lossy: involves f64 at some point; result may lose precision.
§Examples
use decimal_scaled::D38s12;
// asin(0) == 0.
assert_eq!(D38s12::ZERO.asin(), D38s12::ZERO);Sourcepub fn acos_fast(self) -> Self
pub fn acos_fast(self) -> Self
Arccosine of self. Returns radians in [0, pi].
f64::acos returns NaN for inputs outside [-1, 1], which
Self::from_f64 maps to D38::ZERO.
§Precision
Lossy: involves f64 at some point; result may lose precision.
§Examples
use decimal_scaled::{D38s12, DecimalConsts};
// acos(1) == 0.
assert_eq!(D38s12::ONE.acos(), D38s12::ZERO);Sourcepub fn atan2_fast(self, other: Self) -> Self
pub fn atan2_fast(self, other: Self) -> Self
Four-quadrant arctangent of self (y) over other (x).
Returns radians in (-pi, pi].
Signature matches f64::atan2(self, other): the receiver is
y and the argument is x.
§Precision
Lossy: involves f64 at some point; result may lose precision.
§Examples
use decimal_scaled::{D38s12, DecimalConsts};
// atan2(1, 1) ~= pi/4 (45 degrees, first quadrant).
let one = D38s12::ONE;
let result = one.atan2(one); // approximately D38s12::quarter_pi()Sourcepub fn sinh_fast(self) -> Self
pub fn sinh_fast(self) -> Self
Hyperbolic sine of self.
Defined for the entire real line. Saturates at large magnitudes
per Self::from_f64.
§Precision
Lossy: involves f64 at some point; result may lose precision.
§Examples
use decimal_scaled::D38s12;
// sinh(0) == 0.
assert_eq!(D38s12::ZERO.sinh(), D38s12::ZERO);Sourcepub fn cosh_fast(self) -> Self
pub fn cosh_fast(self) -> Self
Hyperbolic cosine of self.
Defined for the entire real line; result is always >= 1.
Saturates at large magnitudes per Self::from_f64.
§Precision
Lossy: involves f64 at some point; result may lose precision.
§Examples
use decimal_scaled::D38s12;
// cosh(0) == 1.
assert_eq!(D38s12::ZERO.cosh(), D38s12::ONE);Sourcepub fn asinh_fast(self) -> Self
pub fn asinh_fast(self) -> Self
Sourcepub fn acosh_fast(self) -> Self
pub fn acosh_fast(self) -> Self
Inverse hyperbolic cosine of self.
f64::acosh returns NaN for inputs less than 1, which
Self::from_f64 maps to D38::ZERO.
§Precision
Lossy: involves f64 at some point; result may lose precision.
§Examples
use decimal_scaled::D38s12;
// acosh(1) == 0.
assert_eq!(D38s12::ONE.acosh(), D38s12::ZERO);Sourcepub fn atanh_fast(self) -> Self
pub fn atanh_fast(self) -> Self
Inverse hyperbolic tangent of self.
f64::atanh returns NaN for inputs outside (-1, 1), which
Self::from_f64 maps to D38::ZERO.
§Precision
Lossy: involves f64 at some point; result may lose precision.
§Examples
use decimal_scaled::D38s12;
// atanh(0) == 0.
assert_eq!(D38s12::ZERO.atanh(), D38s12::ZERO);Sourcepub fn to_degrees_fast(self) -> Self
pub fn to_degrees_fast(self) -> Self
Convert radians to degrees: self * (180 / pi).
Routed through f64::to_degrees so results match the de facto
reference produced by the rest of the Rust ecosystem. Multiplying
by a precomputed D38 factor derived from D38::pi() would
diverge from f64 by a 1-LSB rescale rounding without any
practical determinism gain, since the f64 bridge is already the
precision floor.
§Precision
Lossy: involves f64 at some point; result may lose precision.
§Examples
use decimal_scaled::D38s12;
// to_degrees(0) == 0.
assert_eq!(D38s12::ZERO.to_degrees(), D38s12::ZERO);Sourcepub fn to_radians_fast(self) -> Self
pub fn to_radians_fast(self) -> Self
Convert degrees to radians: self * (pi / 180).
Routed through f64::to_radians. See Self::to_degrees for
the rationale.
§Precision
Lossy: involves f64 at some point; result may lose precision.
§Examples
use decimal_scaled::D38s12;
// to_radians(0) == 0.
assert_eq!(D38s12::ZERO.to_radians(), D38s12::ZERO);Trait Implementations§
Source§impl<const SCALE: u32> AddAssign for D38<SCALE>
impl<const SCALE: u32> AddAssign for D38<SCALE>
Source§fn add_assign(&mut self, rhs: Self)
fn add_assign(&mut self, rhs: Self)
+= operation. Read moreSource§impl<const SCALE: u32> BitAndAssign for D38<SCALE>
impl<const SCALE: u32> BitAndAssign for D38<SCALE>
Source§fn bitand_assign(&mut self, rhs: Self)
fn bitand_assign(&mut self, rhs: Self)
&= operation. Read moreSource§impl<const SCALE: u32> BitOrAssign for D38<SCALE>
impl<const SCALE: u32> BitOrAssign for D38<SCALE>
Source§fn bitor_assign(&mut self, rhs: Self)
fn bitor_assign(&mut self, rhs: Self)
|= operation. Read moreSource§impl<const SCALE: u32> BitXorAssign for D38<SCALE>
impl<const SCALE: u32> BitXorAssign for D38<SCALE>
Source§fn bitxor_assign(&mut self, rhs: Self)
fn bitxor_assign(&mut self, rhs: Self)
^= operation. Read moreSource§impl<const SCALE: u32> CheckedAdd for D38<SCALE>
impl<const SCALE: u32> CheckedAdd for D38<SCALE>
Source§fn checked_add(&self, rhs: &Self) -> Option<Self>
fn checked_add(&self, rhs: &Self) -> Option<Self>
None is
returned.Source§impl<const SCALE: u32> CheckedDiv for D38<SCALE>
impl<const SCALE: u32> CheckedDiv for D38<SCALE>
Source§fn checked_div(&self, rhs: &Self) -> Option<Self>
fn checked_div(&self, rhs: &Self) -> Option<Self>
None is returned.Source§impl<const SCALE: u32> CheckedMul for D38<SCALE>
impl<const SCALE: u32> CheckedMul for D38<SCALE>
Source§fn checked_mul(&self, rhs: &Self) -> Option<Self>
fn checked_mul(&self, rhs: &Self) -> Option<Self>
None is returned.Source§impl<const SCALE: u32> CheckedNeg for D38<SCALE>
impl<const SCALE: u32> CheckedNeg for D38<SCALE>
Source§fn checked_neg(&self) -> Option<Self>
fn checked_neg(&self) -> Option<Self>
None for results that can’t be represented, like signed MIN
values that can’t be positive, or non-zero unsigned values that can’t be negative. Read moreSource§impl<const SCALE: u32> CheckedRem for D38<SCALE>
impl<const SCALE: u32> CheckedRem for D38<SCALE>
Source§fn checked_rem(&self, rhs: &Self) -> Option<Self>
fn checked_rem(&self, rhs: &Self) -> Option<Self>
None is returned. Read moreSource§impl<const SCALE: u32> CheckedSub for D38<SCALE>
impl<const SCALE: u32> CheckedSub for D38<SCALE>
Source§fn checked_sub(&self, rhs: &Self) -> Option<Self>
fn checked_sub(&self, rhs: &Self) -> Option<Self>
None is returned.Source§impl<const SCALE: u32> Decimal for D38<SCALE>
impl<const SCALE: u32> Decimal for D38<SCALE>
Source§const SCALE: u32 = SCALE
const SCALE: u32 = SCALE
10^-SCALE.Source§const MAX_SCALE: u32 = 38
const MAX_SCALE: u32 = 38
SCALE for this width. Equal to the largest
k such that 10^k fits in Self::Storage. For example, 38
for D38, 76 for D76.Source§const MAX: Self = D38<SCALE>::MAX
const MAX: Self = D38<SCALE>::MAX
Self::Storage::MAX).Source§const MIN: Self = D38<SCALE>::MIN
const MIN: Self = D38<SCALE>::MIN
Self::Storage::MIN).Source§fn multiplier() -> i128
fn multiplier() -> i128
10^SCALE, the factor that converts a logical integer
to its storage representation.Source§fn scale(self) -> u32
fn scale(self) -> u32
Self::SCALE; provided for ergonomic method-call syntax).Source§fn abs(self) -> Self
fn abs(self) -> Self
Self::MIN.abs() panics in debug, wraps to
Self::MIN in release (mirroring the storage type).Source§fn is_positive(self) -> bool
fn is_positive(self) -> bool
true when self > ZERO.Source§fn is_negative(self) -> bool
fn is_negative(self) -> bool
true when self < ZERO.Source§fn is_infinite(self) -> bool
fn is_infinite(self) -> bool
false — fixed-point decimals cannot represent infinity.Source§fn div_euclid(self, rhs: Self) -> Self
fn div_euclid(self, rhs: Self) -> Self
Self. Panics on rhs == ZERO.Source§fn rem_euclid(self, rhs: Self) -> Self
fn rem_euclid(self, rhs: Self) -> Self
rhs != ZERO. Panics on
rhs == ZERO.Source§fn div_floor(self, rhs: Self) -> Self
fn div_floor(self, rhs: Self) -> Self
-∞). Panics on rhs == ZERO.Source§fn div_ceil(self, rhs: Self) -> Self
fn div_ceil(self, rhs: Self) -> Self
+∞). Panics on rhs == ZERO.Source§fn midpoint(self, rhs: Self) -> Self
fn midpoint(self, rhs: Self) -> Self
self and rhs (rounding toward -∞), computed
without intermediate overflow.Source§fn mul_add(self, a: Self, b: Self) -> Self
fn mul_add(self, a: Self, b: Self) -> Self
self * a + b — mirrors the f64::mul_add call shape so
f64-generic numeric code can monomorphise to a decimal type.Source§fn pow(self, exp: u32) -> Self
fn pow(self, exp: u32) -> Self
self^exp via square-and-multiply. Overflow follows Mul
(debug panic, release wrap).Source§fn powi(self, exp: i32) -> Self
fn powi(self, exp: i32) -> Self
exp produces
ONE / self.pow(|exp|); the divide truncates at the type’s
scale.Source§fn checked_pow(self, exp: u32) -> Option<Self>
fn checked_pow(self, exp: u32) -> Option<Self>
Some(self^exp), or None if any intermediate step overflows.Source§fn wrapping_pow(self, exp: u32) -> Self
fn wrapping_pow(self, exp: u32) -> Self
pow. Each multiplication step wraps in the storage
type.Source§fn saturating_pow(self, exp: u32) -> Self
fn saturating_pow(self, exp: u32) -> Self
pow — clamps to MAX / MIN on overflow, with
the sign matching the mathematical result.Source§fn overflowing_pow(self, exp: u32) -> (Self, bool)
fn overflowing_pow(self, exp: u32) -> (Self, bool)
(self^exp, overflowed) — the wrapping result paired with a
boolean.Source§fn checked_add(self, rhs: Self) -> Option<Self>
fn checked_add(self, rhs: Self) -> Option<Self>
Some(self + rhs), or None if the sum overflows.Source§fn checked_sub(self, rhs: Self) -> Option<Self>
fn checked_sub(self, rhs: Self) -> Option<Self>
Some(self - rhs), or None if the difference overflows.Source§fn checked_mul(self, rhs: Self) -> Option<Self>
fn checked_mul(self, rhs: Self) -> Option<Self>
Some(self * rhs), or None if the scaled product overflows.Source§fn checked_div(self, rhs: Self) -> Option<Self>
fn checked_div(self, rhs: Self) -> Option<Self>
Some(self / rhs), or None if rhs == ZERO or the quotient
overflows the storage.Source§fn checked_neg(self) -> Option<Self>
fn checked_neg(self) -> Option<Self>
Some(-self), or None when self == MIN.Source§fn checked_rem(self, rhs: Self) -> Option<Self>
fn checked_rem(self, rhs: Self) -> Option<Self>
Some(self % rhs), or None on divide-by-zero / MIN % -ONE.Source§fn wrapping_add(self, rhs: Self) -> Self
fn wrapping_add(self, rhs: Self) -> Self
+.Source§fn wrapping_sub(self, rhs: Self) -> Self
fn wrapping_sub(self, rhs: Self) -> Self
-.Source§fn wrapping_mul(self, rhs: Self) -> Self
fn wrapping_mul(self, rhs: Self) -> Self
* — intermediate widens for overflow detection, the
final narrowing wraps.Source§fn wrapping_div(self, rhs: Self) -> Self
fn wrapping_div(self, rhs: Self) -> Self
/ — panics on rhs == ZERO, matching
i128::wrapping_div.Source§fn wrapping_neg(self) -> Self
fn wrapping_neg(self) -> Self
-self; MIN.wrapping_neg() == MIN.Source§fn wrapping_rem(self, rhs: Self) -> Self
fn wrapping_rem(self, rhs: Self) -> Self
% — panics on rhs == ZERO.Source§fn saturating_add(self, rhs: Self) -> Self
fn saturating_add(self, rhs: Self) -> Self
+.Source§fn saturating_sub(self, rhs: Self) -> Self
fn saturating_sub(self, rhs: Self) -> Self
-.Source§fn saturating_mul(self, rhs: Self) -> Self
fn saturating_mul(self, rhs: Self) -> Self
* — sign of the saturated bound matches the
mathematical product.Source§fn saturating_div(self, rhs: Self) -> Self
fn saturating_div(self, rhs: Self) -> Self
/ — divide-by-zero saturates to MAX / MIN
according to the sign of self.Source§fn saturating_neg(self) -> Self
fn saturating_neg(self) -> Self
-self — MIN.saturating_neg() == MAX.Source§fn overflowing_add(self, rhs: Self) -> (Self, bool)
fn overflowing_add(self, rhs: Self) -> (Self, bool)
+.Source§fn overflowing_sub(self, rhs: Self) -> (Self, bool)
fn overflowing_sub(self, rhs: Self) -> (Self, bool)
-.Source§fn overflowing_mul(self, rhs: Self) -> (Self, bool)
fn overflowing_mul(self, rhs: Self) -> (Self, bool)
*.Source§fn overflowing_div(self, rhs: Self) -> (Self, bool)
fn overflowing_div(self, rhs: Self) -> (Self, bool)
/ — overflowed is true on out-of-range or
divide-by-zero.Source§fn overflowing_neg(self) -> (Self, bool)
fn overflowing_neg(self) -> (Self, bool)
-self — overflowed is true iff self == MIN.Source§fn overflowing_rem(self, rhs: Self) -> (Self, bool)
fn overflowing_rem(self, rhs: Self) -> (Self, bool)
%.Source§fn from_i32(value: i32) -> Self
fn from_i32(value: i32) -> Self
i32, scaling by 10^SCALE. Width-generic
integer constructor; for wider source integers use the
concrete type’s from_int (whose IntSrc parameter varies
per width).Source§fn to_int(self) -> i64
fn to_int(self) -> i64
i64 using the crate-default rounding mode, with
saturating overflow on out-of-range integer parts.Source§fn to_int_with(self, mode: RoundingMode) -> i64
fn to_int_with(self, mode: RoundingMode) -> i64
i64 using the supplied rounding mode for the
fractional discard step. Saturating overflow on out-of-range
integer parts.Source§fn from_f64(value: f64) -> Self
fn from_f64(value: f64) -> Self
f64 using the crate-default rounding mode.
NaN saturates to ZERO; ±∞ saturates to MAX / MIN.Source§fn from_f64_with(value: f64, mode: RoundingMode) -> Self
fn from_f64_with(value: f64, mode: RoundingMode) -> Self
f64 using the supplied rounding mode.Source§fn to_f64(self) -> f64
fn to_f64(self) -> f64
f64. Lossy when the storage magnitude exceeds
f64’s ~15-digit exact range.Source§fn is_normal(self) -> bool
fn is_normal(self) -> bool
true for every non-zero value (a fixed-point decimal has no
subnormals).Source§fn sum<I>(iter: I) -> Selfwhere
I: IntoIterator<Item = Self>,
fn sum<I>(iter: I) -> Selfwhere
I: IntoIterator<Item = Self>,
ZERO. Width-generic convenience for iter.fold(ZERO, +).Source§fn product<I>(iter: I) -> Selfwhere
I: IntoIterator<Item = Self>,
fn product<I>(iter: I) -> Selfwhere
I: IntoIterator<Item = Self>,
ONE. Width-generic convenience for iter.fold(ONE, *).Source§impl<const SCALE: u32> DecimalConsts for D38<SCALE>
impl<const SCALE: u32> DecimalConsts for D38<SCALE>
Source§fn quarter_pi() -> Self
fn quarter_pi() -> Self
Source§impl<const SCALE: u32> Default for D38<SCALE>
Default returns ZERO, matching i128::default() == 0.
impl<const SCALE: u32> Default for D38<SCALE>
Default returns ZERO, matching i128::default() == 0.
This lets #[derive(Default)] work correctly on structs that contain
D38<S> fields.
Source§impl<'de, const SCALE: u32> Deserialize<'de> for D38<SCALE>
impl<'de, const SCALE: u32> Deserialize<'de> for D38<SCALE>
Source§fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
Deserialise from a base-10 integer string (human-readable formats), 16 little-endian bytes (binary formats), or a native integer (self-describing binary formats such as CBOR).
Human-readable formats route via deserialize_any so a JSON
string, JSON number, or TOML integer all reach the correct
visitor branch. Binary formats that are not self-describing
(postcard, bincode) route via deserialize_bytes directly.
§Precision
Strict: all arithmetic is integer-only; result is bit-exact.
Source§impl<const SCALE: u32> Div for D38<SCALE>
impl<const SCALE: u32> Div for D38<SCALE>
Source§fn div(self, rhs: Self) -> Self
fn div(self, rhs: Self) -> Self
Divide self by rhs, rescaling the numerator to keep the result
in value * 10^S form.
The numerator self.0 is widened to 256 bits and multiplied by
10^SCALE before dividing by rhs.0. This avoids the intermediate
overflow that would occur with a naive (self.0 * 10^S) / rhs.0
approach at large dividend magnitudes.
§Panics
Panics on division by zero (matching i128 /). Also panics in debug
builds when the final quotient overflows i128; wraps in release
builds.
§Precision
Strict: all arithmetic is integer-only; result is bit-exact.
§Examples
use decimal_scaled::D38s12;
let a = D38s12::from_bits(3_000_000_000_000); // 3.0
let b = D38s12::from_bits(2_000_000_000_000); // 2.0
assert_eq!((a / b).to_bits(), 1_500_000_000_000); // 1.5Source§impl<const SCALE: u32> DivAssign for D38<SCALE>
impl<const SCALE: u32> DivAssign for D38<SCALE>
Source§fn div_assign(&mut self, rhs: Self)
fn div_assign(&mut self, rhs: Self)
Divide self by rhs in place.
§Precision
Strict: all arithmetic is integer-only; result is bit-exact.
Source§impl<const SCALE: u32> FromPrimitive for D38<SCALE>
impl<const SCALE: u32> FromPrimitive for D38<SCALE>
Source§fn from_i64(n: i64) -> Option<Self>
fn from_i64(n: i64) -> Option<Self>
i64 to return an optional value of this type. If the
value cannot be represented by this type, then None is returned.Source§fn from_u64(n: u64) -> Option<Self>
fn from_u64(n: u64) -> Option<Self>
u64 to return an optional value of this type. If the
value cannot be represented by this type, then None is returned.Source§fn from_i128(n: i128) -> Option<Self>
fn from_i128(n: i128) -> Option<Self>
i128 to return an optional value of this type. If the
value cannot be represented by this type, then None is returned. Read moreSource§fn from_u128(n: u128) -> Option<Self>
fn from_u128(n: u128) -> Option<Self>
u128 to return an optional value of this type. If the
value cannot be represented by this type, then None is returned. Read moreSource§fn from_f32(n: f32) -> Option<Self>
fn from_f32(n: f32) -> Option<Self>
f32 to return an optional value of this type. If the
value cannot be represented by this type, then None is returned.Source§fn from_f64(n: f64) -> Option<Self>
fn from_f64(n: f64) -> Option<Self>
f64 to return an optional value of this type. If the
value cannot be represented by this type, then None is returned. Read moreSource§fn from_isize(n: isize) -> Option<Self>
fn from_isize(n: isize) -> Option<Self>
isize to return an optional value of this type. If the
value cannot be represented by this type, then None is returned.Source§fn from_i8(n: i8) -> Option<Self>
fn from_i8(n: i8) -> Option<Self>
i8 to return an optional value of this type. If the
value cannot be represented by this type, then None is returned.Source§fn from_i16(n: i16) -> Option<Self>
fn from_i16(n: i16) -> Option<Self>
i16 to return an optional value of this type. If the
value cannot be represented by this type, then None is returned.Source§fn from_i32(n: i32) -> Option<Self>
fn from_i32(n: i32) -> Option<Self>
i32 to return an optional value of this type. If the
value cannot be represented by this type, then None is returned.Source§fn from_usize(n: usize) -> Option<Self>
fn from_usize(n: usize) -> Option<Self>
usize to return an optional value of this type. If the
value cannot be represented by this type, then None is returned.Source§fn from_u8(n: u8) -> Option<Self>
fn from_u8(n: u8) -> Option<Self>
u8 to return an optional value of this type. If the
value cannot be represented by this type, then None is returned.Source§impl<const SCALE: u32> LowerExp for D38<SCALE>
impl<const SCALE: u32> LowerExp for D38<SCALE>
Source§fn fmt(&self, f: &mut Formatter<'_>) -> Result
fn fmt(&self, f: &mut Formatter<'_>) -> Result
Formats the value in scientific notation with a lowercase e.
Trailing zeros in the mantissa are stripped, so 1.500000000000
formats as 1.5e0. Zero formats as 0e0.
§Precision
Strict: all arithmetic is integer-only; result is bit-exact.
§Examples
use decimal_scaled::D38s12;
let v = D38s12::from_bits(1_500_000_000_000);
assert_eq!(format!("{v:e}"), "1.5e0");
let sub = D38s12::from_bits(1_500_000_000);
assert_eq!(format!("{sub:e}"), "1.5e-3");Source§impl<const SCALE: u32> Mul for D38<SCALE>
impl<const SCALE: u32> Mul for D38<SCALE>
Source§fn mul(self, rhs: Self) -> Self
fn mul(self, rhs: Self) -> Self
Multiply two values, rescaling the result back to value * 10^S form.
The raw product a.0 * b.0 has units 10^(2S), so it must be
divided by 10^S to restore the canonical scale. This is done via
a 256-bit widening intermediate and a Moller-Granlund magic-number
divide (see the mg_divide module), which avoids the intermediate
overflow that would occur with a naive i128 multiply at large
operand magnitudes.
§Panics
Panics in debug builds when the final rescaled quotient overflows
i128::MAX. In release builds the result wraps two’s-complement.
§Precision
Strict: all arithmetic is integer-only; result is bit-exact.
§Examples
use decimal_scaled::D38s12;
let a = D38s12::from_bits(1_500_000_000_000); // 1.5
let b = D38s12::from_bits(2_000_000_000_000); // 2.0
assert_eq!((a * b).to_bits(), 3_000_000_000_000); // 3.0Source§impl<const SCALE: u32> MulAssign for D38<SCALE>
impl<const SCALE: u32> MulAssign for D38<SCALE>
Source§fn mul_assign(&mut self, rhs: Self)
fn mul_assign(&mut self, rhs: Self)
Multiply self by rhs in place.
§Precision
Strict: all arithmetic is integer-only; result is bit-exact.
Source§impl<const SCALE: u32> Num for D38<SCALE>
impl<const SCALE: u32> Num for D38<SCALE>
type FromStrRadixErr = ParseError
Source§fn from_str_radix(s: &str, radix: u32) -> Result<Self, Self::FromStrRadixErr>
fn from_str_radix(s: &str, radix: u32) -> Result<Self, Self::FromStrRadixErr>
2..=36). Read moreSource§impl<const SCALE: u32> Ord for D38<SCALE>
impl<const SCALE: u32> Ord for D38<SCALE>
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl<const SCALE: u32> PartialEq<D38<SCALE>> for f32
impl<const SCALE: u32> PartialEq<D38<SCALE>> for f32
Source§impl<const SCALE: u32> PartialEq<D38<SCALE>> for f64
impl<const SCALE: u32> PartialEq<D38<SCALE>> for f64
Source§impl<const SCALE: u32> PartialEq<D38<SCALE>> for i128
impl<const SCALE: u32> PartialEq<D38<SCALE>> for i128
Source§impl<const SCALE: u32> PartialEq<D38<SCALE>> for i16
impl<const SCALE: u32> PartialEq<D38<SCALE>> for i16
Source§impl<const SCALE: u32> PartialEq<D38<SCALE>> for i32
impl<const SCALE: u32> PartialEq<D38<SCALE>> for i32
Source§impl<const SCALE: u32> PartialEq<D38<SCALE>> for i64
impl<const SCALE: u32> PartialEq<D38<SCALE>> for i64
Source§impl<const SCALE: u32> PartialEq<D38<SCALE>> for i8
impl<const SCALE: u32> PartialEq<D38<SCALE>> for i8
Source§impl<const SCALE: u32> PartialEq<D38<SCALE>> for isize
impl<const SCALE: u32> PartialEq<D38<SCALE>> for isize
Source§impl<const SCALE: u32> PartialEq<D38<SCALE>> for u128
impl<const SCALE: u32> PartialEq<D38<SCALE>> for u128
Source§impl<const SCALE: u32> PartialEq<D38<SCALE>> for u16
impl<const SCALE: u32> PartialEq<D38<SCALE>> for u16
Source§impl<const SCALE: u32> PartialEq<D38<SCALE>> for u32
impl<const SCALE: u32> PartialEq<D38<SCALE>> for u32
Source§impl<const SCALE: u32> PartialEq<D38<SCALE>> for u64
impl<const SCALE: u32> PartialEq<D38<SCALE>> for u64
Source§impl<const SCALE: u32> PartialEq<D38<SCALE>> for u8
impl<const SCALE: u32> PartialEq<D38<SCALE>> for u8
Source§impl<const SCALE: u32> PartialEq<D38<SCALE>> for usize
impl<const SCALE: u32> PartialEq<D38<SCALE>> for usize
Source§impl<const SCALE: u32> PartialEq for D38<SCALE>
impl<const SCALE: u32> PartialEq for D38<SCALE>
Source§impl<const SCALE: u32> PartialOrd for D38<SCALE>
impl<const SCALE: u32> PartialOrd for D38<SCALE>
Source§impl<const SCALE: u32> RemAssign for D38<SCALE>
impl<const SCALE: u32> RemAssign for D38<SCALE>
Source§fn rem_assign(&mut self, rhs: Self)
fn rem_assign(&mut self, rhs: Self)
%= operation. Read moreSource§impl<const SCALE: u32> ShlAssign<u32> for D38<SCALE>
impl<const SCALE: u32> ShlAssign<u32> for D38<SCALE>
Source§fn shl_assign(&mut self, n: u32)
fn shl_assign(&mut self, n: u32)
<<= operation. Read moreSource§impl<const SCALE: u32> ShrAssign<u32> for D38<SCALE>
impl<const SCALE: u32> ShrAssign<u32> for D38<SCALE>
Source§fn shr_assign(&mut self, n: u32)
fn shr_assign(&mut self, n: u32)
>>= operation. Read moreSource§impl<const SCALE: u32> Signed for D38<SCALE>
impl<const SCALE: u32> Signed for D38<SCALE>
Source§fn is_positive(&self) -> bool
fn is_positive(&self) -> bool
Source§fn is_negative(&self) -> bool
fn is_negative(&self) -> bool
Source§impl<const SCALE: u32> SubAssign for D38<SCALE>
impl<const SCALE: u32> SubAssign for D38<SCALE>
Source§fn sub_assign(&mut self, rhs: Self)
fn sub_assign(&mut self, rhs: Self)
-= operation. Read moreSource§impl<const SCALE: u32> ToPrimitive for D38<SCALE>
impl<const SCALE: u32> ToPrimitive for D38<SCALE>
Source§fn to_i64(&self) -> Option<i64>
fn to_i64(&self) -> Option<i64>
self to an i64. If the value cannot be
represented by an i64, then None is returned.Source§fn to_u64(&self) -> Option<u64>
fn to_u64(&self) -> Option<u64>
self to a u64. If the value cannot be
represented by a u64, then None is returned.Source§fn to_i128(&self) -> Option<i128>
fn to_i128(&self) -> Option<i128>
self to an i128. If the value cannot be
represented by an i128 (i64 under the default implementation), then
None is returned. Read moreSource§fn to_u128(&self) -> Option<u128>
fn to_u128(&self) -> Option<u128>
self to a u128. If the value cannot be
represented by a u128 (u64 under the default implementation), then
None is returned. Read moreSource§fn to_f32(&self) -> Option<f32>
fn to_f32(&self) -> Option<f32>
self to an f32. Overflows may map to positive
or negative inifinity, otherwise None is returned if the value cannot
be represented by an f32.Source§fn to_f64(&self) -> Option<f64>
fn to_f64(&self) -> Option<f64>
self to an f64. Overflows may map to positive
or negative inifinity, otherwise None is returned if the value cannot
be represented by an f64. Read moreSource§fn to_isize(&self) -> Option<isize>
fn to_isize(&self) -> Option<isize>
self to an isize. If the value cannot be
represented by an isize, then None is returned.Source§fn to_i8(&self) -> Option<i8>
fn to_i8(&self) -> Option<i8>
self to an i8. If the value cannot be
represented by an i8, then None is returned.Source§fn to_i16(&self) -> Option<i16>
fn to_i16(&self) -> Option<i16>
self to an i16. If the value cannot be
represented by an i16, then None is returned.Source§fn to_i32(&self) -> Option<i32>
fn to_i32(&self) -> Option<i32>
self to an i32. If the value cannot be
represented by an i32, then None is returned.Source§fn to_usize(&self) -> Option<usize>
fn to_usize(&self) -> Option<usize>
self to a usize. If the value cannot be
represented by a usize, then None is returned.Source§fn to_u8(&self) -> Option<u8>
fn to_u8(&self) -> Option<u8>
self to a u8. If the value cannot be
represented by a u8, then None is returned.Source§impl<const SCALE: u32> TryFrom<D153<SCALE>> for D38<SCALE>
impl<const SCALE: u32> TryFrom<D153<SCALE>> for D38<SCALE>
Source§fn try_from(value: D153<SCALE>) -> Result<Self, Self::Error>
fn try_from(value: D153<SCALE>) -> Result<Self, Self::Error>
Attempts to narrow a wider decimal type to this narrower
one. Fails with Overflow when the source value exceeds
the destination’s MIN..=MAX. The scale is unchanged.
Source§type Error = ConvertError
type Error = ConvertError
Source§impl<const SCALE: u32> TryFrom<D38<SCALE>> for D18<SCALE>
impl<const SCALE: u32> TryFrom<D38<SCALE>> for D18<SCALE>
Source§fn try_from(value: D38<SCALE>) -> Result<Self, Self::Error>
fn try_from(value: D38<SCALE>) -> Result<Self, Self::Error>
Attempts to narrow a wider decimal type to this narrower
one. Fails with OutOfRange when the source value
exceeds the destination’s MIN..=MAX. The scale is
unchanged.
Source§type Error = ConvertError
type Error = ConvertError
Source§impl<const SCALE: u32> TryFrom<D38<SCALE>> for D9<SCALE>
impl<const SCALE: u32> TryFrom<D38<SCALE>> for D9<SCALE>
Source§fn try_from(value: D38<SCALE>) -> Result<Self, Self::Error>
fn try_from(value: D38<SCALE>) -> Result<Self, Self::Error>
Attempts to narrow a wider decimal type to this narrower
one. Fails with OutOfRange when the source value
exceeds the destination’s MIN..=MAX. The scale is
unchanged.
Source§type Error = ConvertError
type Error = ConvertError
Source§impl<const SCALE: u32> TryFrom<D76<SCALE>> for D38<SCALE>
impl<const SCALE: u32> TryFrom<D76<SCALE>> for D38<SCALE>
Source§fn try_from(value: D76<SCALE>) -> Result<Self, Self::Error>
fn try_from(value: D76<SCALE>) -> Result<Self, Self::Error>
Attempts to narrow a wider decimal type to this narrower
one. Fails with Overflow when the source value exceeds
the destination’s MIN..=MAX. The scale is unchanged.
Source§type Error = ConvertError
type Error = ConvertError
Source§impl<const SCALE: u32> UpperExp for D38<SCALE>
impl<const SCALE: u32> UpperExp for D38<SCALE>
Source§fn fmt(&self, f: &mut Formatter<'_>) -> Result
fn fmt(&self, f: &mut Formatter<'_>) -> Result
Formats the value in scientific notation with an uppercase E.
Identical to fmt::LowerExp except the exponent separator is E.
§Precision
Strict: all arithmetic is integer-only; result is bit-exact.
§Examples
use decimal_scaled::D38s12;
let v = D38s12::from_bits(1_500_000_000_000);
assert_eq!(format!("{v:E}"), "1.5E0");