copysign: enhance tests
authorEric Blake <eblake@redhat.com>
Fri, 5 Nov 2010 14:03:34 +0000 (08:03 -0600)
committerEric Blake <eblake@redhat.com>
Fri, 5 Nov 2010 14:20:39 +0000 (08:20 -0600)
* modules/copysign-tests (Files): Add minus-zero.h.
* tests/test-copysign.c (main): Also test zeros.

Signed-off-by: Eric Blake <eblake@redhat.com>
ChangeLog
modules/copysign-tests
tests/test-copysign.c

index ea1a01f..7af53b8 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2010-11-05  Eric Blake  <eblake@redhat.com>
+
+       copysign: enhance tests
+       * modules/copysign-tests (Files): Add minus-zero.h.
+       * tests/test-copysign.c (main): Also test zeros.
+
 2010-11-04  Eric Blake  <eblake@redhat.com>
 
        ceil, floor, round, trunc: enhance tests of -0
index 44f1d81..5a07220 100644 (file)
@@ -1,6 +1,7 @@
 Files:
 tests/test-copysign.c
 tests/signature.h
+tests/minus-zero.h
 tests/macros.h
 
 Depends-on:
index 60bda2f..3c75e12 100644 (file)
 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 (&z, &zero, sizeof z) == 0);
+
+  x = 0.0;
+  y = -1.0;
+  z = copysign (x, y);
+  ASSERT (z == 0.0);
+  ASSERT (memcmp (&z, &zero, sizeof z) != 0);
+
+  x = minus_zerod;
+  y = 1.0;
+  z = copysign (x, y);
+  ASSERT (z == 0.0);
+  ASSERT (memcmp (&z, &zero, sizeof z) == 0);
+
+  x = minus_zerod;
+  y = -1.0;
+  z = copysign (x, y);
+  ASSERT (z == 0.0);
+  ASSERT (memcmp (&z, &zero, sizeof z) != 0);
+
   return 0;
 }