nx_fx_f64_nan.nx source
↩ module page · 23 lines · 1302 B
1// nx_fx_f64_nan.nx -- LN38 fixture: IEEE-754 unordered compares. Every ordered predicate on a NaN operand is
2// FALSE and != is TRUE; ordinary ordered compares keep their answers. Exit 0 iff every check holds, else a
3// bitmask naming the failing checks (bit k = check k). license_tier: ORIGINAL
4import "nx_syscalls.nx"
5func fx_nan(z: f64) -> f64 { return z / z }
6func fx_id(x: f64) -> f64 { return x }
7func main() -> i64 {
8 let z: f64 = fx_id(0.0)
9 let n: f64 = fx_nan(z)
10 let one: f64 = fx_id(1.0)
11 var bad: i64 = 0
12 if n != n { } else { bad = bad + 1 } // check 0: NaN != NaN must be TRUE
13 if n == n { bad = bad + 2 } // check 1: NaN == NaN must be FALSE
14 if n < one { bad = bad + 4 } // check 2
15 if n > one { bad = bad + 8 } // check 3
16 if one < n { bad = bad + 16 } // check 4: NaN as op1
17 if one >= n { bad = bad + 32 } // check 5
18 if n <= n { bad = bad + 64 } // check 6
19 if one < 2.0 { } else { bad = bad + 128 } // check 7: ordered control stays TRUE
20 if (0.0 - one) < (0.0 - 2.0) { bad = bad + 256 } // check 8: ordered negative control stays FALSE
21 if one == one { } else { bad = bad + 512 } // check 9: equality control stays TRUE
22 return bad
23}