nx_math_basics.nx
buildroot/runtime/nx_math_basics.nx
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
imports: nx_types.nxnx_tier.nx
imported by: nx_math_basics_test.nx
structs
| none |
consts
| none |
functions
| 48 | func nx_iabs(x: nx_int) -> nx_int called by 1: main |
| 54 | func nx_imin(a: nx_int, b: nx_int) -> nx_int called by 1: main |
| 60 | func nx_imax(a: nx_int, b: nx_int) -> nx_int called by 1: main |
| 68 | func nx_iclamp(x: nx_int, lo: nx_int, hi: nx_int) -> nx_int called by 1: main |
| 75 | func nx_isign(x: nx_int) -> nx_int called by 1: main |
| 83 | func nx_ibool(b: nx_int) -> nx_int called by 1: main |
| 91 | func nx_iand(a: nx_int, b: nx_int) -> nx_int called by 1: main |
| 97 | func nx_ior(a: nx_int, b: nx_int) -> nx_int called by 1: main |
| 103 | func nx_inot(a: nx_int) -> nx_int called by 1: main |