Commit Graph
2 Commits
Author SHA1 Message Date
swaitsandDeepSeek V4.1 Flash 803dfc5de0 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>
2026-11-09 09:38:09 -07:00
swaitsandDeepSeek V4.1 Flash a5c62a2412 test(core): Kani and bridge for the kernel ratios
Kani proves the kernel's percentages and ratio splits on i64: a percent is
within half a step of the exact ratio (the model's whole fixed so its
truncating division is exact: an i64 quotient loses the fraction before
the multiply, which Decimal keeps), a percent of a zero or negative whole
is None, and a 1 : 2 split's rounded part plus its exact rest is the
amount.

The bridge carries the same laws to Decimal: the i64 model and the engine
agree where the quotient is exact; percent_of and split_ratio agree with
an independent exact i128 reference (no Decimal division at the reference)
for parts, wholes, ratios and steps of every sign and scale; a split's
parts sum and its rounded side is a whole multiple on every input; and the
edges (Decimal::MAX, scale 28, a zero whole and a zero ratio) are None or
exact, never a panic.

docs/proofs/k-u6.md records the harness-to-law table, the measured times,
the bridge properties and what rounds at Decimal's edge (K-U10). The law
is bookspec law 44; the traceability gate passes against the k-u6 bookspec
branch (the pin moves when that branch is merged).

Co-Authored-By: DeepSeek V4.1 Flash <noreply@opencode.ai>
2026-11-09 09:14:41 -07:00