From e9101693adb3c251ee277242ef4af7aa570193b6 Mon Sep 17 00:00:00 2001 From: Eric Blake Date: Fri, 5 Nov 2010 08:03:34 -0600 Subject: [PATCH] copysign: enhance tests * modules/copysign-tests (Files): Add minus-zero.h. * tests/test-copysign.c (main): Also test zeros. Signed-off-by: Eric Blake --- ChangeLog | 6 ++++++ modules/copysign-tests | 1 + tests/test-copysign.c | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 58 insertions(+) diff --git a/ChangeLog b/ChangeLog index ea1a01f5e..7af53b8c2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2010-11-05 Eric Blake + + copysign: enhance tests + * modules/copysign-tests (Files): Add minus-zero.h. + * tests/test-copysign.c (main): Also test zeros. + 2010-11-04 Eric Blake ceil, floor, round, trunc: enhance tests of -0 diff --git a/modules/copysign-tests b/modules/copysign-tests index 44f1d8106..5a07220eb 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 60bda2fe8..3c75e126e 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 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; } -- 2.11.0