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:
swaitsandClaude Sonnet 5.5 committed 2026-11-09 20:46:19 -07:00
1 parent 38da08b2c2
commit 786e503858
7 files changed
+559 -80

No files matched your search

+7 -5
View File
@@ -17,9 +17,11 @@
//!
//! 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).
//! pinned below), 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). These are `rust_decimal`'s own behaviours, pinned here as
//! such; the kernel's `Amount for Decimal` refuses both (K-U10, checked
//! in `tests/kernel_bridge/decimal_exact.rs`).
//!
//! 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
@@ -436,8 +438,8 @@ 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.
/// so the day `rust_decimal` makes it exact, this test says so; the
/// kernel's `Amount::checked_add` refuses it (K-U10).
#[test]
fn checked_add_rounds_dust_away_next_to_the_maximum() {
let dust = Decimal::new(4, 1);