code wiki / (root) / nx_cast_projection_gate_t234.nx

nx_cast_projection_gate_t234.nx source

↩ module page · 34 lines · 2194 B

1import "nx_shader_ir.nx" 2import "nx_gate_verdict.nx" 3import "nx_cast_projection_contract_t234.nx" 4func cpg_eq(a:*u8,b:*u8)->i64{if (a as i64)<=0{return 0};var i:i64=0;while a[i]!=0 as u8{if a[i]!=b[i]{return 0};i=i+1};if b[i]!=0 as u8{return 0};return 1} 5func main()->i64{ 6 let c:*i64=gv_ctr() 7 csp_configure(80,300000,81,1000) 8 gv_check("current projection admitted",csp_valid(80,300000,81,1000)==1,c) 9 gv_check("positive near required",csp_configure(0,300000,81,1000)==0,c) 10 gv_check("ordered far required",csp_configure(80,80,81,1000)==0,c) 11 gv_check("guard covers near",csp_configure(80,300000,79,1000)==0,c) 12 gv_check("guard below far",csp_configure(80,300000,300000,1000)==0,c) 13 gv_check("decimal scale required",csp_configure(80,300000,81,3)==0,c) 14 gv_check("zero scale refused",csp_configure(80,300000,81,0)==0,c) 15 gv_check("arithmetic overflow refused",csp_configure(2,9223372036854775807,3,1000)==0,c) 16 gv_check("failed config invalidates emission",csp_scale==0&&(csp_literal(1) as i64)==0,c) 17 gv_check("explicit valid configuration restores emission",csp_configure(80,300000,81,1000)==1,c) 18 gv_check("guard literal parity",cpg_eq(csp_literal(0),"0.081")==1,c) 19 gv_check("sum literal parity",cpg_eq(csp_literal(1),"300.08")==1,c) 20 gv_check("difference literal parity",cpg_eq(csp_literal(2),"299.92")==1,c) 21 gv_check("product literal parity",cpg_eq(csp_literal(3),"48.0")==1,c) 22 gv_check("derived outward nearQ8",csp_near_q8()==21,c) 23 let out:*u8=sys_mmap(1024) 24 gv_check("short metadata destination refused",csp_record(out,1)==0-2,c) 25 gv_check("metadata emitted",csp_record(out,1024)>0,c) 26 gv_check("alternate input accepted",csp_configure(125,10000,126,1000)==1,c) 27 gv_check("alternate nearQ8 not fixed21",csp_near_q8()==32,c) 28 gv_check("alternate sum updates IR literal",cpg_eq(csp_literal(1),"10.125")==1,c) 29 gv_check("alternate product updates IR literal",cpg_eq(csp_literal(3),"2.5")==1,c) 30 csp_near=0 31 gv_check("invalid internal metadata refused",csp_record(out,1024)==0-1,c) 32 gv_check("invalid internal literal refused",(csp_literal(1) as i64)==0,c) 33 return gv_verdict("CAST-PROJECTION-CONTRACT",c,"rational projection inputs shared by shader literals and capture metadata") 34}