Skip to main content

Module arithmetic

Module arithmetic 

Source
Expand description

Arithmetic operations: add, sub, mul, div, mul_div, neg, abs.

§Scale Alignment

Before addition/subtraction, both operands are scaled to the same number of decimal places (max(a.scale, b.scale)) via align_scales. This can itself overflow if the mantissa is near i128::MAX; that is reported as ArithmeticError::Overflow.

§mul_div Safety

checked_mul_div uses a 256-bit intermediate (U256) for (a × b) / c so that the product does not silently wrap. See [U256] for the implementation.