nx_unitconv.nx
buildroot/runtime/nx_unitconv.nx
about
nx_unitconv.nx -- MEASUREMENT SYSTEMS + EXACT CONVERSION (engineering-twin metrology substrate).
(Placement note: DISTINCT from nx_units.nx = kernel_v2 SI dimensional-ANALYSIS engine (physics equations,
7-D dim vectors) and nx_measure.nx = Lebesgue measure theory. THIS organ converts between the world's
still-used measurement SYSTEMS -- metric, US customary, UK imperial, survey -- on the runtime/i64 stack.
They compose, not compete: analysis checks equations, THIS checks the numbers feeding them.)
The anti-Mars-Climate-Orbiter organ: that probe was lost because one team produced lbf-s and the other READ
it as N-s (factor 4.4482) -- a silent unit mislabel. Doctrine: (1) every value travels WITH a unit index,
(2) conversions are EXACT RATIONALS from the international definitions (1 in = 25.4 mm EXACT since 1959,
1 lb = 453.59237 g EXACT), never floats, (3) every conversion returns an EXACTNESS REMAINDER (0 = exact) so
rounding is VISIBLE, (4) dimension mismatches and overflow REFUSE LOUDLY (error codes) -- never a wrong number.
Covers metric (SI), US customary, UK imperial (gallon/pint DIFFER from US -- still in daily use), the
US-survey-foot trap (1200/3937 m, 2ppm off the international foot -- state-plane data hazard), and the twin's
own fx256-mm grid as a first-class unit. Bases integer-exact: LENGTH nm, MASS ug, FORCE nN, VOLUME uL,
TIME us, IMPULSE nN-s. Data-driven registry: units are TABLE ROWS, auto-gcd-reduced + overflow-guarded at
add (fail-fast). license_tier: ORIGINAL
dependencies 1 imports · 2 importers
imports: nx_syscalls.nx
imported by: nx_cadtwin_report.nxnx_unitconv_gate.nx
structs
| none |
consts
| 19 | const UR_LEN: i64 = 1 |
| 20 | const UR_MASS: i64 = 2 |
| 21 | const UR_FORCE: i64 = 3 |
| 22 | const UR_VOL: i64 = 4 |
| 23 | const UR_TIME: i64 = 5 |
| 24 | const UR_IMP: i64 = 6 |
| 25 | const UR_BIG: i64 = 9000000000000000000 |
functions
| 27 | func ur_gcd(a0: i64, b0: i64) -> i64 |
| 42 | func ur_init(u: *i64, cap: i64) -> i64 |
| 53 | func ur_add(u: *i64, name: *u8, dim: i64, num: i64, den: i64) -> i64 |
| 73 | func ur_streq(a: *u8, b: *u8) -> i64 called by 1: ur_find |
| 83 | func ur_find(u: *i64, name: *u8) -> i64 |
| 94 | func ur_mdiv(val: i64, num: i64, den: i64, out2: *i64) -> i64 called by 1: ur_conv |
| 110 | func ur_conv(u: *i64, val: i64, ia: i64, ib: i64, out2: *i64) -> i64 |
| 149 | func ur_std(u: *i64) -> i64 |