code wiki / (root) / nx_money.nx

nx_money.nx

buildroot/runtime/nx_money.nx

3726 B91 linesdepth 2pulls 2 transitivereach 51 importersview sourcekind librarytopic money
docsdependenciesstructsconstsfunctions

about

nx_money.nx -- R1 of THE NISHI FINANCIAL ECOSYSTEM engine: the NO-FLOAT money substrate. Money is exact i64 MINOR UNITS (cents). Rates are fixed-point scaled by MNY_RATE_SCALE (1e9). All arithmetic is integer -- floats are WRONG for money (0.1 + 0.2 != 0.3), so this is correctness, not doctrine. Provides exact add/sub/neg, rounded division (floor / half-up / banker's half-even), scaled-rate application (interest), APR->periodic, percent constructor, and [-]D.CC formatting. Foundation for the ledger (R2), debt/amortization (R4), audit (R5), optimizer (R7). PRECONDITION on mny_apply_rate: |amount * rate_scaled| < 2^63 (true for all realistic personal-finance amounts; 128-bit-safe widening for extreme values is the R1b hardening rung). license_tier: ORIGINAL

dependencies 1 imports · 31 importers

nx_syscalls.nx nx_money.nx nx_adhd.nx nx_adhd_gate.nx nx_bills.nx nx_bills_gate.nx nx_bills_store_gate.nx nx_browser_buyguard.nx nx_browser_buyguard_gate.nx nx_card_rewards.nx nx_climbout.nx nx_climbout_docs.nx

diagram shows first 10 each side; +0 more imports, +21 more importers in the complete lists below.

imports: nx_syscalls.nx

imported by: nx_adhd.nxnx_adhd_gate.nxnx_bills.nxnx_bills_gate.nxnx_bills_store_gate.nxnx_browser_buyguard.nxnx_browser_buyguard_gate.nxnx_card_rewards.nxnx_climbout.nxnx_climbout_docs.nxnx_climbout_docs_gate.nxnx_climbout_gate.nxnx_climbout_real.nxnx_climbout_real_gate.nxnx_debt_gate.nxnx_debt_payoff.nxnx_doc_extract_gate.nxnx_fin_audit.nxnx_fin_audit_gate.nxnx_fin_dispute.nxnx_fin_dispute_gate.nxnx_fin_finance.nxnx_fin_finance_gate.nxnx_fin_ledger.nxnx_fin_ledger_gate.nxnx_fin_rules_gate.nxnx_finance_web.nxnx_intake_handler_gate.nxnx_money_gate.nxnx_purchase.nxnx_purchase_gate.nx

structs

none

consts

11const MNY_RATE_SCALE: i64 = 1000000000
12const RND_FLOOR: i64 = 0
13const RND_HALF_UP: i64 = 1
14const RND_HALF_EVEN: i64 = 2

functions

16func mny_add(a: i64, b: i64) -> i64 { return a + b }
17func mny_sub(a: i64, b: i64) -> i64 { return a - b }
called by 1: main
18func mny_neg(a: i64) -> i64 { return 0 - a }
called by 1: main
21func mny_div_floor(num: i64, den: i64) -> i64
called by 1: mny_div_round
30func mny_div_round(num: i64, den: i64, mode: i64) -> i64
51func mny_apply_rate(amount: i64, rate_scaled: i64, mode: i64) -> i64
56func mny_rate_monthly(apr_scaled: i64) -> i64
62func mny_rate_from_pct(pct_num: i64, pct_den: i64) -> i64
67func mny_wdec(out: *u8, pos: i64, v: i64) -> i64
called by 1: mny_format calls 1: sys_mmap
80func mny_format(amount: i64, out: *u8) -> i64
called by 3: wmgdmain calls 1: mny_wdec