code wiki / (root) / nx_math_basics.nx

nx_math_basics.nx

buildroot/runtime/nx_math_basics.nx

3482 B106 linesdepth 1pulls 2 transitivereach 1 importersview sourcekind librarytopic math
docsdependenciesstructsconstsfunctions

about

nx_math_basics.nx -- canonical shared integer-math basics. license_tier: ORIGINAL Centralizes a handful of one-line helpers that the substrate had duplicated across many files (see `bench/sprawl_scan.sh`). Each helper here is the SINGLE source of truth for that operation. Migration path for existing files: replace local `iabs` / `imin` / `imax` / `iclamp` with these `nx_*` variants and import this file. Discipline: per cardinal DRY-through-shared-libraries, a pattern appearing in 3+ files belongs in shared/. This file is that for the integer-math family. Today's sprawl signal: iabs defined in 29 files (largest cluster) imin defined in 7+ imax defined in 5+ These should all collapse to imports from this file. Per the cardinal scale-agnostic-tier-locks, types use the nx_int alias so swapping i64 -> i128 retargets the whole substrate. nx_safety_envelope: intended_use: "Foundational integer math primitives (abs, min, max, clamp, sign, lerp) -- shared substrate math foundation" sil_target: SIL2 asil_target: QM dal_target: DAL B evidence: [no_FP_no_division_pure_integer, sealed_enum_for_verdict_paths, target_independent_implementation] hazard_register: [bug-tape-i64-overflow-on-abs-of-min-value, bug-tape-min-max-NaN-confusion-via-FP-mix] residual_risk: "abs(INT64_MIN) overflows by design; substrate documents this in function comments; callers requiring saturation use the _sat_ variants." verdict: NOT_YET_EVALUATED

dependencies 2 imports · 1 importers

nx_types.nx nx_tier.nx nx_math_basics.nx nx_math_basics_test.nx

imports: nx_types.nxnx_tier.nx

imported by: nx_math_basics_test.nx

structs

none

consts

none

functions

48func nx_iabs(x: nx_int) -> nx_int
called by 1: main
54func nx_imin(a: nx_int, b: nx_int) -> nx_int
called by 1: main
60func nx_imax(a: nx_int, b: nx_int) -> nx_int
called by 1: main
68func nx_iclamp(x: nx_int, lo: nx_int, hi: nx_int) -> nx_int
called by 1: main
75func nx_isign(x: nx_int) -> nx_int
called by 1: main
83func nx_ibool(b: nx_int) -> nx_int
called by 1: main
91func nx_iand(a: nx_int, b: nx_int) -> nx_int
called by 1: main
97func nx_ior(a: nx_int, b: nx_int) -> nx_int
called by 1: main
103func nx_inot(a: nx_int) -> nx_int
called by 1: main