summaryrefslogtreecommitdiff
path: root/lib/std/test
diff options
context:
space:
mode:
authorS. Gilles <sgilles@math.umd.edu>2018-04-18 08:30:41 -0400
committerS. Gilles <sgilles@math.umd.edu>2018-04-18 08:30:41 -0400
commit9aabbe574e648e0a462b211c62da5eb5875343b7 (patch)
tree9ac90949a12806359fd4b996029757c84ef6e2a6 /lib/std/test
parent4acd9ee51a541f94e81457b1a7fb3accbd790696 (diff)
parent3d71446ecb6569add0d9eaf2e7e4a05d99bd2625 (diff)
downloadmc-9aabbe574e648e0a462b211c62da5eb5875343b7.tar.gz
Merge remote-tracking branch 'ori/master' into HEAD
Diffstat (limited to 'lib/std/test')
-rw-r--r--lib/std/test/fltbits.myr66
1 files changed, 41 insertions, 25 deletions
diff --git a/lib/std/test/fltbits.myr b/lib/std/test/fltbits.myr
index 3907a0f..6493231 100644
--- 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],
@@ -15,24 +25,26 @@ const main = {
}
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
@@ -46,9 +58,11 @@ const bitsround32 = {c
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))
@@ -66,9 +80,11 @@ const bitsround64 = {c
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))