shithub: mc

Download patch

ref: 373facebac71ac1e6743d30152543627ad115cf7
parent: 96cb72770eb9c9bf3259ebb4647ef88092438808
author: S. Gilles <sgilles@math.umd.edu>
date: Sun Mar 11 20:05:09 EDT 2018

Implement std.eq for floats

--- a/lib/math/fpmath.myr
+++ b/lib/math/fpmath.myr
@@ -12,8 +12,26 @@
 //		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 =
--- a/lib/math/test/fpmath-sum-impl.myr
+++ b/lib/math/test/fpmath-sum-impl.myr
@@ -14,14 +14,6 @@
 	][:])
 }
 
-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),
--- a/lib/math/test/fpmath-trunc-impl.myr
+++ b/lib/math/test/fpmath-trunc-impl.myr
@@ -13,14 +13,6 @@
 	][:])
 }
 
-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),