nx_i128.nx
buildroot/runtime/nx_i128.nx
about
nx_i128.nx -- minimum-viable signed 128-bit integer primitive.
Numeric tier N2 in the substrate's tier ladder (see docs/
NUMERIC_TIER_LADDER.md). Exists because i64 (N1) hits overflow
in cases that occur in the wild: e.g. HLL cubic Lagrange
interpolation at lg_k=10 with milli-units X table produces
intermediate products up to ~1.7e21, exceeding i64 max ~9.2e18.
The substrate's discipline: when i64 isn't enough, ESCALATE to
i128 (or higher). Never silently downgrade precision.
Representation: { hi: i64, lo: i64 } where lo holds the low 64
bits (treated as unsigned via masking) and hi holds the upper 64
bits (signed). Two's-complement throughout. Sign of the i128
= sign of hi.
Operations: enough to support Lagrange interpolation
(mul i64*i64 -> i128, shl by k, div by i64 -> i64). More
operations added as additional callers need them.
Numerical Recipes ref: §1.1 (basic arithmetic) + §5.6 (Lagrange).
Hacker's Delight ch.8 (signed/unsigned multiword arithmetic).
genealogy_id: knuth_taocp_vol2 + warren_hackers_delight
lineage_id: integer_arithmetic
dependencies 1 imports · 17 importers
diagram shows first 10 each side; +0 more imports, +7 more importers in the complete lists below.
imports: syscalls.nx
imported by: nx_acceleration.nxnx_color_v2.nxnx_complex.nxnx_estimator_diagnostics.nxnx_features.nxnx_force.nxnx_gcode_extrude.nxnx_i128_test.nxnx_image.nxnx_lattice.nxnx_measure.nxnx_poly.nxnx_polygon.nxnx_qed_freek.nxnx_sketch_hll.nxnx_torque.nxsketch_hll.nx
structs
| 34 | struct I128 |
consts
| 39 | const NX_I128_LO_MASK: i64 = 0xFFFFFFFF |
| 40 | const NX_I128_HALF_BITS: i64 = 32 |
functions
| 44 | func nx_i128_alloc() -> *I128 |
| 52 | func nx_i128_set_i64(z: *I128, v: i64) -> i64 called by 1: nx_polygon_signed_2area_q28_hi |
| 61 | func nx_i128_is_neg(z: *I128) -> i64 called by 1: nx_i128_div_i64 |
| 68 | func nx_i128_neg(z: *I128) -> i64 |
| 83 | func nx_i128_add(z: *I128, b: *I128) -> i64 called by 1: nx_polygon_signed_2area_q28_hi |
| 109 | func nx_i128_mul_u64(a: i64, b: i64, out: *I128) -> i64 called by 1: nx_i128_mul_i64 |
| 134 | func nx_i128_mul_i64(a: i64, b: i64, out: *I128) -> i64 called by 3: nx_muldiv_i64nx_mulshl_div_i64nx_polygon_signed_2area_q28_hi calls 2: nx_i128_mul_u64nx_i128_neg |
| 149 | func nx_i128_shl(z: *I128, n: i64) -> i64 called by 1: nx_mulshl_div_i64 |
| 174 | func nx_i128_udiv_u64(z: *I128, d: i64) -> i64 called by 1: nx_i128_div_i64 |
| 243 | func nx_i128_div_i64(z: *I128, d: i64) -> i64 |
| 263 | func nx_muldiv_i64(a: i64, b: i64, c: i64) -> i64 |
| 276 | func nx_mulshl_div_i64(a: i64, b: i64, shift: i64, c: i64) -> i64 |