code wiki / (root) / nx_icbrt.nx

nx_icbrt.nx

buildroot/runtime/nx_icbrt.nx

3794 B98 linesdepth 2pulls 2 transitivereach 44 importersview sourcekind library
docsdependenciesstructsconstsfunctions

about

nx_icbrt.nx -- bits-up integer cube root + Q14 fixed-point wrapper. Returns floor(cube_root(n)) for n >= 0; 0 for n < 0. Algorithm: bit-by-bit, analogous to nx_isqrt. Iterate from the highest possible bit of the cube root down; at each bit, try setting it and check whether candidate^3 still fits within n. Why this exists (substrate-level motivation, 2026-05-19): Q14 fixed-point cube root is needed for unit-exact bending mechanics in nx_pillar_physics v2.1 (the EXCEED axis vs Orca/Bambu/Cura/Prusa which use constant pillar diameter regardless of load). Square pillar bending stress: σ = M × (s/2) / I where I = s⁴/12 yields the textbook formula s = ∛(6M / σ_yield). No production slicer implements this; no academic system implements it at slice-time. Cube root has uses beyond pillar sizing -- volumetric flow at the extruder (radius scales as cbrt of flow per area), surface-area / volume ratios for cooling models, etc. Ships as a general bits-up math primitive that any future arc can compose. Overflow safety: for i64 inputs the cube root fits in 22 bits (since cube_root(2^63) ≈ 2.1e21 < 2^22 = 4.2e21). At candidate ≈ 2^21, candidate^2 ≈ 2^42 and the test candidate^3 ≤ n is rewritten as candidate^2 ≤ n / candidate to keep all intermediates in i64. license_tier: ORIGINAL

dependencies 2 imports · 2 importers

nx_syscalls.nx nx_tier.nx nx_icbrt.nx nx_icbrt_test.nx nx_pillar_physics.nx

imports: nx_syscalls.nxnx_tier.nx

imported by: nx_icbrt_test.nxnx_pillar_physics.nx

structs

none

consts

32const NX_ICBRT_TOP_BIT: i64 = 21
37const NX_ICBRT_Q14_SHIFT: i64 = 268435456
43const NX_ICBRT_Q14_LIMIT: i64 = 34359738367

functions

56func nx_icbrt(n: nx_int) -> nx_int
called by 2: nx_icbrt_q14main
92func nx_icbrt_q14(x_q14: nx_int) -> nx_int