From 0a56509612c0b43a3f05361ecfb73b8b39f8e66c Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Wed, 2 Apr 2008 03:06:02 +0200 Subject: [PATCH] Use macros NaNf, NaNd, NaNl instead of NAN. --- ChangeLog | 71 ++++++++++++++++++++++++++++++++++++++++++ lib/isnan.c | 4 +-- modules/ceilf-tests | 1 + modules/floorf-tests | 1 + modules/frexp-tests | 1 + modules/isnand-nolibm | 1 - modules/isnand-nolibm-tests | 1 + modules/isnanf-nolibm | 1 - modules/isnanf-nolibm-tests | 1 + modules/isnanl | 1 - modules/isnanl-nolibm | 1 - modules/round-tests | 1 + modules/roundf-tests | 1 + modules/snprintf-posix-tests | 2 +- modules/sprintf-posix-tests | 2 +- modules/trunc-tests | 1 + modules/truncf-tests | 1 + modules/vasnprintf-posix-tests | 2 +- modules/vasprintf-posix-tests | 2 +- modules/vsnprintf-posix-tests | 2 +- modules/vsprintf-posix-tests | 2 +- tests/nan.h | 50 +++++++++++++++++++++++++++++ tests/test-ceilf1.c | 5 +-- tests/test-floorf1.c | 5 +-- tests/test-frexp.c | 3 +- tests/test-isnand.c | 7 +++-- tests/test-isnanf.c | 9 +++--- tests/test-math.c | 5 +++ tests/test-round1.c | 3 +- tests/test-roundf1.c | 3 +- tests/test-snprintf-posix.h | 45 +++++++++++--------------- tests/test-sprintf-posix.h | 45 +++++++++++--------------- tests/test-trunc1.c | 3 +- tests/test-truncf1.c | 5 +-- tests/test-vasnprintf-posix.c | 46 ++++++++++++--------------- tests/test-vasprintf-posix.c | 46 ++++++++++++--------------- 36 files changed, 247 insertions(+), 133 deletions(-) create mode 100644 tests/nan.h diff --git a/ChangeLog b/ChangeLog index ba14306e1..9a2c288da 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,74 @@ +2008-04-01 Bruno Haible + + * tests/test-vasnprintf-posix.c: Include nan.h instead of . + (test_function): Use NaNd, NaNl instead of NAN or 0.0L/0.0L. + * modules/vasnprintf-posix-tests (Files): Add tests/nan.h. + (Depends-on): Remove math. + + * tests/test-vasprintf-posix.c: Include nan.h instead of . + (test_function): Use NaNd, NaNl instead of NAN or 0.0L/0.0L. + * modules/vasprintf-posix-tests (Files): Add tests/nan.h. + (Depends-on): Remove math. + + * tests/test-snprintf-posix.h: Include nan.h instead of . + (test_function): Use NaNd, NaNl instead of NAN or 0.0L/0.0L. + * modules/snprintf-posix-tests (Files): Add tests/nan.h. + (Depends-on): Remove math. + * modules/vsnprintf-posix-tests (Files): Add tests/nan.h. + (Depends-on): Remove math. + + * tests/test-sprintf-posix.h: Include nan.h instead of . + (test_function): Use NaNd, NaNl instead of NAN or 0.0L/0.0L. + * modules/sprintf-posix-tests (Files): Add tests/nan.h. + (Depends-on): Remove math. + * modules/vsprintf-posix-tests (Files): Add tests/nan.h. + (Depends-on): Remove math. + + * tests/test-round1.c: Include nan.h. + (main): Use NaNd instead of NAN. + * modules/round-tests (Files): Add tests/nan.h. + + * tests/test-trunc1.c: Include nan.h. + (main): Use NaNd instead of NAN. + * modules/trunc-tests (Files): Add tests/nan.h. + + * tests/test-roundf1.c: Include nan.h. + (main): Use NaNf instead of NAN. + * modules/roundf-tests (Files): Add tests/nan.h. + + * tests/test-truncf1.c: Include nan.h. + (main): Use NaNf instead of NAN. + * modules/truncf-tests (Files): Add tests/nan.h. + + * tests/test-ceilf1.c: Include nan.h. + (main): Use NaNf instead of NAN. + * modules/ceilf-tests (Files): Add tests/nan.h. + + * tests/test-floorf1.c: Include nan.h. + (main): Use NaNf instead of NAN. + * modules/floorf-tests (Files): Add tests/nan.h. + + * tests/test-isnanf.c: Include nan.h instead of . + (main): Use NaNf instead of NAN. + * modules/isnanf-nolibm-tests (Files): Add tests/nan.h. + + * tests/test-isnand.c: Include nan.h instead of . + (main): Use NaNd instead of NAN. + * modules/isnand-nolibm-tests (Files): Add tests/nan.h. + + * tests/test-frexp.c: Include nan.h. + (main): Use NaNd instead of NAN. + * modules/frexp-tests (Files): Add tests/nan.h. + + * lib/isnan.c: Don't include . + (FUNC): Don't use NAN macro. + * modules/isnand-nolibm (Depends-on): Remove math. + * modules/isnanf-nolibm (Depends-on): Remove math. + * modules/isnanl (Depends-on): Remove math. + * modules/isnanl-nolibm (Depends-on): Remove math. + + * tests/nan.h: New file. + 2008-04-01 Eric Blake Fix typos. diff --git a/lib/isnan.c b/lib/isnan.c index 81f394d16..a5ca38df4 100644 --- a/lib/isnan.c +++ b/lib/isnan.c @@ -19,7 +19,6 @@ #include #include -#include #include #include "float+.h" @@ -112,10 +111,11 @@ FUNC (DOUBLE x) also fails when constant-folding 0.0 / 0.0 even when constant-folding is not required. The SGI MIPSpro C compiler complains about "floating-point operation result is out of range". */ + static DOUBLE zero = L_(0.0); memory_double nan; DOUBLE plus_inf = L_(1.0) / L_(0.0); DOUBLE minus_inf = -L_(1.0) / L_(0.0); - nan.value = NAN; + nan.value = zero / zero; # else static memory_double nan = { L_(0.0) / L_(0.0) }; static DOUBLE plus_inf = L_(1.0) / L_(0.0); diff --git a/modules/ceilf-tests b/modules/ceilf-tests index 33d5be9cb..8653c4760 100644 --- a/modules/ceilf-tests +++ b/modules/ceilf-tests @@ -1,6 +1,7 @@ Files: tests/test-ceilf1.c tests/test-ceilf2.c +tests/nan.h Depends-on: float diff --git a/modules/floorf-tests b/modules/floorf-tests index 5390f4bad..e3f2b03fa 100644 --- a/modules/floorf-tests +++ b/modules/floorf-tests @@ -1,6 +1,7 @@ Files: tests/test-floorf1.c tests/test-floorf2.c +tests/nan.h Depends-on: float diff --git a/modules/frexp-tests b/modules/frexp-tests index 6982cf94e..eee00fd02 100644 --- a/modules/frexp-tests +++ b/modules/frexp-tests @@ -1,5 +1,6 @@ Files: tests/test-frexp.c +tests/nan.h Depends-on: isnand-nolibm diff --git a/modules/isnand-nolibm b/modules/isnand-nolibm index cab173d5c..6bb8c7da3 100644 --- a/modules/isnand-nolibm +++ b/modules/isnand-nolibm @@ -10,7 +10,6 @@ m4/isnand.m4 Depends-on: fpieee -math configure.ac: gl_FUNC_ISNAND_NO_LIBM diff --git a/modules/isnand-nolibm-tests b/modules/isnand-nolibm-tests index cfe52b800..7fd37bae0 100644 --- a/modules/isnand-nolibm-tests +++ b/modules/isnand-nolibm-tests @@ -1,5 +1,6 @@ Files: tests/test-isnand.c +tests/nan.h Depends-on: diff --git a/modules/isnanf-nolibm b/modules/isnanf-nolibm index 1489e307b..3f906295f 100644 --- a/modules/isnanf-nolibm +++ b/modules/isnanf-nolibm @@ -10,7 +10,6 @@ m4/isnanf.m4 Depends-on: fpieee -math configure.ac: gl_FUNC_ISNANF_NO_LIBM diff --git a/modules/isnanf-nolibm-tests b/modules/isnanf-nolibm-tests index fa8b9c0ae..8225ff4e0 100644 --- a/modules/isnanf-nolibm-tests +++ b/modules/isnanf-nolibm-tests @@ -1,5 +1,6 @@ Files: tests/test-isnanf.c +tests/nan.h Depends-on: diff --git a/modules/isnanl b/modules/isnanl index 6ba1ee4cb..026981f27 100644 --- a/modules/isnanl +++ b/modules/isnanl @@ -11,7 +11,6 @@ m4/isnanl.m4 Depends-on: float fpieee -math configure.ac: gl_FUNC_ISNANL diff --git a/modules/isnanl-nolibm b/modules/isnanl-nolibm index 783dc770d..9250fef0e 100644 --- a/modules/isnanl-nolibm +++ b/modules/isnanl-nolibm @@ -11,7 +11,6 @@ m4/isnanl.m4 Depends-on: float fpieee -math configure.ac: gl_FUNC_ISNANL_NO_LIBM diff --git a/modules/round-tests b/modules/round-tests index a4d2a15ab..909910c95 100644 --- a/modules/round-tests +++ b/modules/round-tests @@ -1,6 +1,7 @@ Files: tests/test-round1.c tests/test-round2.c +tests/nan.h Depends-on: isnand-nolibm diff --git a/modules/roundf-tests b/modules/roundf-tests index 6aa6372cf..c1ae0de5c 100644 --- a/modules/roundf-tests +++ b/modules/roundf-tests @@ -2,6 +2,7 @@ Files: tests/test-roundf1.c tests/test-round2.c tests/test-roundf2.c +tests/nan.h Depends-on: ceilf diff --git a/modules/snprintf-posix-tests b/modules/snprintf-posix-tests index 382605124..5af4266ac 100644 --- a/modules/snprintf-posix-tests +++ b/modules/snprintf-posix-tests @@ -2,9 +2,9 @@ Files: tests/test-snprintf-posix.c tests/test-snprintf-posix.h tests/test-snprintf.c +tests/nan.h Depends-on: -math stdint configure.ac: diff --git a/modules/sprintf-posix-tests b/modules/sprintf-posix-tests index 5df186ad8..cf6720438 100644 --- a/modules/sprintf-posix-tests +++ b/modules/sprintf-posix-tests @@ -1,9 +1,9 @@ Files: tests/test-sprintf-posix.c tests/test-sprintf-posix.h +tests/nan.h Depends-on: -math stdint configure.ac: diff --git a/modules/trunc-tests b/modules/trunc-tests index 621e76d42..f986e3c09 100644 --- a/modules/trunc-tests +++ b/modules/trunc-tests @@ -1,6 +1,7 @@ Files: tests/test-trunc1.c tests/test-trunc2.c +tests/nan.h Depends-on: float diff --git a/modules/truncf-tests b/modules/truncf-tests index 3584de225..0f56e7f4e 100644 --- a/modules/truncf-tests +++ b/modules/truncf-tests @@ -1,6 +1,7 @@ Files: tests/test-truncf1.c tests/test-truncf2.c +tests/nan.h Depends-on: float diff --git a/modules/vasnprintf-posix-tests b/modules/vasnprintf-posix-tests index d8a39d4d9..f46fffa19 100644 --- a/modules/vasnprintf-posix-tests +++ b/modules/vasnprintf-posix-tests @@ -2,10 +2,10 @@ Files: tests/test-vasnprintf-posix.c tests/test-vasnprintf-posix2.sh tests/test-vasnprintf-posix2.c +tests/nan.h m4/locale-fr.m4 Depends-on: -math stdint configure.ac: diff --git a/modules/vasprintf-posix-tests b/modules/vasprintf-posix-tests index 391c6a135..221ccd109 100644 --- a/modules/vasprintf-posix-tests +++ b/modules/vasprintf-posix-tests @@ -1,8 +1,8 @@ Files: tests/test-vasprintf-posix.c +tests/nan.h Depends-on: -math stdint configure.ac: diff --git a/modules/vsnprintf-posix-tests b/modules/vsnprintf-posix-tests index 1604b1e3b..3b45e44cf 100644 --- a/modules/vsnprintf-posix-tests +++ b/modules/vsnprintf-posix-tests @@ -2,9 +2,9 @@ Files: tests/test-vsnprintf-posix.c tests/test-snprintf-posix.h tests/test-vsnprintf.c +tests/nan.h Depends-on: -math stdint configure.ac: diff --git a/modules/vsprintf-posix-tests b/modules/vsprintf-posix-tests index 7c4203931..e48d5aef5 100644 --- a/modules/vsprintf-posix-tests +++ b/modules/vsprintf-posix-tests @@ -1,9 +1,9 @@ Files: tests/test-vsprintf-posix.c tests/test-sprintf-posix.h +tests/nan.h Depends-on: -math stdint configure.ac: diff --git a/tests/nan.h b/tests/nan.h new file mode 100644 index 000000000..3bdf6438c --- /dev/null +++ b/tests/nan.h @@ -0,0 +1,50 @@ +/* Macros for not-a-number. + Copyright (C) 2007-2008 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 + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + + +/* NaNf () returns a 'float' not-a-number. */ + +/* The Compaq (ex-DEC) C 6.4 compiler chokes on the expression 0.0 / 0.0. */ +#ifdef __DECC +static float +NaNf () +{ + static float zero = 0.0f; + return zero / zero; +} +#else +# define NaNf() (0.0f / 0.0f) +#endif + + +/* NaNd () returns a 'double' not-a-number. */ + +/* The Compaq (ex-DEC) C 6.4 compiler chokes on the expression 0.0 / 0.0. */ +#ifdef __DECC +static double +NaNd () +{ + static double zero = 0.0; + return zero / zero; +} +#else +# define NaNd() (0.0 / 0.0) +#endif + + +/* NaNl () returns a 'long double' not-a-number. */ + +#define NaNl() (0.0L / 0.0L) diff --git a/tests/test-ceilf1.c b/tests/test-ceilf1.c index b323227b7..e2a04a0ec 100644 --- a/tests/test-ceilf1.c +++ b/tests/test-ceilf1.c @@ -1,5 +1,5 @@ /* Test of rounding towards positive infinity. - Copyright (C) 2007, 2008 Free Software Foundation, Inc. + Copyright (C) 2007-2008 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,6 +24,7 @@ #include #include "isnanf.h" +#include "nan.h" #define ASSERT(expr) \ do \ @@ -67,7 +68,7 @@ main () ASSERT (ceilf (1.0f / 0.0f) == 1.0f / 0.0f); ASSERT (ceilf (-1.0f / 0.0f) == -1.0f / 0.0f); /* NaNs. */ - ASSERT (isnanf (ceilf (NAN))); + ASSERT (isnanf (ceilf (NaNf ()))); return 0; } diff --git a/tests/test-floorf1.c b/tests/test-floorf1.c index a45bcfc2a..2a9d10305 100644 --- a/tests/test-floorf1.c +++ b/tests/test-floorf1.c @@ -1,5 +1,5 @@ /* Test of rounding towards negative infinity. - Copyright (C) 2007, 2008 Free Software Foundation, Inc. + Copyright (C) 2007-2008 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,6 +24,7 @@ #include #include "isnanf.h" +#include "nan.h" #define ASSERT(expr) \ do \ @@ -67,7 +68,7 @@ main () ASSERT (floorf (1.0f / 0.0f) == 1.0f / 0.0f); ASSERT (floorf (-1.0f / 0.0f) == -1.0f / 0.0f); /* NaNs. */ - ASSERT (isnanf (floorf (NAN))); + ASSERT (isnanf (floorf (NaNf ()))); return 0; } diff --git a/tests/test-frexp.c b/tests/test-frexp.c index cb80f5641..9e92667cb 100644 --- a/tests/test-frexp.c +++ b/tests/test-frexp.c @@ -25,6 +25,7 @@ #include #include "isnand.h" +#include "nan.h" #define ASSERT(expr) \ do \ @@ -61,7 +62,7 @@ main () { /* NaN. */ int exp = -9999; double mantissa; - x = NAN; + x = NaNd (); mantissa = frexp (x, &exp); ASSERT (isnand (mantissa)); } diff --git a/tests/test-isnand.c b/tests/test-isnand.c index 1dc923896..ff7310121 100644 --- a/tests/test-isnand.c +++ b/tests/test-isnand.c @@ -21,10 +21,11 @@ #include "isnand.h" #include -#include #include #include +#include "nan.h" + #define ASSERT(expr) \ do \ { \ @@ -52,7 +53,7 @@ main () ASSERT (!isnand (1.0 / 0.0)); ASSERT (!isnand (-1.0 / 0.0)); /* Quiet NaN. */ - ASSERT (isnand (NAN)); + ASSERT (isnand (NaNd ())); #if defined DBL_EXPBIT0_WORD && defined DBL_EXPBIT0_BIT /* Signalling NaN. */ { @@ -60,7 +61,7 @@ main () ((sizeof (double) + sizeof (unsigned int) - 1) / sizeof (unsigned int)) typedef union { double value; unsigned int word[NWORDS]; } memory_double; memory_double m; - m.value = NAN; + m.value = NaNd (); # if DBL_EXPBIT0_BIT > 0 m.word[DBL_EXPBIT0_WORD] ^= (unsigned int) 1 << (DBL_EXPBIT0_BIT - 1); # else diff --git a/tests/test-isnanf.c b/tests/test-isnanf.c index 6c084acb2..c70b619e7 100644 --- a/tests/test-isnanf.c +++ b/tests/test-isnanf.c @@ -1,5 +1,5 @@ /* Test of isnanf() substitute. - Copyright (C) 2007, 2008 Free Software Foundation, Inc. + Copyright (C) 2007-2008 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 @@ -21,10 +21,11 @@ #include "isnanf.h" #include -#include #include #include +#include "nan.h" + #define ASSERT(expr) \ do \ { \ @@ -52,7 +53,7 @@ main () ASSERT (!isnanf (1.0f / 0.0f)); ASSERT (!isnanf (-1.0f / 0.0f)); /* Quiet NaN. */ - ASSERT (isnanf (NAN)); + ASSERT (isnanf (NaNf ())); #if defined FLT_EXPBIT0_WORD && defined FLT_EXPBIT0_BIT /* Signalling NaN. */ { @@ -60,7 +61,7 @@ main () ((sizeof (float) + sizeof (unsigned int) - 1) / sizeof (unsigned int)) typedef union { float value; unsigned int word[NWORDS]; } memory_float; memory_float m; - m.value = NAN; + m.value = NaNf (); # if FLT_EXPBIT0_BIT > 0 m.word[FLT_EXPBIT0_WORD] ^= (unsigned int) 1 << (FLT_EXPBIT0_BIT - 1); # else diff --git a/tests/test-math.c b/tests/test-math.c index 5c00581d1..56cf058c4 100644 --- a/tests/test-math.c +++ b/tests/test-math.c @@ -25,6 +25,11 @@ choke me #endif +#if 0 +/* Check that NAN expands into a constant expression. */ +static float n = NAN; +#endif + int main () { diff --git a/tests/test-round1.c b/tests/test-round1.c index 704e1da64..2710f911f 100644 --- a/tests/test-round1.c +++ b/tests/test-round1.c @@ -26,6 +26,7 @@ #include #include "isnand.h" +#include "nan.h" #define ASSERT(expr) \ do \ @@ -74,7 +75,7 @@ main () ASSERT (round (1.0 / 0.0) == 1.0 / 0.0); ASSERT (round (-1.0 / 0.0) == -1.0 / 0.0); /* NaNs. */ - ASSERT (isnand (round (NAN))); + ASSERT (isnand (round (NaNd ()))); return 0; } diff --git a/tests/test-roundf1.c b/tests/test-roundf1.c index aeee3b173..8131cb2aa 100644 --- a/tests/test-roundf1.c +++ b/tests/test-roundf1.c @@ -26,6 +26,7 @@ #include #include "isnanf.h" +#include "nan.h" #define ASSERT(expr) \ do \ @@ -74,7 +75,7 @@ main () ASSERT (roundf (1.0 / 0.0f) == 1.0 / 0.0f); ASSERT (roundf (-1.0 / 0.0f) == -1.0 / 0.0f); /* NaNs. */ - ASSERT (isnanf (roundf (NAN))); + ASSERT (isnanf (roundf (NaNf ()))); return 0; } diff --git a/tests/test-snprintf-posix.h b/tests/test-snprintf-posix.h index 4d69267a6..570f8b77d 100644 --- a/tests/test-snprintf-posix.h +++ b/tests/test-snprintf-posix.h @@ -16,7 +16,7 @@ /* Written by Bruno Haible , 2007. */ -#include +#include "nan.h" /* The SGI MIPS floating-point format does not distinguish 0.0 and -0.0. */ static int @@ -197,7 +197,7 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) { /* NaN. */ char result[100]; int retval = - my_snprintf (result, sizeof (result), "%a %d", NAN, 33, 44, 55); + my_snprintf (result, sizeof (result), "%a %d", NaNd (), 33, 44, 55); ASSERT (strlen (result) >= 3 + 3 && strisnan (result, 0, strlen (result) - 3, 0) && strcmp (result + strlen (result) - 3, " 33") == 0); @@ -394,7 +394,7 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) { /* FLAG_ZERO with NaN. */ char result[100]; int retval = - my_snprintf (result, sizeof (result), "%050a %d", NAN, 33, 44, 55); + my_snprintf (result, sizeof (result), "%050a %d", NaNd (), 33, 44, 55); /* "0000000nan 33" is not a valid result; see */ ASSERT (strlen (result) == 50 + 3 @@ -461,7 +461,7 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) { /* NaN. */ char result[100]; int retval = - my_snprintf (result, sizeof (result), "%La %d", 0.0L / 0.0L, 33, 44, 55); + my_snprintf (result, sizeof (result), "%La %d", NaNl (), 33, 44, 55); ASSERT (strlen (result) >= 3 + 3 && strisnan (result, 0, strlen (result) - 3, 0) && strcmp (result + strlen (result) - 3, " 33") == 0); @@ -746,7 +746,7 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) { /* FLAG_ZERO with NaN. */ char result[100]; int retval = - my_snprintf (result, sizeof (result), "%050La %d", 0.0L / 0.0L, 33, 44, 55); + my_snprintf (result, sizeof (result), "%050La %d", NaNl (), 33, 44, 55); /* "0000000nan 33" is not a valid result; see */ ASSERT (strlen (result) == 50 + 3 @@ -908,7 +908,7 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) { /* NaN. */ char result[100]; int retval = - my_snprintf (result, sizeof (result), "%f %d", NAN, 33, 44, 55); + my_snprintf (result, sizeof (result), "%f %d", NaNd (), 33, 44, 55); ASSERT (strlen (result) >= 3 + 3 && strisnan (result, 0, strlen (result) - 3, 0) && strcmp (result + strlen (result) - 3, " 33") == 0); @@ -989,7 +989,7 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) { /* FLAG_ZERO with NaN. */ char result[100]; int retval = - my_snprintf (result, sizeof (result), "%050f %d", NAN, 33, 44, 55); + my_snprintf (result, sizeof (result), "%050f %d", NaNd (), 33, 44, 55); ASSERT (strlen (result) == 50 + 3 && strisnan (result, strspn (result, " "), strlen (result) - 3, 0) && strcmp (result + strlen (result) - 3, " 33") == 0); @@ -1153,10 +1153,9 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) } { /* NaN. */ - static long double zero = 0.0L; char result[100]; int retval = - my_snprintf (result, sizeof (result), "%Lf %d", zero / zero, 33, 44, 55); + my_snprintf (result, sizeof (result), "%Lf %d", NaNl (), 33, 44, 55); ASSERT (strlen (result) >= 3 + 3 && strisnan (result, 0, strlen (result) - 3, 0) && strcmp (result + strlen (result) - 3, " 33") == 0); @@ -1322,10 +1321,9 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) } { /* FLAG_ZERO with NaN. */ - static long double zero = 0.0L; char result[100]; int retval = - my_snprintf (result, sizeof (result), "%050Lf %d", zero / zero, 33, 44, 55); + my_snprintf (result, sizeof (result), "%050Lf %d", NaNl (), 33, 44, 55); ASSERT (strlen (result) == 50 + 3 && strisnan (result, strspn (result, " "), strlen (result) - 3, 0) && strcmp (result + strlen (result) - 3, " 33") == 0); @@ -1404,7 +1402,7 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) { /* NaN. */ char result[100]; int retval = - my_snprintf (result, sizeof (result), "%F %d", NAN, 33, 44, 55); + my_snprintf (result, sizeof (result), "%F %d", NaNd (), 33, 44, 55); ASSERT (strlen (result) >= 3 + 3 && strisnan (result, 0, strlen (result) - 3, 1) && strcmp (result + strlen (result) - 3, " 33") == 0); @@ -1496,10 +1494,9 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) } { /* NaN. */ - static long double zero = 0.0L; char result[100]; int retval = - my_snprintf (result, sizeof (result), "%LF %d", zero / zero, 33, 44, 55); + my_snprintf (result, sizeof (result), "%LF %d", NaNl (), 33, 44, 55); ASSERT (strlen (result) >= 3 + 3 && strisnan (result, 0, strlen (result) - 3, 1) && strcmp (result + strlen (result) - 3, " 33") == 0); @@ -1698,7 +1695,7 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) { /* NaN. */ char result[100]; int retval = - my_snprintf (result, sizeof (result), "%e %d", NAN, 33, 44, 55); + my_snprintf (result, sizeof (result), "%e %d", NaNd (), 33, 44, 55); ASSERT (strlen (result) >= 3 + 3 && strisnan (result, 0, strlen (result) - 3, 0) && strcmp (result + strlen (result) - 3, " 33") == 0); @@ -1789,7 +1786,7 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) { /* FLAG_ZERO with NaN. */ char result[100]; int retval = - my_snprintf (result, sizeof (result), "%050e %d", NAN, 33, 44, 55); + my_snprintf (result, sizeof (result), "%050e %d", NaNd (), 33, 44, 55); ASSERT (strlen (result) == 50 + 3 && strisnan (result, strspn (result, " "), strlen (result) - 3, 0) && strcmp (result + strlen (result) - 3, " 33") == 0); @@ -1954,10 +1951,9 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) } { /* NaN. */ - static long double zero = 0.0L; char result[100]; int retval = - my_snprintf (result, sizeof (result), "%Le %d", zero / zero, 33, 44, 55); + my_snprintf (result, sizeof (result), "%Le %d", NaNl (), 33, 44, 55); ASSERT (strlen (result) >= 3 + 3 && strisnan (result, 0, strlen (result) - 3, 0) && strcmp (result + strlen (result) - 3, " 33") == 0); @@ -2125,10 +2121,9 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) } { /* FLAG_ZERO with NaN. */ - static long double zero = 0.0L; char result[100]; int retval = - my_snprintf (result, sizeof (result), "%050Le %d", zero / zero, 33, 44, 55); + my_snprintf (result, sizeof (result), "%050Le %d", NaNl (), 33, 44, 55); ASSERT (strlen (result) == 50 + 3 && strisnan (result, strspn (result, " "), strlen (result) - 3, 0) && strcmp (result + strlen (result) - 3, " 33") == 0); @@ -2306,7 +2301,7 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) { /* NaN. */ char result[100]; int retval = - my_snprintf (result, sizeof (result), "%g %d", NAN, 33, 44, 55); + my_snprintf (result, sizeof (result), "%g %d", NaNd (), 33, 44, 55); ASSERT (strlen (result) >= 3 + 3 && strisnan (result, 0, strlen (result) - 3, 0) && strcmp (result + strlen (result) - 3, " 33") == 0); @@ -2390,7 +2385,7 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) { /* FLAG_ZERO with NaN. */ char result[100]; int retval = - my_snprintf (result, sizeof (result), "%050g %d", NAN, 33, 44, 55); + my_snprintf (result, sizeof (result), "%050g %d", NaNd (), 33, 44, 55); ASSERT (strlen (result) == 50 + 3 && strisnan (result, strspn (result, " "), strlen (result) - 3, 0) && strcmp (result + strlen (result) - 3, " 33") == 0); @@ -2555,10 +2550,9 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) } { /* NaN. */ - static long double zero = 0.0L; char result[100]; int retval = - my_snprintf (result, sizeof (result), "%Lg %d", zero / zero, 33, 44, 55); + my_snprintf (result, sizeof (result), "%Lg %d", NaNl (), 33, 44, 55); ASSERT (strlen (result) >= 3 + 3 && strisnan (result, 0, strlen (result) - 3, 0) && strcmp (result + strlen (result) - 3, " 33") == 0); @@ -2726,10 +2720,9 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) } { /* FLAG_ZERO with NaN. */ - static long double zero = 0.0L; char result[100]; int retval = - my_snprintf (result, sizeof (result), "%050Lg %d", zero / zero, 33, 44, 55); + my_snprintf (result, sizeof (result), "%050Lg %d", NaNl (), 33, 44, 55); ASSERT (strlen (result) == 50 + 3 && strisnan (result, strspn (result, " "), strlen (result) - 3, 0) && strcmp (result + strlen (result) - 3, " 33") == 0); diff --git a/tests/test-sprintf-posix.h b/tests/test-sprintf-posix.h index ac2afcf91..afe7ea28e 100644 --- a/tests/test-sprintf-posix.h +++ b/tests/test-sprintf-posix.h @@ -16,7 +16,7 @@ /* Written by Bruno Haible , 2007. */ -#include +#include "nan.h" /* The SGI MIPS floating-point format does not distinguish 0.0 and -0.0. */ static int @@ -183,7 +183,7 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) { /* NaN. */ char result[1000]; int retval = - my_sprintf (result, "%a %d", NAN, 33, 44, 55); + my_sprintf (result, "%a %d", NaNd (), 33, 44, 55); ASSERT (strlen (result) >= 3 + 3 && strisnan (result, 0, strlen (result) - 3, 0) && strcmp (result + strlen (result) - 3, " 33") == 0); @@ -380,7 +380,7 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) { /* FLAG_ZERO with NaN. */ char result[1000]; int retval = - my_sprintf (result, "%050a %d", NAN, 33, 44, 55); + my_sprintf (result, "%050a %d", NaNd (), 33, 44, 55); /* "0000000nan 33" is not a valid result; see */ ASSERT (strlen (result) == 50 + 3 @@ -447,7 +447,7 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) { /* NaN. */ char result[1000]; int retval = - my_sprintf (result, "%La %d", 0.0L / 0.0L, 33, 44, 55); + my_sprintf (result, "%La %d", NaNl (), 33, 44, 55); ASSERT (strlen (result) >= 3 + 3 && strisnan (result, 0, strlen (result) - 3, 0) && strcmp (result + strlen (result) - 3, " 33") == 0); @@ -732,7 +732,7 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) { /* FLAG_ZERO with NaN. */ char result[1000]; int retval = - my_sprintf (result, "%050La %d", 0.0L / 0.0L, 33, 44, 55); + my_sprintf (result, "%050La %d", NaNl (), 33, 44, 55); /* "0000000nan 33" is not a valid result; see */ ASSERT (strlen (result) == 50 + 3 @@ -894,7 +894,7 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) { /* NaN. */ char result[1000]; int retval = - my_sprintf (result, "%f %d", NAN, 33, 44, 55); + my_sprintf (result, "%f %d", NaNd (), 33, 44, 55); ASSERT (strlen (result) >= 3 + 3 && strisnan (result, 0, strlen (result) - 3, 0) && strcmp (result + strlen (result) - 3, " 33") == 0); @@ -969,7 +969,7 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) { /* FLAG_ZERO with NaN. */ char result[1000]; int retval = - my_sprintf (result, "%050f %d", NAN, 33, 44, 55); + my_sprintf (result, "%050f %d", NaNd (), 33, 44, 55); ASSERT (strlen (result) == 50 + 3 && strisnan (result, strspn (result, " "), strlen (result) - 3, 0) && strcmp (result + strlen (result) - 3, " 33") == 0); @@ -1133,10 +1133,9 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) } { /* NaN. */ - static long double zero = 0.0L; char result[1000]; int retval = - my_sprintf (result, "%Lf %d", zero / zero, 33, 44, 55); + my_sprintf (result, "%Lf %d", NaNl (), 33, 44, 55); ASSERT (strlen (result) >= 3 + 3 && strisnan (result, 0, strlen (result) - 3, 0) && strcmp (result + strlen (result) - 3, " 33") == 0); @@ -1296,10 +1295,9 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) } { /* FLAG_ZERO with NaN. */ - static long double zero = 0.0L; char result[1000]; int retval = - my_sprintf (result, "%050Lf %d", zero / zero, 33, 44, 55); + my_sprintf (result, "%050Lf %d", NaNl (), 33, 44, 55); ASSERT (strlen (result) == 50 + 3 && strisnan (result, strspn (result, " "), strlen (result) - 3, 0) && strcmp (result + strlen (result) - 3, " 33") == 0); @@ -1378,7 +1376,7 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) { /* NaN. */ char result[1000]; int retval = - my_sprintf (result, "%F %d", NAN, 33, 44, 55); + my_sprintf (result, "%F %d", NaNd (), 33, 44, 55); ASSERT (strlen (result) >= 3 + 3 && strisnan (result, 0, strlen (result) - 3, 1) && strcmp (result + strlen (result) - 3, " 33") == 0); @@ -1470,10 +1468,9 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) } { /* NaN. */ - static long double zero = 0.0L; char result[1000]; int retval = - my_sprintf (result, "%LF %d", zero / zero, 33, 44, 55); + my_sprintf (result, "%LF %d", NaNl (), 33, 44, 55); ASSERT (strlen (result) >= 3 + 3 && strisnan (result, 0, strlen (result) - 3, 1) && strcmp (result + strlen (result) - 3, " 33") == 0); @@ -1672,7 +1669,7 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) { /* NaN. */ char result[1000]; int retval = - my_sprintf (result, "%e %d", NAN, 33, 44, 55); + my_sprintf (result, "%e %d", NaNd (), 33, 44, 55); ASSERT (strlen (result) >= 3 + 3 && strisnan (result, 0, strlen (result) - 3, 0) && strcmp (result + strlen (result) - 3, " 33") == 0); @@ -1763,7 +1760,7 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) { /* FLAG_ZERO with NaN. */ char result[1000]; int retval = - my_sprintf (result, "%050e %d", NAN, 33, 44, 55); + my_sprintf (result, "%050e %d", NaNd (), 33, 44, 55); ASSERT (strlen (result) == 50 + 3 && strisnan (result, strspn (result, " "), strlen (result) - 3, 0) && strcmp (result + strlen (result) - 3, " 33") == 0); @@ -1928,10 +1925,9 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) } { /* NaN. */ - static long double zero = 0.0L; char result[1000]; int retval = - my_sprintf (result, "%Le %d", zero / zero, 33, 44, 55); + my_sprintf (result, "%Le %d", NaNl (), 33, 44, 55); ASSERT (strlen (result) >= 3 + 3 && strisnan (result, 0, strlen (result) - 3, 0) && strcmp (result + strlen (result) - 3, " 33") == 0); @@ -2099,10 +2095,9 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) } { /* FLAG_ZERO with NaN. */ - static long double zero = 0.0L; char result[1000]; int retval = - my_sprintf (result, "%050Le %d", zero / zero, 33, 44, 55); + my_sprintf (result, "%050Le %d", NaNl (), 33, 44, 55); ASSERT (strlen (result) == 50 + 3 && strisnan (result, strspn (result, " "), strlen (result) - 3, 0) && strcmp (result + strlen (result) - 3, " 33") == 0); @@ -2280,7 +2275,7 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) { /* NaN. */ char result[1000]; int retval = - my_sprintf (result, "%g %d", NAN, 33, 44, 55); + my_sprintf (result, "%g %d", NaNd (), 33, 44, 55); ASSERT (strlen (result) >= 3 + 3 && strisnan (result, 0, strlen (result) - 3, 0) && strcmp (result + strlen (result) - 3, " 33") == 0); @@ -2364,7 +2359,7 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) { /* FLAG_ZERO with NaN. */ char result[1000]; int retval = - my_sprintf (result, "%050g %d", NAN, 33, 44, 55); + my_sprintf (result, "%050g %d", NaNd (), 33, 44, 55); ASSERT (strlen (result) == 50 + 3 && strisnan (result, strspn (result, " "), strlen (result) - 3, 0) && strcmp (result + strlen (result) - 3, " 33") == 0); @@ -2529,10 +2524,9 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) } { /* NaN. */ - static long double zero = 0.0L; char result[1000]; int retval = - my_sprintf (result, "%Lg %d", zero / zero, 33, 44, 55); + my_sprintf (result, "%Lg %d", NaNl (), 33, 44, 55); ASSERT (strlen (result) >= 3 + 3 && strisnan (result, 0, strlen (result) - 3, 0) && strcmp (result + strlen (result) - 3, " 33") == 0); @@ -2700,10 +2694,9 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) } { /* FLAG_ZERO with NaN. */ - static long double zero = 0.0L; char result[1000]; int retval = - my_sprintf (result, "%050Lg %d", zero / zero, 33, 44, 55); + my_sprintf (result, "%050Lg %d", NaNl (), 33, 44, 55); ASSERT (strlen (result) == 50 + 3 && strisnan (result, strspn (result, " "), strlen (result) - 3, 0) && strcmp (result + strlen (result) - 3, " 33") == 0); diff --git a/tests/test-trunc1.c b/tests/test-trunc1.c index 6b283636e..7f1bd1037 100644 --- a/tests/test-trunc1.c +++ b/tests/test-trunc1.c @@ -24,6 +24,7 @@ #include #include "isnand.h" +#include "nan.h" #define ASSERT(expr) \ do \ @@ -66,7 +67,7 @@ main () ASSERT (trunc (1.0 / 0.0) == 1.0 / 0.0); ASSERT (trunc (-1.0 / 0.0) == -1.0 / 0.0); /* NaNs. */ - ASSERT (isnand (trunc (NAN))); + ASSERT (isnand (trunc (NaNd ()))); return 0; } diff --git a/tests/test-truncf1.c b/tests/test-truncf1.c index 9d365763f..482738951 100644 --- a/tests/test-truncf1.c +++ b/tests/test-truncf1.c @@ -1,5 +1,5 @@ /* Test of rounding towards zero. - Copyright (C) 2007, 2008 Free Software Foundation, Inc. + Copyright (C) 2007-2008 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,6 +24,7 @@ #include #include "isnanf.h" +#include "nan.h" #define ASSERT(expr) \ do \ @@ -66,7 +67,7 @@ main () ASSERT (truncf (1.0f / 0.0f) == 1.0f / 0.0f); ASSERT (truncf (-1.0f / 0.0f) == -1.0f / 0.0f); /* NaNs. */ - ASSERT (isnanf (truncf (NAN))); + ASSERT (isnanf (truncf (NaNf ()))); return 0; } diff --git a/tests/test-vasnprintf-posix.c b/tests/test-vasnprintf-posix.c index c29546a85..4605cd1d9 100644 --- a/tests/test-vasnprintf-posix.c +++ b/tests/test-vasnprintf-posix.c @@ -21,7 +21,6 @@ #include "vasnprintf.h" #include -#include #include #include #include @@ -29,6 +28,8 @@ #include #include +#include "nan.h" + #define SIZEOF(array) (sizeof (array) / sizeof (array[0])) #define ASSERT(expr) \ do \ @@ -246,7 +247,7 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) { /* NaN. */ size_t length; char *result = - my_asnprintf (NULL, &length, "%a %d", NAN, 33, 44, 55); + my_asnprintf (NULL, &length, "%a %d", NaNd (), 33, 44, 55); ASSERT (result != NULL); ASSERT (strlen (result) >= 3 + 3 && strisnan (result, 0, strlen (result) - 3, 0) @@ -479,7 +480,7 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) { /* FLAG_ZERO with NaN. */ size_t length; char *result = - my_asnprintf (NULL, &length, "%050a %d", NAN, 33, 44, 55); + my_asnprintf (NULL, &length, "%050a %d", NaNd (), 33, 44, 55); ASSERT (result != NULL); /* "0000000nan 33" is not a valid result; see */ @@ -560,7 +561,7 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) { /* NaN. */ size_t length; char *result = - my_asnprintf (NULL, &length, "%La %d", 0.0L / 0.0L, 33, 44, 55); + my_asnprintf (NULL, &length, "%La %d", NaNl (), 33, 44, 55); ASSERT (result != NULL); ASSERT (strlen (result) >= 3 + 3 && strisnan (result, 0, strlen (result) - 3, 0) @@ -895,7 +896,7 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) { /* FLAG_ZERO with NaN. */ size_t length; char *result = - my_asnprintf (NULL, &length, "%050La %d", 0.0L / 0.0L, 33, 44, 55); + my_asnprintf (NULL, &length, "%050La %d", NaNl (), 33, 44, 55); ASSERT (result != NULL); /* "0000000nan 33" is not a valid result; see */ @@ -1075,7 +1076,7 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) { /* NaN. */ size_t length; char *result = - my_asnprintf (NULL, &length, "%f %d", NAN, 33, 44, 55); + my_asnprintf (NULL, &length, "%f %d", NaNd (), 33, 44, 55); ASSERT (result != NULL); ASSERT (strlen (result) >= 3 + 3 && strisnan (result, 0, strlen (result) - 3, 0) @@ -1168,7 +1169,7 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) { /* FLAG_ZERO with NaN. */ size_t length; char *result = - my_asnprintf (NULL, &length, "%050f %d", NAN, 33, 44, 55); + my_asnprintf (NULL, &length, "%050f %d", NaNd (), 33, 44, 55); ASSERT (result != NULL); ASSERT (strlen (result) == 50 + 3 && strisnan (result, strspn (result, " "), strlen (result) - 3, 0) @@ -1352,10 +1353,9 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) } { /* NaN. */ - static long double zero = 0.0L; size_t length; char *result = - my_asnprintf (NULL, &length, "%Lf %d", zero / zero, 33, 44, 55); + my_asnprintf (NULL, &length, "%Lf %d", NaNl (), 33, 44, 55); ASSERT (result != NULL); ASSERT (strlen (result) >= 3 + 3 && strisnan (result, 0, strlen (result) - 3, 0) @@ -1547,10 +1547,9 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) } { /* FLAG_ZERO with NaN. */ - static long double zero = 0.0L; size_t length; char *result = - my_asnprintf (NULL, &length, "%050Lf %d", zero / zero, 33, 44, 55); + my_asnprintf (NULL, &length, "%050Lf %d", NaNl (), 33, 44, 55); ASSERT (result != NULL); ASSERT (strlen (result) == 50 + 3 && strisnan (result, strspn (result, " "), strlen (result) - 3, 0) @@ -1647,7 +1646,7 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) { /* NaN. */ size_t length; char *result = - my_asnprintf (NULL, &length, "%F %d", NAN, 33, 44, 55); + my_asnprintf (NULL, &length, "%F %d", NaNd (), 33, 44, 55); ASSERT (result != NULL); ASSERT (strlen (result) >= 3 + 3 && strisnan (result, 0, strlen (result) - 3, 1) @@ -1761,10 +1760,9 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) } { /* NaN. */ - static long double zero = 0.0L; size_t length; char *result = - my_asnprintf (NULL, &length, "%LF %d", zero / zero, 33, 44, 55); + my_asnprintf (NULL, &length, "%LF %d", NaNl (), 33, 44, 55); ASSERT (result != NULL); ASSERT (strlen (result) >= 3 + 3 && strisnan (result, 0, strlen (result) - 3, 1) @@ -1986,7 +1984,7 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) { /* NaN. */ size_t length; char *result = - my_asnprintf (NULL, &length, "%e %d", NAN, 33, 44, 55); + my_asnprintf (NULL, &length, "%e %d", NaNd (), 33, 44, 55); ASSERT (result != NULL); ASSERT (strlen (result) >= 3 + 3 && strisnan (result, 0, strlen (result) - 3, 0) @@ -2097,7 +2095,7 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) { /* FLAG_ZERO with NaN. */ size_t length; char *result = - my_asnprintf (NULL, &length, "%050e %d", NAN, 33, 44, 55); + my_asnprintf (NULL, &length, "%050e %d", NaNd (), 33, 44, 55); ASSERT (result != NULL); ASSERT (strlen (result) == 50 + 3 && strisnan (result, strspn (result, " "), strlen (result) - 3, 0) @@ -2282,10 +2280,9 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) } { /* NaN. */ - static long double zero = 0.0L; size_t length; char *result = - my_asnprintf (NULL, &length, "%Le %d", zero / zero, 33, 44, 55); + my_asnprintf (NULL, &length, "%Le %d", NaNl (), 33, 44, 55); ASSERT (result != NULL); ASSERT (strlen (result) >= 3 + 3 && strisnan (result, 0, strlen (result) - 3, 0) @@ -2487,10 +2484,9 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) } { /* FLAG_ZERO with NaN. */ - static long double zero = 0.0L; size_t length; char *result = - my_asnprintf (NULL, &length, "%050Le %d", zero / zero, 33, 44, 55); + my_asnprintf (NULL, &length, "%050Le %d", NaNl (), 33, 44, 55); ASSERT (result != NULL); ASSERT (strlen (result) == 50 + 3 && strisnan (result, strspn (result, " "), strlen (result) - 3, 0) @@ -2688,7 +2684,7 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) { /* NaN. */ size_t length; char *result = - my_asnprintf (NULL, &length, "%g %d", NAN, 33, 44, 55); + my_asnprintf (NULL, &length, "%g %d", NaNd (), 33, 44, 55); ASSERT (result != NULL); ASSERT (strlen (result) >= 3 + 3 && strisnan (result, 0, strlen (result) - 3, 0) @@ -2792,7 +2788,7 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) { /* FLAG_ZERO with NaN. */ size_t length; char *result = - my_asnprintf (NULL, &length, "%050g %d", NAN, 33, 44, 55); + my_asnprintf (NULL, &length, "%050g %d", NaNd (), 33, 44, 55); ASSERT (result != NULL); ASSERT (strlen (result) == 50 + 3 && strisnan (result, strspn (result, " "), strlen (result) - 3, 0) @@ -2977,10 +2973,9 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) } { /* NaN. */ - static long double zero = 0.0L; size_t length; char *result = - my_asnprintf (NULL, &length, "%Lg %d", zero / zero, 33, 44, 55); + my_asnprintf (NULL, &length, "%Lg %d", NaNl (), 33, 44, 55); ASSERT (result != NULL); ASSERT (strlen (result) >= 3 + 3 && strisnan (result, 0, strlen (result) - 3, 0) @@ -3182,10 +3177,9 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) } { /* FLAG_ZERO with NaN. */ - static long double zero = 0.0L; size_t length; char *result = - my_asnprintf (NULL, &length, "%050Lg %d", zero / zero, 33, 44, 55); + my_asnprintf (NULL, &length, "%050Lg %d", NaNl (), 33, 44, 55); ASSERT (result != NULL); ASSERT (strlen (result) == 50 + 3 && strisnan (result, strspn (result, " "), strlen (result) - 3, 0) diff --git a/tests/test-vasprintf-posix.c b/tests/test-vasprintf-posix.c index 806ce749f..2270d6aee 100644 --- a/tests/test-vasprintf-posix.c +++ b/tests/test-vasprintf-posix.c @@ -21,7 +21,6 @@ #include #include -#include #include #include #include @@ -29,6 +28,8 @@ #include #include +#include "nan.h" + #define SIZEOF(array) (sizeof (array) / sizeof (array[0])) #define ASSERT(expr) \ do \ @@ -227,7 +228,7 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) { /* NaN. */ char *result; int retval = - my_asprintf (&result, "%a %d", NAN, 33, 44, 55); + my_asprintf (&result, "%a %d", NaNd (), 33, 44, 55); ASSERT (result != NULL); ASSERT (strlen (result) >= 3 + 3 && strisnan (result, 0, strlen (result) - 3, 0) @@ -460,7 +461,7 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) { /* FLAG_ZERO with NaN. */ char *result; int retval = - my_asprintf (&result, "%050a %d", NAN, 33, 44, 55); + my_asprintf (&result, "%050a %d", NaNd (), 33, 44, 55); ASSERT (result != NULL); /* "0000000nan 33" is not a valid result; see */ @@ -541,7 +542,7 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) { /* NaN. */ char *result; int retval = - my_asprintf (&result, "%La %d", 0.0L / 0.0L, 33, 44, 55); + my_asprintf (&result, "%La %d", NaNl (), 33, 44, 55); ASSERT (result != NULL); ASSERT (strlen (result) >= 3 + 3 && strisnan (result, 0, strlen (result) - 3, 0) @@ -876,7 +877,7 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) { /* FLAG_ZERO with NaN. */ char *result; int retval = - my_asprintf (&result, "%050La %d", 0.0L / 0.0L, 33, 44, 55); + my_asprintf (&result, "%050La %d", NaNl (), 33, 44, 55); ASSERT (result != NULL); /* "0000000nan 33" is not a valid result; see */ @@ -1056,7 +1057,7 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) { /* NaN. */ char *result; int retval = - my_asprintf (&result, "%f %d", NAN, 33, 44, 55); + my_asprintf (&result, "%f %d", NaNd (), 33, 44, 55); ASSERT (result != NULL); ASSERT (strlen (result) >= 3 + 3 && strisnan (result, 0, strlen (result) - 3, 0) @@ -1149,7 +1150,7 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) { /* FLAG_ZERO with NaN. */ char *result; int retval = - my_asprintf (&result, "%050f %d", NAN, 33, 44, 55); + my_asprintf (&result, "%050f %d", NaNd (), 33, 44, 55); ASSERT (result != NULL); ASSERT (strlen (result) == 50 + 3 && strisnan (result, strspn (result, " "), strlen (result) - 3, 0) @@ -1333,10 +1334,9 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) } { /* NaN. */ - static long double zero = 0.0L; char *result; int retval = - my_asprintf (&result, "%Lf %d", zero / zero, 33, 44, 55); + my_asprintf (&result, "%Lf %d", NaNl (), 33, 44, 55); ASSERT (result != NULL); ASSERT (strlen (result) >= 3 + 3 && strisnan (result, 0, strlen (result) - 3, 0) @@ -1528,10 +1528,9 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) } { /* FLAG_ZERO with NaN. */ - static long double zero = 0.0L; char *result; int retval = - my_asprintf (&result, "%050Lf %d", zero / zero, 33, 44, 55); + my_asprintf (&result, "%050Lf %d", NaNl (), 33, 44, 55); ASSERT (result != NULL); ASSERT (strlen (result) == 50 + 3 && strisnan (result, strspn (result, " "), strlen (result) - 3, 0) @@ -1628,7 +1627,7 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) { /* NaN. */ char *result; int retval = - my_asprintf (&result, "%F %d", NAN, 33, 44, 55); + my_asprintf (&result, "%F %d", NaNd (), 33, 44, 55); ASSERT (result != NULL); ASSERT (strlen (result) >= 3 + 3 && strisnan (result, 0, strlen (result) - 3, 1) @@ -1742,10 +1741,9 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) } { /* NaN. */ - static long double zero = 0.0L; char *result; int retval = - my_asprintf (&result, "%LF %d", zero / zero, 33, 44, 55); + my_asprintf (&result, "%LF %d", NaNl (), 33, 44, 55); ASSERT (result != NULL); ASSERT (strlen (result) >= 3 + 3 && strisnan (result, 0, strlen (result) - 3, 1) @@ -1967,7 +1965,7 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) { /* NaN. */ char *result; int retval = - my_asprintf (&result, "%e %d", NAN, 33, 44, 55); + my_asprintf (&result, "%e %d", NaNd (), 33, 44, 55); ASSERT (result != NULL); ASSERT (strlen (result) >= 3 + 3 && strisnan (result, 0, strlen (result) - 3, 0) @@ -2078,7 +2076,7 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) { /* FLAG_ZERO with NaN. */ char *result; int retval = - my_asprintf (&result, "%050e %d", NAN, 33, 44, 55); + my_asprintf (&result, "%050e %d", NaNd (), 33, 44, 55); ASSERT (result != NULL); ASSERT (strlen (result) == 50 + 3 && strisnan (result, strspn (result, " "), strlen (result) - 3, 0) @@ -2263,10 +2261,9 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) } { /* NaN. */ - static long double zero = 0.0L; char *result; int retval = - my_asprintf (&result, "%Le %d", zero / zero, 33, 44, 55); + my_asprintf (&result, "%Le %d", NaNl (), 33, 44, 55); ASSERT (result != NULL); ASSERT (strlen (result) >= 3 + 3 && strisnan (result, 0, strlen (result) - 3, 0) @@ -2468,10 +2465,9 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) } { /* FLAG_ZERO with NaN. */ - static long double zero = 0.0L; char *result; int retval = - my_asprintf (&result, "%050Le %d", zero / zero, 33, 44, 55); + my_asprintf (&result, "%050Le %d", NaNl (), 33, 44, 55); ASSERT (result != NULL); ASSERT (strlen (result) == 50 + 3 && strisnan (result, strspn (result, " "), strlen (result) - 3, 0) @@ -2669,7 +2665,7 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) { /* NaN. */ char *result; int retval = - my_asprintf (&result, "%g %d", NAN, 33, 44, 55); + my_asprintf (&result, "%g %d", NaNd (), 33, 44, 55); ASSERT (result != NULL); ASSERT (strlen (result) >= 3 + 3 && strisnan (result, 0, strlen (result) - 3, 0) @@ -2773,7 +2769,7 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) { /* FLAG_ZERO with NaN. */ char *result; int retval = - my_asprintf (&result, "%050g %d", NAN, 33, 44, 55); + my_asprintf (&result, "%050g %d", NaNd (), 33, 44, 55); ASSERT (result != NULL); ASSERT (strlen (result) == 50 + 3 && strisnan (result, strspn (result, " "), strlen (result) - 3, 0) @@ -2958,10 +2954,9 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) } { /* NaN. */ - static long double zero = 0.0L; char *result; int retval = - my_asprintf (&result, "%Lg %d", zero / zero, 33, 44, 55); + my_asprintf (&result, "%Lg %d", NaNl (), 33, 44, 55); ASSERT (result != NULL); ASSERT (strlen (result) >= 3 + 3 && strisnan (result, 0, strlen (result) - 3, 0) @@ -3163,10 +3158,9 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) } { /* FLAG_ZERO with NaN. */ - static long double zero = 0.0L; char *result; int retval = - my_asprintf (&result, "%050Lg %d", zero / zero, 33, 44, 55); + my_asprintf (&result, "%050Lg %d", NaNl (), 33, 44, 55); ASSERT (result != NULL); ASSERT (strlen (result) == 50 + 3 && strisnan (result, strspn (result, " "), strlen (result) - 3, 0) -- 2.11.0