ref: 2652cf20199949dd23fc3e2d3327dd3f9e9be2ba
parent: 7f8782b1ccbf724f44b4e86bc2fef9c6d309d564
author: Ori Bernstein <ori@eigenstate.org>
date: Sun Dec 25 17:59:28 EST 2016
Add isnan() function.
--- a/lib/std/fltbits.myr
+++ b/lib/std/fltbits.myr
@@ -6,6 +6,7 @@
const flt32inf : (-> flt32)
const flt32nan : (-> flt32)
+ generic isnan : (f : @a::floating -> bool)
const flt64frombits : (bits : uint64 -> flt64)
const flt32frombits : (bits : uint32 -> flt32)
const flt64explode : (flt : flt64 -> (bool, int64, int64))
@@ -83,6 +84,15 @@
-> std.flt32frombits(s << 31 | e << 22 | m)
}
+
+generic isnan = {f
+ var b
+
+ b = flt64bits((f : flt64))
+ -> (b >> 52) & 0x7ffl == 0x7ffl && \
+ b & ~(0x7ffl) != 0
+}
+
const flt64inf = {
-> std.flt64frombits(0x7ff0000000000000ul)
}
--- /dev/null
+++ b/lib/std/test/fltbits.myr
@@ -1,0 +1,5 @@
+use std
+
+const main = {
+ std.assert(std.isnan(0./0.), "isnan(0/0) false\n")
+}