[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH] copysign: enhance tests
From: |
Eric Blake |
Subject: |
[PATCH] copysign: enhance tests |
Date: |
Fri, 5 Nov 2010 08:20:11 -0600 |
* modules/copysign-tests (Files): Add minus-zero.h.
* tests/test-copysign.c (main): Also test zeros.
Signed-off-by: Eric Blake <address@hidden>
---
I was about to fix strtod to use copysign to work around the icc
bug; the first step is to strengthen the test to prove that it
will work with icc. I've tested that this still works with icc,
and also in Irix with SGI's cc.
Unfortunately, I then realized that copysign still requires -lm,
which is exactly what we don't want to drag in to strtod, so
we'd need a copysign-nolibm module. :(
ChangeLog | 6 +++++
modules/copysign-tests | 1 +
tests/test-copysign.c | 51 ++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 58 insertions(+), 0 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index ea1a01f..7af53b8 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2010-11-05 Eric Blake <address@hidden>
+
+ copysign: enhance tests
+ * modules/copysign-tests (Files): Add minus-zero.h.
+ * tests/test-copysign.c (main): Also test zeros.
+
2010-11-04 Eric Blake <address@hidden>
ceil, floor, round, trunc: enhance tests of -0
diff --git a/modules/copysign-tests b/modules/copysign-tests
index 44f1d81..5a07220 100644
--- a/modules/copysign-tests
+++ b/modules/copysign-tests
@@ -1,6 +1,7 @@
Files:
tests/test-copysign.c
tests/signature.h
+tests/minus-zero.h
tests/macros.h
Depends-on:
diff --git a/tests/test-copysign.c b/tests/test-copysign.c
index 60bda2f..3bd44d2 100644
--- a/tests/test-copysign.c
+++ b/tests/test-copysign.c
@@ -24,10 +24,14 @@
SIGNATURE_CHECK (copysign, double, (double, double));
#include "macros.h"
+#include "minus-zero.h"
+
+#include <string.h>
volatile double x;
volatile double y;
double z;
+double zero = 0.0;
int
main ()
@@ -56,5 +60,52 @@ main ()
z = copysign (x, y);
ASSERT (z == -0.6);
+ /* From signed zero. */
+ x = 1.0;
+ y = 0.0;
+ z = copysign (x, y);
+ ASSERT (z == 1.0);
+
+ x = 1.0;
+ y = minus_zerod;
+ z = copysign (x, y);
+ /* Assume all gnulib targets support -0.0, until proven otherwise. */
+ ASSERT (z == -1.0);
+
+ x = -1.0;
+ y = 0.0;
+ z = copysign (x, y);
+ ASSERT (z == 1.0);
+
+ x = -1.0;
+ y = minus_zerod;
+ z = copysign (x, y);
+ ASSERT (z == -1.0);
+
+ /* To signed zero. */
+ x = 0.0;
+ y = 1.0;
+ z = copysign (x, y);
+ ASSERT (z == 0.0);
+ ASSERT (memcmp (&zero, &z, sizeof z) == 0);
+
+ x = 0.0;
+ y = -1.0;
+ z = copysign (x, y);
+ ASSERT (z == 0.0);
+ ASSERT (memcmp (&zero, &z, sizeof z) != 0);
+
+ x = minus_zerod;
+ y = 1.0;
+ z = copysign (x, y);
+ ASSERT (z == 0.0);
+ ASSERT (memcmp (&zero, &z, sizeof z) == 0);
+
+ x = minus_zerod;
+ y = -1.0;
+ z = copysign (x, y);
+ ASSERT (z == 0.0);
+ ASSERT (memcmp (&zero, &z, sizeof z) != 0);
+
return 0;
}
--
1.7.3.2
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [PATCH] copysign: enhance tests,
Eric Blake <=