code wiki / _hdl_build / nx_rational.nx
nx_rational.nx
buildroot/runtime/_hdl_build/nx_rational.nx
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
imports: nx_syscalls.nx
imported by: _rational_gate.nxnx_swcompare_bench.nx
structs
| none |
consts
| none |
functions
| 14 | func rat_new() -> *i64 { let r: *i64 = sys_mmap(16) as *i64; r[0] = 0; r[1] = 1; return r } |
| 17 | func rat_gcd(a: i64, b: i64) -> i64 |
| 27 | func rat_norm(r: *i64) -> i64 |
| 38 | func rat_set(r: *i64, num: i64, den: i64) -> i64 { r[0] = num; r[1] = den; rat_norm(r); return 0 } |
| 41 | func rat_add(out: *i64, a: *i64, b: *i64) -> i64 |
| 50 | func rat_mul(out: *i64, a: *i64, b: *i64) -> i64 |
| 59 | func rat_eq(a: *i64, b: *i64) -> i64 |