code wiki / (root) / nx_numeric.nx

nx_numeric.nx

buildroot/runtime/nx_numeric.nx

6550 B191 linesdepth 2pulls 2 transitivereach 0 importersview sourcekind orphan librarytopic numeric
docsdependenciesstructsconstsfunctions

about

numeric.nx -- Kahan-discipline numerical primitives. Per W. Kahan ("How Java's Floating-Point Hurts Everyone Everywhere" 1998 + "MxMulEps" matrix-mul precision paper), a numerically sound language must expose substrate-level building blocks for catastrophic-cancellation-resistant arithmetic. This file ships the canonical three: TwoSum, TwoProduct, and Kahan compensated summation. Compilation note: this module uses `f64` types and arithmetic operators directly, which the NishiLang sovereign sibling (nxc.elf) accepts but the C bootstrap (nxc2.exe) does NOT lex. That is the correct division of labor: C bootstrap is one Wheeler-comparator anchor for the integer subset; f64-using modules Wheeler against a different peer (rustc, gcc-riscv64 compiling an equivalent C program, or self-host nxc.elf when it ships). NishiLang is not limited by what its bootstrap can lex; the bootstrap is limited by NishiLang's needs. Calling convention: state structs caller-allocated via sys_mmap, mutated through pointers; scalar helpers return single f64 values. No struct-by-value returns, no &local out-params (pre-existing language constraints). Bibliography: Dekker (1971) "A Floating-Point Technique for Extending the Available Precision" -- TwoSum, TwoProduct, the SPLIT_FACTOR trick Møller (1965) pre-Dekker accumulating-correction summation Kahan (1965) compensated summation algorithm Kahan & Ivory (1995) "Roundoff Degrades an Idealized Cantilever" Ogita-Rump-Oishi (2005) "Accurate Sum and Dot Product" -- compensated dot product

dependencies 1 imports · 0 importers

nx_syscalls.nx nx_numeric.nx

imports: nx_syscalls.nx

imported by: nobody (leaf or entry point)

structs

49struct KahanState

consts

108const NX_DEKKER_SPLIT: f64 = 134217729.0

functions

54func nx_kahan_alloc() -> *KahanState
called by 1: nx_compensated_dot calls 1: sys_mmap
62func nx_kahan_reset(st: *KahanState) -> i64
68func nx_kahan_finish(st: *KahanState) -> f64
called by 1: nx_compensated_dot
88func nx_two_sum(a: f64, b: f64) -> f64
92func nx_two_sum_err(a: f64, b: f64) -> f64
110func nx_dekker_hi(a: f64) -> f64
called by 1: nx_two_product_err
115func nx_dekker_lo(a: f64) -> f64
called by 1: nx_two_product_err
129func nx_two_product(a: f64, b: f64) -> f64
133func nx_two_product_err(a: f64, b: f64) -> f64
157func nx_kahan_add(st: *KahanState, x: f64) -> i64
called by 1: nx_compensated_dot
175func nx_compensated_dot(x: *f64, y: *f64, n: i64) -> f64