nx_itoa_boundary_gate_t297.nx source
↩ module page · 22 lines · 1290 B
1import "nx_itoa_lib.nx"
2import "nx_gate_verdict.nx"
3func ni_check(v:i64,expected:*u8,ctr:*i64)->i64{
4 let b:*u8=sys_mmap_try(NXI_BUF+2);if (b as i64)<=0{return 1}
5 var i:i64=0;while i<NXI_BUF+2{b[i]=165 as u8;i=i+1}
6 var len:i64=0;while expected[len]!=(0 as u8){len=len+1}
7 let end:i64=nxi_buf(b,1,v);var same:i64=1;i=0;while i<len{if b[i+1]!=expected[i]{same=0};i=i+1}
8 gv_check("shared digits exact with prefix and suffix guards",end==len+1&&same==1&&b[0]==(165 as u8)&&b[end]==(165 as u8),ctr)
9 let ze:i64=ccz_cat_num(b,1,v);same=1;i=0;while i<len{if b[i+1]!=expected[i]{same=0};i=i+1}
10 gv_check("NUL writer reuses exact digits and preserves next byte",ze==end&&same==1&&b[ze]==(0 as u8)&&b[ze+1]==(165 as u8),ctr)
11 sys_munmap_direct(b,NXI_BUF+2);return 0
12}
13func main()->i64{
14 let ctr:*i64=gv_ctr()
15 ni_check(0,"0",ctr);ni_check(1,"1",ctr);ni_check(-1,"-1",ctr)
16 ni_check(9,"9",ctr);ni_check(10,"10",ctr);ni_check(-10,"-10",ctr)
17 ni_check(1000000000000000000,"1000000000000000000",ctr)
18 ni_check(-1000000000000000000,"-1000000000000000000",ctr)
19 ni_check(9223372036854775807,"9223372036854775807",ctr)
20 ni_check(0-9223372036854775807-1,"-9223372036854775808",ctr)
21 return gv_verdict("INTEGER-FULL-SIGNED-RANGE",ctr,"Shared formatter boundary fixtures; no allocation in digit emitter")
22}