code wiki / _hdl_build / nx_viz_trig_gate.nx

nx_viz_trig_gate.nx source

↩ module page · 61 lines · 2739 B

1// nx_viz_trig_gate.nx -- REFEREE for the trig layer (integer sin/cos, scale 10000). 2// T1 sin KAT (exact): sin(0)=0 sin(30)=5000 sin(90)=10000 sin(150)=5000 sin(180)=0 sin(270)=-10000 3// T2 cos KAT (exact): cos(0)=10000 cos(90)=0 cos(180)=-10000 4// T3 sin(45) in tolerance [6900,7200] (Bhaskara ~ 7059 vs true 7071) 5// T4 Pythagorean identity sin^2+cos^2 ~= 10000^2 (within 1%) at 45 and 60 -- internal consistency 6// GREEN iff T1..T4. Sovereign: nx_viz_trig + nx_syscalls. license_tier: ORIGINAL 7import "nx_viz_trig.nx" 8import "nx_syscalls.nx" 9import "nx_gate_verdict.nx" 10 11func g_w(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 } 12func g_row(name: *u8, ok: i64) -> i64 { 13 if ok == 1 { g_w(" PASS " as *u8) } 14 if ok != 1 { g_w(" FAIL " as *u8) } 15 g_w(name); g_w("\n" as *u8) 16 return ok 17} 18func pyth_ok(deg: i64) -> i64 { 19 let s: i64 = vs_sin(deg) 20 let c: i64 = vs_cos(deg) 21 var diff: i64 = s * s + c * c - 100000000 22 if diff < 0 { diff = 0 - diff } 23 if diff < 1000000 { return 1 } 24 return 0 25} 26 27func main() -> i64 { 28 g_w("viz-trig gate (integer sin/cos, Bhaskara, scale 10000)\n" as *u8) 29 var pass: i64 = 0 30 31 var t1: i64 = 0 32 if vs_sin(0) == 0 { if vs_sin(30) == 5000 { if vs_sin(90) == 10000 { if vs_sin(150) == 5000 { if vs_sin(180) == 0 { if vs_sin(270) == (0 - 10000) { t1 = 1 } } } } } } 33 pass = pass + g_row("T1 sin KAT 0/30/90/150/180/270\x00" as *u8, t1) 34 35 var t2: i64 = 0 36 if vs_cos(0) == 10000 { if vs_cos(90) == 0 { if vs_cos(180) == (0 - 10000) { t2 = 1 } } } 37 pass = pass + g_row("T2 cos KAT 0/90/180\x00" as *u8, t2) 38 39 var t3: i64 = 0 40 let s45: i64 = vs_sin(45) 41 if s45 > 6900 { if s45 < 7200 { t3 = 1 } } 42 pass = pass + g_row("T3 sin(45) in [6900,7200]\x00" as *u8, t3) 43 44 var t4: i64 = 0 45 if pyth_ok(45) == 1 { if pyth_ok(60) == 1 { t4 = 1 } } 46 pass = pass + g_row("T4 sin^2+cos^2 ~= 1 at 45 and 60\x00" as *u8, t4) 47 48 var t5: i64 = 0 49 if vs_isqrt(16) == 4 { if vs_isqrt(15) == 3 { if vs_isqrt(17) == 4 { if vs_isqrt(1000000) == 1000 { if vs_isqrt(0) == 0 { t5 = 1 } } } } } 50 pass = pass + g_row("T5 isqrt 16/15/17/1e6/0 = 4/3/4/1000/0\x00" as *u8, t5) 51 52 // MIGRATED onto nx_gate_verdict by nx_gate_dry_apply (D001, minimal form): every check 53 // row above is untouched, so the PASS/FAIL vector cannot change; only the hand-rolled 54 // verdict emission is replaced by the ONE shared base class. Proven by nx_gate_migrate verify. 55 let ctr__dry: *i64 = gv_ctr() 56 ctr__dry[0] = pass 57 ctr__dry[1] = 5 58 let rc__dry: i64 = gv_verdict("VIZ-TRIG-GATE" as *u8, ctr__dry, "5/5 (integer sin/cos + isqrt, no FPU/table)" as *u8) 59 sys_exit(rc__dry) 60 return rc__dry 61}