nx_fx_lib.nx
buildroot/runtime/nx_fx_lib.nx
about
nx_fx_lib.nx -- F984: EXACT MULTI-CURRENCY on the sovereign ledger.
Every incumbent FX path loses fractions of a cent to rounding and buries it. The sovereign property
here is that a conversion LOSES NO VALUE: the truncated remainder is RETURNED and accounted, never
silently dropped, so a converted amount can be reconstructed EXACTLY. Money is neither created nor
destroyed by crossing a currency boundary -- the same invariant the ledger enforces within one
currency, extended across two.
A rate is a RATIONAL num/den (integer, exact) -- never a float, because a float rate drifts and an
auditor cannot reproduce it. A rate carries PROVENANCE (source + the pair it prices): a conversion
can cite exactly which rate, from which source, produced its number. No provenance, no conversion is
the honest posture, though the raw fx_convert is available for pure arithmetic.
FAIL-CLOSED: a zero or negative denominator is REFUSED (return -1, remainder 0) -- a divide-by-zero
rate is a data error, not a silent NaN.
SCALE ENVELOPE (declared): fx_convert computes amount*num before dividing, so amount*num must fit i64
(~9.2e18). For cents and realistic rates this is billions of dollars of headroom; a 128-bit widening
mul is the rung if a book ever needs trillions-of-minor-units single transactions. Declared, not hidden.
DRY: composes nx_matter_lib (reg_put/reg_get/mt_field/canon_encode) for rate storage. license_tier: ORIGINAL LIB.
dependencies 1 imports · 1 importers
imports: nx_matter_lib.nx
imported by: nx_fx_gate.nx
structs
| none |
consts
| 23 | const FX_MAGIC_1024: i64 = 1024 |
| 25 | const FX_BAD_RATE: i64 = 0 - 1 |
functions
| 27 | func fx_atoi(s: *u8) -> i64 called by 1: fx_rate_get |
| 43 | func fx_convert(amount: i64, rate_num: i64, rate_den: i64, rem: *i64) -> i64 |
| 52 | func fx_reconstruct(amount_b: i64, rem: i64, rate_num: i64, rate_den: i64) -> i64 called by 1: main |
| 58 | func fx_rate_put(prefix: *u8, pair_id: *u8, rate_num: i64, rate_den: i64, source: *u8) -> i64 |
| 79 | func fx_rate_get(prefix: *u8, pair_id: *u8, num: *i64, den: *i64) -> i64 |
| 94 | func fx_convert_priced(prefix: *u8, pair_id: *u8, amount: i64, rem: *i64) -> i64 |