ref: 7ed35649bb5b7ce79c7a01f1b1d8cb850b8d388a
parent: 8703e529a235c8315b6a25d5242a134456da0209
author: Ori Bernstein <ori@eigenstate.org>
date: Fri Mar 30 20:52:50 EDT 2018
Fix tests on 9front. The floating point on 9front is strict compared to the environment on other systems. It does not allow for NaN, which makes testing for NaN behavior crashy. We should eventually verify that we generate FPEs on 9front when we generate a nan, but for now, it's simpler just to skip those tests.
--- a/lib/std/test/fltbits.myr
+++ b/lib/std/test/fltbits.myr
@@ -1,8 +1,18 @@
use std
-
use testr
+var testnan
+
const main = {
+ var si
+
+ /* Floating point mode traps on 9front. */
+ std.getsysinfo(&si)
+ match si.system
+ | "Plan9": testnan = false
+ | _: testnan = true
+ ;;
+
testr.run([
[.name = "isnan", .fn = isnan01],
[.name = "bits-roundtrip-32", .fn = bitsround32],
@@ -13,24 +23,26 @@
}
const isnan01 = {c
- testr.check(c, std.isnan(std.flt64nan()), "std.flt64nan() should give a NaN")
- testr.check(c, std.isnan(std.flt32nan()), "std.flt32nan() should give a NaN")
-
- /*
- a NaN should be {any sign bit}, then {8 or 11 exponent
- bits, all 1}, then {any non-zero sequence of 23 or 52
- bits}
- */
- testr.check(c, std.isnan(std.flt64frombits(0xfff0000500000000ul)), "0xfff0000500000000 should be a NaN")
- testr.check(c, std.isnan(std.flt64frombits(0x7ff0000500000000ul)), "0x7ff0000500000000 should be a NaN")
- testr.check(c, std.isnan(std.flt32frombits(0xff800090)), "0xff800090 should be a NaN")
- testr.check(c, std.isnan(std.flt32frombits(0x7f800090)), "0x7f800090 should be a NaN")
-
- /* if the significand bits are all 0, it's an infinity instead */
- testr.check(c, !std.isnan(std.flt64frombits(0x7ff0000000000000ul)), "Infinities[1] should not be NaNs")
- testr.check(c, !std.isnan(std.flt64frombits(0xfff0000000000000ul)), "Infinities[2] should not be NaNs")
- testr.check(c, !std.isnan(std.flt32frombits(0xff800000)), "Infinities[3] should not be NaNs")
- testr.check(c, !std.isnan(std.flt32frombits(0x7f800000)), "Infinities[4] should not be NaNs")
+ if testnan
+ testr.check(c, std.isnan(std.flt64nan()), "std.flt64nan() should give a NaN")
+ testr.check(c, std.isnan(std.flt32nan()), "std.flt32nan() should give a NaN")
+
+ /*
+ a NaN should be {any sign bit}, then {8 or 11 exponent
+ bits, all 1}, then {any non-zero sequence of 23 or 52
+ bits}
+ */
+ testr.check(c, std.isnan(std.flt64frombits(0xfff0000500000000ul)), "0xfff0000500000000 should be a NaN")
+ testr.check(c, std.isnan(std.flt64frombits(0x7ff0000500000000ul)), "0x7ff0000500000000 should be a NaN")
+ testr.check(c, std.isnan(std.flt32frombits(0xff800090)), "0xff800090 should be a NaN")
+ testr.check(c, std.isnan(std.flt32frombits(0x7f800090)), "0x7f800090 should be a NaN")
+
+ /* if the significand bits are all 0, it's an infinity instead */
+ testr.check(c, !std.isnan(std.flt64frombits(0x7ff0000000000000ul)), "Infinities[1] should not be NaNs")
+ testr.check(c, !std.isnan(std.flt64frombits(0xfff0000000000000ul)), "Infinities[2] should not be NaNs")
+ testr.check(c, !std.isnan(std.flt32frombits(0xff800000)), "Infinities[3] should not be NaNs")
+ testr.check(c, !std.isnan(std.flt32frombits(0x7f800000)), "Infinities[4] should not be NaNs")
+ ;;
}
const bitsround32 = {c
@@ -44,9 +56,11 @@
testr.check(c, u == v, "bits -> flt -> bits non-identity: {} != {}", u, v)
;;
- var nan_f = std.flt32frombits(0xff800090)
- var nan_g = std.flt32frombits(std.flt32bits(nan_f))
- testr.check(c, nan_f == nan_g, "flt -> bits -> flt non-identity for nan")
+ if testnan
+ var nan_f = std.flt32frombits(0xff800090)
+ var nan_g = std.flt32frombits(std.flt32bits(nan_f))
+ testr.check(c, nan_f == nan_g, "flt -> bits -> flt non-identity for nan")
+ ;;
var inf_f = std.flt32frombits(0x7f800000)
var inf_g = std.flt32frombits(std.flt32bits(inf_f))
@@ -64,9 +78,11 @@
testr.check(c, u == v, "bits -> flt -> bits non-identity: {} != {}", u, v)
;;
- var nan_f = std.flt64frombits(0x7ff000000000a000ul)
- var nan_g = std.flt64frombits(std.flt64bits(nan_f))
- testr.check(c, nan_f == nan_g, "flt -> bits -> flt non-identity for nan")
+ if testnan
+ var nan_f = std.flt64frombits(0x7ff000000000a000ul)
+ var nan_g = std.flt64frombits(std.flt64bits(nan_f))
+ testr.check(c, nan_f == nan_g, "flt -> bits -> flt non-identity for nan")
+ ;;
var inf_f = std.flt64frombits(0xfff0000000000000ul)
var inf_g = std.flt64frombits(std.flt64bits(inf_f))