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

+3
View File
@@ -115,5 +115,8 @@ pub fn split_ratio<T: Amount>(amount: T, a: T, b: T, step: T, mode: Rounding) ->
}
let part = round_step(share_of(amount, a, whole)?, step, mode)?;
let rest = amount.checked_sub(part)?;
// A checked subtraction can hand back a negative zero (the negated
// subtrahend keeps the sign bit); money's zero is always +0.
let rest = if rest == T::ZERO { T::ZERO } else { rest };
Some((part, rest))
}