test(core): the Decimal edges are refused, not rounded
The bridge compares impl Amount for Decimal's add, subtract and multiply with rust_decimal's own result and with an independent BigRational reference over every mantissa to 2^96 - 1 and every scale 0 to 28: a Some is the exact result; an exact old result is returned unchanged, compared as strings; a rounded one is None; an overflow stays None. Over the posted range (line cap, ten places, any raw scale) sums, differences, running totals and FX products are identical to the old to the character, and the FX product is checked rounded once from the exact one in all four rounding modes. Unit tests check the private 256-bit helpers against num_bigint. The pinned findings now assert the law holding: finding_decimal_add_rounds_dust_at_the_edge and finding_decimal_add_rounds_scale_near_the_top become a_sum_past_exact_arithmetic_is_refused, the_mantissa_edge_is_outside_the_precondition_and_pinned becomes the_mantissa_edge_books_the_exact_products_cent (10500000099.89, which the reference gives; the old 99.90 was a double rounding). Expectations that moved are all outside what a posted line carries: 599 parts of 1.3e26 at the cent sum past 96 bits (schedule::the_edges), the 26-place product now rounds once to 0.00, and the replaced-chain comparison refuses a step rust_decimal rounded. No golden changed. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
38da08b2c2
commit
786e503858
7 files changed
+559
-80
No files matched your search
@@ -242,16 +242,25 @@ fn the_edges() {
|
||||
// answer is not None, because the plug is exact; but the quotient
|
||||
// MAX / 2 = ...167.5 has 29 digits, so Decimal's division rounds it to
|
||||
// ...168 first, and the part is half a unit from the exact quotient,
|
||||
// a hundred steps at the cent: the K-U10 item, which is why the
|
||||
// callers refuse totals of 10^26 or more (EXACT_LIMIT).
|
||||
// a hundred steps at the cent: the K-U10 item (the division's, left
|
||||
// as it is), which is why the callers refuse totals of 10^26 or more
|
||||
// (EXACT_LIMIT). The sum of the parts is exact or refused (K-U10):
|
||||
// 599 parts of 1.3e26 at the cent need more than 96 bits at scale 2,
|
||||
// and `rust_decimal` used to round that sum.
|
||||
for months in [1usize, 2, 3, 7, 600] {
|
||||
for step in ["1", "0.01", "0.001"] {
|
||||
let parts = decimal_parts(widest, parse(step), months)
|
||||
.expect("MAX fits: the quotient is smaller, the last is the remainder");
|
||||
let parts = decimal_parts(widest, parse(step), months);
|
||||
if months == 600 && step != "1" {
|
||||
assert_eq!(
|
||||
parts, None,
|
||||
"{months} months at {step}: the sum is not exact"
|
||||
);
|
||||
continue;
|
||||
}
|
||||
let parts =
|
||||
parts.expect("MAX fits: the quotient is smaller, the last is the remainder");
|
||||
assert_eq!(
|
||||
parts
|
||||
.iter()
|
||||
.try_fold(Decimal::ZERO, |a, &b| a.checked_add(b)),
|
||||
kernel::total(parts.iter().copied()),
|
||||
Some(widest),
|
||||
"{months} months at {step}"
|
||||
);
|
||||
|
||||
Reference in new issue
Block a user