nx_tier_swap_demo.nx
buildroot/runtime/nx_tier_swap_demo.nx
about
nx_tier_swap_demo.nx -- proof that nx_tier.nx swap is real.
Computes the triangular sum 1 + 2 + ... + N where N is chosen
to overflow signed 32-bit int but fit signed 64-bit.
sum(N) = N * (N+1) / 2
N = 100000 -> sum = 5,000,050,000 (~5e9)
int32 max = 2,147,483,647 (~2.1e9) -> overflows
int64 max = 9.2e18 -> fits
With nx_int = i64: prints "5000050000" and exits 0
With nx_int = i32: would wrap to a negative number and exit 1
(after editing nx_tier.nx to swap the alias).
Substrate-level proof that one edit to nx_tier.nx propagates.
dependencies 3 imports · 0 importers
imports: nx_syscalls.nxnx_runtime.nxnx_tier.nx
imported by: nobody (leaf or entry point)
call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown
structs
| none |
consts
| 26 | const K_MAGIC_100000: i64 = 100000 |
| 27 | const K_MAGIC_5000050000: i64 = 5000050000 |
| 29 | const STDOUT: i64 = 1 |
functions
| 31 | func triangular_sum(n: nx_int) -> nx_int called by 1: main |
| 41 | func main() -> i64 |