fix(core): a ratio split's zero rest is +0, never -0

`split_ratio(0.00, 1, 2, 0.01, half-to-even)` handed the rest back as -0:
the generic `checked_sub` negates the subtrahend, and a zero negated
keeps its sign bit. Decimal equality hides it, but a printed "-0.00" is
not money and a sign test saw it. Map a zero rest to T::ZERO, which is
generic and always +0.

The bridge's edge test now asserts the sign (`!is_sign_negative()`) for
a zero rest and a zero percent, including a negative-zero amount, instead
of trusting equality. Its refusal test also covers a negative step for
both functions, which the kernel already refuses.

Co-Authored-By: DeepSeek V4.1 Flash <noreply@opencode.ai>
This commit is contained in:
swaitsandDeepSeek V4.1 Flash committed 2026-11-09 09:38:09 -07:00
1 parent c9d6c8f59a
commit 803dfc5de0
3 files changed
+72 -12

No files matched your search

+6 -2
View File
@@ -113,11 +113,15 @@ traceability gate, `crates/ledger-core/tests/bookspec/traceability.rs`):
rounded side is a whole multiple of the step, and a zero `a` share
leaves the whole to the rest.
- `percent_of_refuses_no_whole`: a zero or negative whole, a zero ratio
and a non-positive step are `None`, never a division by zero.
and a non-positive step are `None`, never a division by zero. A
negative step refuses both functions.
- `decimal_ratio_at_the_edges`: `Decimal::MAX` (a part past the range
refuses; a split either refuses or sums), scale 28 (a tiny part is
zero, no negative zero; a ratio of one is 100), a whole past the range
(a percent under a unit is zero), and a zero amount split.
(a percent under a unit is zero), and a zero amount split whose two
parts are asserted to be `+0` (a checked subtraction once handed the
rest back as `-0`, which equality hides and a sign test does not). A
zero part over a positive whole is likewise a `+0` percent.
All pass with the rest of `kernel_bridge`.