code wiki / (root) / nx_f32_sincos.nx

nx_f32_sincos.nx

buildroot/runtime/nx_f32_sincos.nx

7332 B191 linesdepth 4pulls 5 transitivereach 92 importersview sourcekind librarytopic f32
docsdependenciesstructsconstsfunctions

about

nx_f32_sincos.nx -- IEEE 754 binary32 sin(x) + cos(x) bits-up. L6 transcendentals. Composes L4 mul/add/sub/cvt. No libm. Algorithm (clean-room from cited refs): 1. Range reduction: k = round(x * 2/pi) r = x - k * pi/2, r in [-pi/4, pi/4] Quadrant q = k mod 4. 2. Reduced-range polynomials (Taylor, 4 odd / 4 even terms): sin(r) ~= r - r^3/6 + r^5/120 - r^7/5040 ~= r * (1 - r^2/6 + r^4/120 - r^6/5040) cos(r) ~= 1 - r^2/2 + r^4/24 - r^6/720 3. Quadrant dispatch: sin: q=0 -> sin(r) ; q=1 -> cos(r) ; q=2 -> -sin(r) ; q=3 -> -cos(r) cos: q=0 -> cos(r) ; q=1 -> -sin(r) ; q=2 -> -cos(r) ; q=3 -> sin(r) References absorbed clean-room: Hart 1968, Cody+Waite 1980, Muller 2016 Standard quadrant-based range-reduction canon v1 accuracy: ~1000-10000 ULPs (Taylor truncation + range reduction loss; classic single-word pi/2 issue). Adequate for ML positional encoding (RoPE). v2 Remez minimax + Cody-Waite split pi/2 for tighter bounds queued. genealogy_id: standard_quadrant_reduction + taylor_horner_canon lineage_id: substrate_f32_sincos_v1_taylor4

dependencies 4 imports · 9 importers

nx_syscalls.nx nx_tier.nx nx_f32.nx nx_f32_cvt.nx nx_f32_sincos.nx nx_autograd_tensor.nx nx_f32_rope.nx nx_f32_rope_test.nx nx_f32_sincos_test.nx nx_trig_kat.nx nx_tts_formant.nx nx_tts_seq.nx nx_tts_speak.nx nx_tts_word.nx

imports: nx_syscalls.nxnx_tier.nxnx_f32.nxnx_f32_cvt.nx

imported by: nx_autograd_tensor.nxnx_f32_rope.nxnx_f32_rope_test.nxnx_f32_sincos_test.nxnx_trig_kat.nxnx_tts_formant.nxnx_tts_seq.nxnx_tts_speak.nxnx_tts_word.nx

structs

none

consts

37const NX_MAGIC_4294967295: i64 = 4294967295
40const NX_F32_SC_ONE: i64 = 0x3F800000 // 1.0
41const NX_F32_SC_PI_2: i64 = 0x3FC90FDB // pi/2 = 1.5707963
42const NX_F32_SC_2_PI: i64 = 0x3F22F983 // 2/pi = 0.6366198
43const NX_F32_SC_INV_6: i64 = 0x3E2AAAAB // 1/6
44const NX_F32_SC_INV_120: i64 = 0x3C088889 // 1/120
45const NX_F32_SC_INV_5040: i64 = 0x39500D01 // 1/5040
46const NX_F32_SC_INV_2: i64 = 0x3F000000 // 1/2
47const NX_F32_SC_INV_24: i64 = 0x3D2AAAAB // 1/24
48const NX_F32_SC_INV_720: i64 = 0x3AB60B61 // 1/720

functions

53func _sc_f32_to_i32_rne(value: i64) -> i64
91func _sc_sin_poly(r: i64) -> i64
114func _sc_cos_poly(r: i64) -> i64
132func _sc_range_reduce(x: i64, out_r: *i64) -> i64
147func _sc_range_reduce_pk(x: i64) -> i64
159func nx_f32_sin(x: i64) -> i64
177func nx_f32_cos(x: i64) -> i64