nx_numeric.nx
buildroot/runtime/nx_numeric.nx
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
imports: nx_syscalls.nx
imported by: nobody (leaf or entry point)
structs
| 49 | struct KahanState |
consts
| 108 | const NX_DEKKER_SPLIT: f64 = 134217729.0 |
functions
| 54 | func nx_kahan_alloc() -> *KahanState |
| 62 | func nx_kahan_reset(st: *KahanState) -> i64 |
| 68 | func nx_kahan_finish(st: *KahanState) -> f64 called by 1: nx_compensated_dot |
| 88 | func nx_two_sum(a: f64, b: f64) -> f64 |
| 92 | func nx_two_sum_err(a: f64, b: f64) -> f64 |
| 110 | func nx_dekker_hi(a: f64) -> f64 called by 1: nx_two_product_err |
| 115 | func nx_dekker_lo(a: f64) -> f64 called by 1: nx_two_product_err |
| 129 | func nx_two_product(a: f64, b: f64) -> f64 |
| 133 | func nx_two_product_err(a: f64, b: f64) -> f64 |
| 157 | func nx_kahan_add(st: *KahanState, x: f64) -> i64 called by 1: nx_compensated_dot |
| 175 | func nx_compensated_dot(x: *f64, y: *f64, n: i64) -> f64 |