Skip to main content

add_python_scale

Function add_python_scale 

Source
pub fn add_python_scale(a: Decimal, b: Decimal) -> Decimal
Expand description

Add two decimals with Python decimal’s scale rule.

The value is a + b either way; this only restores the scale rust_decimal drops when an operand is zero (see the module docs). The result is padded UP to max(scale(a), scale(b)) and never truncated, so it cannot lose significant digits.

Rescaling is best-effort: Decimal::rescale is a no-op when the target scale would overflow the 96-bit mantissa (a value near Decimal::MAX at high scale). Such a value cannot be represented at that scale at all, so there is nothing to restore and the unrescaled sum is the best available answer — the same one we returned before this function existed.