# K-U12: no Decimal arithmetic outside the kernel (every other crate) K-U11 (`k-u11.md`) brought ledger-core to zero and put the detector in `just check`. This unit does the same for the crates around the core, so bar item 1 of `AGENTS.md` holds for the whole workspace and the compiler checks it. ## What was measured `scripts/raw-decimal-arith.sh `, after K-U9: | Crate | Places | |---|---| | ledger-gui | 123 | | ledger-mcp | 19 | | ledger-import | 18 | | ledger-package | 13 | | ledger-store | 8 | | ledger-config | 2 | | ledger-cli, ledger-host, ledger-reader, ledger-vault | 0 | 183 places. Each was a raw operator on a `Decimal` (it panics when the result does not fit), one of rust_decimal's own `checked_*` methods (it rounds silently past 96 bits, K-U10) or an `Iterator::sum`. ## What was done Every site calls the kernel, or `ledger_core::money`'s helpers over it (`neg`, `signed_amount`, `on_side`, `add_in_range`, `sub_in_range`, public since this unit so the outer crates have no copy of their own): | Was | Now | |---|---| | unary minus | `neg` | | a line's sign by its side, written out as a `match` | `signed_amount`, `on_side` | | `+`, `-`, `+=`, `-=` on figures drawn from the books | `add_in_range`, `sub_in_range`: exact, since posted lines are bounded (BS-entry-3, BS-entry-4) | | `.sum()` of amounts | `kernel::total`, `total_of` | | rust_decimal's `checked_add`, `checked_sub` | `Amount::checked_add`, `checked_sub` by their full path, the same `None` handled the same way | | `/`, `checked_div` | `Amount::checked_div` | | `rescale` | `kernel::rescale_exact`, which cannot round | No figure moves and no test, golden or snapshot was edited. What changes is the edge: a sum exact arithmetic cannot hold is a blank cell, a note or a refusal where a raw operator panicked or rust_decimal rounded. The places that were not a plain sum or sign, each decided one by one before the rewrite and read again in the diff: | Place | Decision | |---|---| | `ledger-config`, `parse_share` | a percent over 100 through `Amount::checked_div`; the shares are summed exactly, and a set too long to add exactly is refused with a sentence saying so | | `ledger-import`, `templates::equal_shares` | 100 / n through the kernel, rounded to two places by `round_places` (a half to even, as before), the last share the exact remainder; no owners gives no shares where `/` panicked | | `ledger-package`, `text.rs` | at least two places, padding only, by `rescale_exact` | | `ledger-store`, the disposal preview | its sums and differences through `Amount`, joining the `None` it already returned | | `ledger-gui`, a party's part of an entry (`books.rs`) | the fraction is a quotient, so its product with each line is a rounded figure by construction: `Amount::checked_mul_rounded`, then cut to the cent as before, the remainder to the first line exactly | | `ledger-gui`, a member's share as a percent (three pages) | `checked_mul_rounded` by 100: rust_decimal's product, which is the exact one here (a share of 28 places times 100 is the same digits at 26) | | `ledger-gui`, "running hot" (`profit.rs`) | the average is a third, a quotient; 1.25 times it is `checked_mul_rounded`, and a limit that cannot be computed flags nothing | | `ledger-gui`, `share_of_what_for` | `kernel::share_of`, the one copy of whole × weight / total (K-U3) | | `ledger-gui`, averages, runway, progress bars, `compact` | `Amount::checked_div`; each quotient is rounded for display or turned into a bar's length on the next line, and none is summed | | `ledger-gui`, the cash-flow table's rows by key | `total_of`; a sum that cannot be computed exactly blanks the cell where `.sum()` panicked | | `ledger-gui`, the demo books | amounts to a step of 25 or 50 by `Amount::checked_div`, `round_places` to a whole number (a half to even, which `Decimal::round` was) and an exact product | Sums of `usize` and `f32` (counts, column widths) are folds, since the detector refuses `Iterator::sum` of any type: reading the source does not show what a `.sum()` adds. ## The gate `just kernel-only`, in the lint part of `just check`, now runs the detector over every crate of the workspace, and fails when a folder under `crates/` is not in the justfile's `kernel_only_crates`: a new crate is held at zero from the day it is added. No crate has a waiver. ## How it was checked - The detector on each crate: 0 places, 0 waived. - Each crate's whole test suite on main after its merge, clippy with warnings denied, and fmt. - Every diff read line by line against the decision made for its site before the rewrite. ledger-store and ledger-config (10 places) were done by hand; the other 173 by two workers from a rule table and a per-site list (`docs/delegation-log.md`). ## What this does not show The same as K-U11's list. The detector shows arithmetic goes through the kernel, not that each site calls the right function; the tests and the reading above carry that. `add_in_range` and `sub_in_range` panic on a sum exact arithmetic cannot hold, as the raw operators did: they are for figures drawn from posted lines, which the line cap keeps in range, and this unit proves nothing new about that bound. The viewer and the exports have no Kani harness or Lean theorem of their own, and need none for this: they hold no arithmetic now.