code wiki / (root) / nx_i128.nx

nx_i128.nx

buildroot/runtime/nx_i128.nx

9884 B282 linesdepth 3pulls 3 transitivereach 317 importersview sourcekind library
docsdependenciesstructsconstsfunctions

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

syscalls.nx nx_i128.nx nx_acceleration.nx nx_color_v2.nx nx_complex.nx nx_estimator_diagnostics.nx nx_features.nx nx_force.nx nx_gcode_extrude.nx nx_i128_test.nx nx_image.nx nx_lattice.nx

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

34struct I128

consts

39const NX_I128_LO_MASK: i64 = 0xFFFFFFFF
40const NX_I128_HALF_BITS: i64 = 32

functions

44func nx_i128_alloc() -> *I128
52func nx_i128_set_i64(z: *I128, v: i64) -> i64
61func nx_i128_is_neg(z: *I128) -> i64
called by 1: nx_i128_div_i64
68func nx_i128_neg(z: *I128) -> i64
83func nx_i128_add(z: *I128, b: *I128) -> i64
109func nx_i128_mul_u64(a: i64, b: i64, out: *I128) -> i64
called by 1: nx_i128_mul_i64
134func nx_i128_mul_i64(a: i64, b: i64, out: *I128) -> i64
149func nx_i128_shl(z: *I128, n: i64) -> i64
called by 1: nx_mulshl_div_i64
174func nx_i128_udiv_u64(z: *I128, d: i64) -> i64
called by 1: nx_i128_div_i64
243func nx_i128_div_i64(z: *I128, d: i64) -> i64
263func nx_muldiv_i64(a: i64, b: i64, c: i64) -> i64
276func nx_mulshl_div_i64(a: i64, b: i64, shift: i64, c: i64) -> i64