refactor(core): proportional shares in the kernel, one copy
The K-1/1065 worksheet, the 1099 worksheet, the parties' shares, the conventions' template split and the cash-flow government split each computed "whole x weight / total, round, hand out the leftover" for themselves. Six copies meant six places for a rounding or sign change to reach a filed figure. Put the shape in kernel::allocate: share_of (the engine's division, rounded at Decimal's 28 significant digits, truncating on a machine integer), share_floor_with (the exact floor to a step by multiplication, the 1099 correction loop's arithmetic), and split_by_weights_with (the split, with the leftover policy named: largest remainder, first absorbs, last absorbs; the running policy stays apportion_cumulative). Each site keeps its own mode, step, sign and leftover policy, so every figure is the same to the digit; the frozen periods rules only gain a doc line naming the kernel policy they equal. Amount gains checked_div, the engine's division as distinct from checked_div_exact. All goldens and existing tests pass unchanged. Co-Authored-By: DeepSeek V4.1 Flash <noreply@opencode.ai>
This commit is contained in:
1 parent
127d33fb0b
commit
24b59e7b85
9 files changed
+394
-84
No files matched your search
@@ -33,6 +33,18 @@ pub trait Amount: Copy + Ord {
|
||||
/// `self / rhs` exactly, or `None` when `rhs` is zero or the quotient
|
||||
/// is not a whole amount of `Self` (never a rounded share).
|
||||
fn checked_div_exact(self, rhs: Self) -> Option<Self>;
|
||||
/// `self / rhs` as the amount type divides: exact where the division
|
||||
/// terminates, otherwise rounded at the type's precision (for
|
||||
/// [`Decimal`], 28 significant digits), and truncating toward zero for
|
||||
/// a machine integer. `None` when `rhs` is zero or the quotient cannot
|
||||
/// be represented.
|
||||
///
|
||||
/// This is the engine's division, not a claim that the quotient is an
|
||||
/// exact rational: [`Amount::checked_div_exact`] is that one. A
|
||||
/// proportional share ([`crate::kernel::share_of`]) is this division,
|
||||
/// so its result is the same figure every call site computed before
|
||||
/// the kernel sweep's U3.
|
||||
fn checked_div(self, rhs: Self) -> Option<Self>;
|
||||
/// `self / rhs`, rounded once to the cent (the nearest whole minor
|
||||
/// unit: a unit for a machine integer, two decimal places for
|
||||
/// [`Decimal`] dollars), ties away from zero; never a negative zero.
|
||||
@@ -86,6 +98,9 @@ impl Amount for Decimal {
|
||||
let q = self.checked_div(rhs)?;
|
||||
(q.checked_mul(rhs) == Some(self)).then_some(q)
|
||||
}
|
||||
fn checked_div(self, rhs: Self) -> Option<Self> {
|
||||
Decimal::checked_div(self, rhs)
|
||||
}
|
||||
fn checked_div_round_cent(self, rhs: Self) -> Option<Self> {
|
||||
if rhs == Self::ZERO {
|
||||
return None;
|
||||
@@ -185,6 +200,9 @@ impl Amount for i32 {
|
||||
}
|
||||
self.checked_div(rhs)
|
||||
}
|
||||
fn checked_div(self, rhs: Self) -> Option<Self> {
|
||||
i32::checked_div(self, rhs)
|
||||
}
|
||||
fn checked_div_round_cent(self, rhs: Self) -> Option<Self> {
|
||||
if rhs == 0 {
|
||||
return None;
|
||||
@@ -237,6 +255,9 @@ impl Amount for i64 {
|
||||
}
|
||||
self.checked_div(rhs)
|
||||
}
|
||||
fn checked_div(self, rhs: Self) -> Option<Self> {
|
||||
i64::checked_div(self, rhs)
|
||||
}
|
||||
fn checked_div_round_cent(self, rhs: Self) -> Option<Self> {
|
||||
if rhs == 0 {
|
||||
return None;
|
||||
|
||||
Reference in new issue
Block a user