fix(core): the shares keep the old scale, and the floor's correction is bounded
The review's kernel findings, with the bridge properties that hold them. FirstAbsorbs computed the first part as whole minus the rest, which is algebraically the old split_first's parts[0] + (whole minus the sum of parts) but not the same scale: 4860 by 6/0.7/0.5 gave 4050.00 where the old code gave 4050, and 902 by 1/0.000001/0.000001 gave 902 where the old code gave 902.00. That scale reaches Part.amount, so a printed share moved. The kernel computes the old expression now, with checked ops; LastAbsorbs was already the old plug_last and the no-places conventions split. The bridge compares the strings. share_floor_with's correction loop could walk without end on a rounded product far from the exact floor: 0.1113 x 5909471247797156928749568911.8 / 0.11134381908633486049673 hangs. Both directions now stop at MAX_CORRECTION_STEPS and refuse, so an input past the cap is None, never a hang; no figure produced within the cap changes. The bridge pins the input. Ranking needed a property of its own: on i64 every remainder is zero, so the harnesses never rank. A random-weight bridge checks the split against the independent exact reference over non-terminating totals, excluding exact ties because the kernel ranks the rounded quotients' remainders; finding_ties_follow_the_rounded_quotient pins those ties (20.00 by 4/1/1 over 6 is 13.33/3.34/3.33, 20 whole is 13/4/3), today's behaviour and the pre-U3 sites' alike, for K-U10 to decide. share_floor and split_by_weights had no engine caller (only the bridge), so they are gone; split_by_weights_with and share_floor_with are the public API, and the docs say both checked_mul and checked_div can round at Decimal's edge. Co-Authored-By: DeepSeek V4.1 Flash <noreply@opencode.ai>
This commit is contained in:
1 parent
d4440b6a4e
commit
8edc2e85dd
6 files changed
+313
-82
No files matched your search
@@ -365,7 +365,8 @@ fn too_large() -> LedgerError {
|
||||
/// 2. A member's exact running total is Σ whole × weight / Σ weights
|
||||
/// over every split so far; their running total (Σ of their parts)
|
||||
/// is the largest-remainder rounding to the cent of the exact running
|
||||
/// totals (ties to the earlier member), so it is within a cent of
|
||||
/// totals (a tie in the rounded remainders to the earlier member; an
|
||||
/// exact tie follows the quotient's 28th digit, K-U10), so it is within a cent of
|
||||
/// exact, strictly. A negative running whole is rounded as its
|
||||
/// magnitude and negated; a running whole of zero is rounded by the
|
||||
/// sign of the whole just split. So a run of losses mirrors the run
|
||||
@@ -655,7 +656,8 @@ fn entry_wholes(
|
||||
/// their part: the pair leaves every later entry's cents as they
|
||||
/// would be without it. Its own parts (it reads as the contrary
|
||||
/// kind, a distribution for a contribution) are split on its own,
|
||||
/// largest remainder, ties to the earlier member.
|
||||
/// largest remainder, a tie in the rounded remainders to the earlier
|
||||
/// member (an exact tie follows the quotient's 28th digit, K-U10).
|
||||
/// ```
|
||||
fn entry_parts(
|
||||
ledger: &Ledger,
|
||||
|
||||
Reference in new issue
Block a user