X-Git-Url: https://erislabs.net/gitweb/?a=blobdiff_plain;f=tests%2Ftest-copysign.c;h=fa6b70911e712f10ff5ad7cbcf35d7a2167c5dcc;hb=74540d44dc16bfd3546e39ae2d7262f32a4147ab;hp=60bda2fe8622466da676d0b7e0a4bf90f78ffd1c;hpb=0a659299175d19479036b4e0555a6e7300544ee2;p=gnulib.git diff --git a/tests/test-copysign.c b/tests/test-copysign.c index 60bda2fe8..fa6b70911 100644 --- a/tests/test-copysign.c +++ b/tests/test-copysign.c @@ -1,5 +1,5 @@ /* Test of copysign() function. - Copyright (C) 2010 Free Software Foundation, Inc. + Copyright (C) 2010-2013 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -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; }