Mercurial > hg > octave-nkf > gnulib-hg
changeset 13836:2ba13be8e841
copysign: enhance tests
* modules/copysign-tests (Files): Add minus-zero.h.
* tests/test-copysign.c (main): Also test zeros.
Signed-off-by: Eric Blake <eblake@redhat.com>
author | Eric Blake <eblake@redhat.com> |
---|---|
date | Fri, 05 Nov 2010 08:03:34 -0600 |
parents | ed864b3ac8ec |
children | d7a891a411c1 |
files | ChangeLog modules/copysign-tests tests/test-copysign.c |
diffstat | 3 files changed, 58 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- 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
--- 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:
--- 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 @@ 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; }