code wiki / _hdl_build / nx_rational.nx

nx_rational.nx

buildroot/runtime/_hdl_build/nx_rational.nx

2101 B62 linesdepth 2pulls 2 transitivereach 2 importersview sourcekind library
docsdependenciesstructsconstsfunctions

about

nx_rational.nx -- ME4 / WOLF-RATIONAL: EXACT rational arithmetic (the foundation of symbolic + arbitrary-precision math, where f64 has rounding error and a CAS does not). A rational is a 2-i64 block [num, den], kept gcd-NORMALIZED with den>0 (canonical, so equality is a field compare). Operations are EXACT: a/b + c/d = (ad+bc)/(bd) reduced; a/b * c/d = ac/bd reduced. (i64 limbs now; nx_bigint arbitrary-precision = the rung-2 upgrade for unbounded numerators -- the API is chosen so that swap is additive.) module: nishi-core.math.rational depends: nishi-core.sys.syscalls capability: EXACT_RATIONAL_ARITHMETIC license_tier: ORIGINAL

dependencies 1 imports · 2 importers

nx_syscalls.nx nx_rational.nx _rational_gate.nx nx_swcompare_bench.nx

imports: nx_syscalls.nx

imported by: _rational_gate.nxnx_swcompare_bench.nx

structs

none

consts

none

functions

14func rat_new() -> *i64 { let r: *i64 = sys_mmap(16) as *i64; r[0] = 0; r[1] = 1; return r }
called by 2: mainmain calls 1: sys_mmap
17func rat_gcd(a: i64, b: i64) -> i64
called by 2: rat_normmain
27func rat_norm(r: *i64) -> i64
called by 3: rat_setrat_addrat_mul calls 1: rat_gcd
38func rat_set(r: *i64, num: i64, den: i64) -> i64 { r[0] = num; r[1] = den; rat_norm(r); return 0 }
called by 2: mainmain calls 1: rat_norm
41func rat_add(out: *i64, a: *i64, b: *i64) -> i64
called by 2: mainmain calls 1: rat_norm
50func rat_mul(out: *i64, a: *i64, b: *i64) -> i64
called by 2: mainmain calls 1: rat_norm
59func rat_eq(a: *i64, b: *i64) -> i64