changeset 9370:4e720cd88140

Don't rely on excess precision: -4 > -3.00000024 - 1 can evaluate to false if the CPU rounds correctly to nearest.
author Bruno Haible <bruno@clisp.org>
date Sat, 20 Oct 2007 14:34:54 +0200
parents 9dcad82b43bb
children 8b3c48038257
files ChangeLog tests/test-ceilf2.c tests/test-floorf2.c tests/test-trunc2.c tests/test-truncf2.c
diffstat 5 files changed, 15 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2007-10-20  Bruno Haible  <bruno@clisp.org>
+
+	* tests/test-floorf2.c (correct_result_p): Don't rely on excess
+	precision in the comparison result > x - 1 or similar.
+	* tests/test-ceilf2.c (correct_result_p): Likewise.
+	* tests/test-truncf2.c (correct_result_p): Likewise.
+	* tests/test-trunc2.c (correct_result_p): Likewise.
+	Reported by Ralf Wildenhues <Ralf.Wildenhues@gmx.de>.
+
 2007-10-20  Bruno Haible  <bruno@clisp.org>
 
 	* modules/ceil: New file.
--- a/tests/test-ceilf2.c
+++ b/tests/test-ceilf2.c
@@ -112,7 +112,7 @@
 {
   return
     (x > 0 && x <= 1 ? result == L_(1.0) :
-     x + 1 > x ? result >= x && result < x + 1 :
+     x + 1 > x ? result >= x && result <= x + 1 && result - x < 1 :
      equal (result, x));
 }
 
--- a/tests/test-floorf2.c
+++ b/tests/test-floorf2.c
@@ -112,7 +112,7 @@
 {
   return
     (x < 0 && x >= -1 ? result == - L_(1.0) :
-     x - 1 < x ? result <= x && result > x - 1 :
+     x - 1 < x ? result <= x && result >= x - 1 && x - result < 1 :
      equal (result, x));
 }
 
--- a/tests/test-trunc2.c
+++ b/tests/test-trunc2.c
@@ -113,10 +113,10 @@
   return
     (x >= 0
      ? (x < 1 ? result == L_(0.0) :
-	x - 1 < x ? result <= x && result > x - 1 :
+	x - 1 < x ? result <= x && result >= x - 1 && x - result < 1 :
 	equal (result, x))
      : (x > -1 ? result == L_(0.0) :
-	x + 1 > x ? result >= x && result < x + 1 :
+	x + 1 > x ? result >= x && result <= x + 1 && result - x < 1 :
 	equal (result, x)));
 }
 
--- a/tests/test-truncf2.c
+++ b/tests/test-truncf2.c
@@ -113,10 +113,10 @@
   return
     (x >= 0
      ? (x < 1 ? result == L_(0.0) :
-	x - 1 < x ? result <= x && result > x - 1 :
+	x - 1 < x ? result <= x && result >= x - 1 && x - result < 1 :
 	equal (result, x))
      : (x > -1 ? result == L_(0.0) :
-	x + 1 > x ? result >= x && result < x + 1 :
+	x + 1 > x ? result >= x && result <= x + 1 && result - x < 1 :
 	equal (result, x)));
 }