summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorS. Gilles <sgilles@math.umd.edu>2018-03-12 00:05:09 -0400
committerS. Gilles <sgilles@math.umd.edu>2018-03-12 23:43:42 -0400
commit373facebac71ac1e6743d30152543627ad115cf7 (patch)
treeccef3b9be9896fe76396150b261a3924ec42813f /lib
parent96cb72770eb9c9bf3259ebb4647ef88092438808 (diff)
downloadmc-373facebac71ac1e6743d30152543627ad115cf7.tar.gz
Implement std.eq for floats
Diffstat (limited to 'lib')
-rw-r--r--lib/math/fpmath.myr18
-rw-r--r--lib/math/test/fpmath-sum-impl.myr8
-rw-r--r--lib/math/test/fpmath-trunc-impl.myr8
3 files changed, 18 insertions, 16 deletions
diff --git a/lib/math/fpmath.myr b/lib/math/fpmath.myr
index bb035e3..c366750 100644
--- a/lib/math/fpmath.myr
+++ b/lib/math/fpmath.myr
@@ -12,10 +12,28 @@ pkg math =
// fast2sum : (a : @f, b : @f -> (@f, @f))
;;
+ impl std.equatable flt32
+ impl std.equatable flt64
impl fpmath flt32
impl fpmath flt64
;;
+/*
+ We consider two floating-point numbers equal if their bits are
+ equal. This does not treat NaNs specially: two distinct NaNs may
+ compare equal, or they may compare distinct (if they arise from
+ different bit patterns).
+
+ Additionally, +0.0 and -0.0 compare differently.
+ */
+impl std.equatable flt32 =
+ eq = {a : flt32, b : flt32; -> std.flt32bits(a) == std.flt32bits(b)}
+;;
+
+impl std.equatable flt64 =
+ eq = {a : flt64, b : flt64; -> std.flt64bits(a) == std.flt64bits(b)}
+;;
+
impl fpmath flt32 =
trunc = {f; -> trunc32(f)}
floor = {f; -> floor32(f)}
diff --git a/lib/math/test/fpmath-sum-impl.myr b/lib/math/test/fpmath-sum-impl.myr
index 64de516..6eb723e 100644
--- a/lib/math/test/fpmath-sum-impl.myr
+++ b/lib/math/test/fpmath-sum-impl.myr
@@ -14,14 +14,6 @@ const main = {
][:])
}
-impl std.equatable flt32 =
- eq = {a : flt32, b : flt32; -> std.flt32bits(a) == std.flt32bits(b)}
-;;
-
-impl std.equatable flt64 =
- eq = {a : flt64, b : flt64; -> std.flt64bits(a) == std.flt64bits(b)}
-;;
-
const trunc01 = {c
var flt32s : (flt32, flt32)[:] = [
(0.0, 0.0),
diff --git a/lib/math/test/fpmath-trunc-impl.myr b/lib/math/test/fpmath-trunc-impl.myr
index 7943161..23f692e 100644
--- a/lib/math/test/fpmath-trunc-impl.myr
+++ b/lib/math/test/fpmath-trunc-impl.myr
@@ -13,14 +13,6 @@ const main = {
][:])
}
-impl std.equatable flt32 =
- eq = {a : flt32, b : flt32; -> std.flt32bits(a) == std.flt32bits(b)}
-;;
-
-impl std.equatable flt64 =
- eq = {a : flt64, b : flt64; -> std.flt64bits(a) == std.flt64bits(b)}
-;;
-
const trunc01 = {c
var flt32s : (flt32, flt32)[:] = [
(0.0, 0.0),