test(core): decimal_exact pins the add's rounding next to Decimal::MAX

Review: the file's checked_add property stays at the books' sums, so it
couldn't see K-U4's finding that MAX + 0.4 gives Some(MAX); the header
now says where the checks are exact and a test pins the edge.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
swaitsandClaude Opus 5.5 committed 2026-11-08 17:10:16 -07:00
1 parent 986c75b31e
commit e6fe6e2949
1 file changed
+17
+17
View File
@@ -15,6 +15,12 @@
//! property compares the `Decimal` answer to the rational one *exactly*;
//! the rounding operations compare to the correctly rounded rational.
//!
//! Exact only up to the sums the books reach. Near `Decimal::MAX` the add
//! rounds dust away (`MAX + 0.4` gives `Some(MAX)`, found by unit K-U4 and
//! pinned below; plan unit K-U10 makes the kernel refuse it), and a product
//! whose scale can't fit 28 places is rounded (the reason for decision
//! D-75's ten-place bound on foreign amounts and rates).
//!
//! This is a test of the dependency, not of the engine. When a property
//! fails, the finding is `rust_decimal`'s, and the failing case stays here
//! as a regression named for the defect.
@@ -428,6 +434,17 @@ fn checked_add_and_sub_return_none_past_the_maximum() {
);
}
/// Inexact at the edge: within one unit of `Decimal::MAX`, `checked_add`
/// rounds the fraction away instead of refusing (K-U4's finding). Pinned
/// so the day `rust_decimal` or the kernel (unit K-U10) makes it exact,
/// this test says so.
#[test]
fn checked_add_rounds_dust_away_next_to_the_maximum() {
let dust = Decimal::new(4, 1);
assert_eq!(Decimal::MAX.checked_add(dust), Some(Decimal::MAX));
assert_eq!(Decimal::MAX.checked_add(Decimal::new(5, 1)), None);
}
#[test]
fn checked_mul_returns_none_when_the_integer_part_cannot_fit() {
assert_eq!(Decimal::MAX.checked_mul(Decimal::from(2u32)), None);