numeric.nx
buildroot/runtime/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: syscalls.nx
imported by: nobody (leaf or entry point)
structs
| 43 | struct KahanState { |
consts
| 102 | const NX_DEKKER_SPLIT: f64 = 134217729.0 |
functions
| 48 | func nx_kahan_alloc() -> *KahanState {
called by 1: nx_compensated_dot |
| 56 | func nx_kahan_reset(st: *KahanState) -> i64 { |
| 62 | func nx_kahan_finish(st: *KahanState) -> f64 {
called by 1: nx_compensated_dot |
| 82 | func nx_two_sum(a: f64, b: f64) -> f64 { |
| 86 | func nx_two_sum_err(a: f64, b: f64) -> f64 { |
| 104 | func nx_dekker_hi(a: f64) -> f64 {
called by 1: nx_two_product_err |
| 109 | func nx_dekker_lo(a: f64) -> f64 {
called by 1: nx_two_product_err |
| 123 | func nx_two_product(a: f64, b: f64) -> f64 { |
| 127 | func nx_two_product_err(a: f64, b: f64) -> f64 { |
| 151 | func nx_kahan_add(st: *KahanState, x: f64) -> i64 {
called by 1: nx_compensated_dot |
| 169 | func nx_compensated_dot(x: *f64, y: *f64, n: i64) -> f64 { |