A note on result exponents (Decimal and Dec128)
decimo follows the preferred-exponent rules from IEEE 754-2008 §3.3 and the IBM General Decimal Arithmetic specification §4.1. Concretely:
- For
add/subtract, the result exponent ismin(exp(a), exp(b)). - For
multiply, the result exponent isexp(a) + exp(b)— even when the numerical value is zero. SoDecimal("123.45") * Decimal("0")prints as"0.00", not"0", because both operands’ scales are preserved in the product’s scale (-2 + 0 = -2). - For
divide, the ideal exponent isexp(a) - exp(b). The result exponent is the ideal one when the quotient is exact at that scale (Decimal("10.5") / Decimal("2.5")prints as"4.2", not"4.20"), and otherwise the smallest exponent that still represents the exact value (Decimal("123.45") / Decimal("-2")prints as"-61.725"). - The sign of zero is preserved (
Decimal("-0.00")round-trips to"-0.00").
This matches Python’s decimal.Decimal, System.Decimal (.NET BCL,
both C# and VB.NET), and the GDA reference. It differs from
rust_decimal, which always pads multiplication-by-zero to the maximum
scale of the operands and pads exact divide quotients with trailing
zeros to the operand-scale difference. If you need rust_decimal-style
output, call .quantize(...) or .normalize() explicitly.