code wiki / _hdl_build / nx_js_f64lit_probe.nx

nx_js_f64lit_probe.nx source

↩ module page · 14 lines · 1147 B

1// check 0.1 parses to the correctly-rounded IEEE bits. expect_exit: 0 license_tier: ORIGINAL 2import "nx_js_vm.nx" 3const K_MAGIC_4591870180066957722: i64 = 4591870180066957722 4func w(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 } 5func nn(v: i64) -> i64 { if v==0 { sys_write(1,"0" as *u8,1); return 0 } var m: i64=v; if m<0 { sys_write(1,"-" as *u8,1); m=0-m } let t: *u8=sys_mmap(24); var k: i64=0; while m>0 { t[k]=(48+(m%10)) as u8; m=m/10; k=k+1 } let o: *u8=sys_mmap(24); var q: i64=k-1; var x: i64=0; while q>=0 { o[x]=t[q]; x=x+1; q=q-1 } sys_write(1,o,x); return 0 } 6func main(argc: i64, argv: *i64) -> i64 { 7 let o: *i64 = sys_mmap(16) as *i64 8 compile_run("0.1" as *u8, o) 9 w("our 0.1 bits = "); nn(o[1]); w("\n" as *u8) 10 w("IEEE correct = 4591870180066957722\n" as *u8) 11 if o[1] == K_MAGIC_4591870180066957722 { w("MATCH (correctly rounded)\n" as *u8) } else { w("DIVERGE (jparse_f64 not correctly rounded -> NavierStokes drift)\n" as *u8) } 12 compile_run("0.5" as *u8, o); w("our 0.5 bits = "); nn(o[1]); w(" (IEEE=4602678819172646912)\n" as *u8) 13 return 0 14}