code wiki / (root) / numeric.nx

numeric.nx

buildroot/runtime/numeric.nx

6481 B185 linesdepth 3pulls 3 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

syscalls.nx numeric.nx

imports: syscalls.nx

imported by: nobody (leaf or entry point)

structs

43struct KahanState {

consts

102const NX_DEKKER_SPLIT: f64 = 134217729.0

functions

48func nx_kahan_alloc() -> *KahanState {
called by 1: nx_compensated_dot
56func nx_kahan_reset(st: *KahanState) -> i64 {
62func nx_kahan_finish(st: *KahanState) -> f64 {
called by 1: nx_compensated_dot
82func nx_two_sum(a: f64, b: f64) -> f64 {
86func nx_two_sum_err(a: f64, b: f64) -> f64 {
104func nx_dekker_hi(a: f64) -> f64 {
called by 1: nx_two_product_err
109func nx_dekker_lo(a: f64) -> f64 {
called by 1: nx_two_product_err
123func nx_two_product(a: f64, b: f64) -> f64 {
127func nx_two_product_err(a: f64, b: f64) -> f64 {
151func nx_kahan_add(st: *KahanState, x: f64) -> i64 {
called by 1: nx_compensated_dot
169func nx_compensated_dot(x: *f64, y: *f64, n: i64) -> f64 {