-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 According to Bruno Haible on 3/31/2008 4:04 PM: | Eric Blake wrote: |> The problem was that Solaris 8 does not define NAN anywhere, so the |> test failures I saw in the NaN section of test-strtod.c were because |> Solaris was correctly parsing NaN, but the test thought that NaN was not |> possible. | | So, the '#ifdef NAN' needs to go. It's less portable than a '#if 1'. All | CPUs nowadays (and already for 15 years) support NaNs. The IEEE 754/854 | are not supported to the letter, but their essential features (NaNs, | Infinities, +/- 0) are supported everywhere.
In which case, strtod.c was also broken for depending on NAN, but rather than just checking if it was defined, it also used it. So I'm patching math.in.h to guarantee NAN, borrowing from test-ceilf1.c. Since I don't have access to the broken Compaq DEC compiler which can't do NAN as a compile-time constant, can you please double-check this? Also, for new enough gcc, should we use __builtin_nan("")? - -- Don't work too hard, make some time for fun as well! Eric Blake [EMAIL PROTECTED] -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.8 (Cygwin) Comment: Public key at home.comcast.net/~ericblake/eblake.gpg Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iEYEARECAAYFAkfxp8cACgkQ84KuGfSFAYB/7gCeKhQojSXkiPJl4UfbxXHVCFxS D50An2aNQuyfzGUXuI3b06VneY3V1LOV =3gy9 -----END PGP SIGNATURE-----
>From 06945b7c073c0872ec2049c0e0b94f789bf8d77e Mon Sep 17 00:00:00 2001 From: Eric Blake <[EMAIL PROTECTED]> Date: Mon, 31 Mar 2008 20:56:25 -0600 Subject: [PATCH] Guarantee a definition of NAN. * lib/math.in.h (NAN): Define if missing. * tests/test-math.c (main): Test it. * doc/posix-headers/math.texi (math.h): Document this. * lib/isnan.c (rpl_isnand): Use it. * tests/test-ceilf1.c (NaN): Delete, and use NAN instead. * tests/test-floorf1.c (NaN): Likewise. * tests/test-frexp.c (NaN): Likewise. * tests/test-isnand.c (NaN): Likewise. * tests/test-isnanf.c (NaN): Likewise. * tests/test-round1.c (NaN): Likewise. * tests/test-roundf1.c (NaN): Likewise. * tests/test-snprintf-posix.h (NaN): Likewise. * tests/test-sprintf-posix.h (NaN): Likewise. * tests/test-trunc1.c (NaN): Likewise. * tests/test-truncf1.c (NaN): Likewise. * tests/test-vasnprintf-posix.c (NaN): Likewise. * tests/test-vasprintf-posix.c (NaN): Likewise. * modules/isnand-nolibm (Depends-on): Add math. * modules/isnanf-nolibm (Depends-on): Likewise. * modules/isnanl (Depends-on): Likewise. * modules/isnanl-nolibm (Depends-on): Likewise. * modules/snprintf-posix-tests (Depends-on): Likewise. * modules/sprintf-posix-tests (Depends-on): Likewise. * modules/vsnprintf-posix-tests (Depends-on): Likewise. * modules/vsprintf-posix-tests (Depends-on): Likewise. * modules/vasnprintf-posix-tests (Depends-on): Likewise. * modules/vasprintf-posix-tests (Depends-on): Likewise. Signed-off-by: Eric Blake <[EMAIL PROTECTED]> --- ChangeLog | 31 +++++++++++++++++++++++++++++++ doc/posix-headers/math.texi | 6 ++++++ lib/isnan.c | 4 ++-- lib/math.in.h | 20 +++++++++++++++++++- modules/isnand-nolibm | 1 + modules/isnanf-nolibm | 1 + modules/isnanl | 1 + modules/isnanl-nolibm | 1 + modules/snprintf-posix-tests | 1 + modules/sprintf-posix-tests | 1 + modules/vasnprintf-posix-tests | 1 + modules/vasprintf-posix-tests | 1 + modules/vsnprintf-posix-tests | 1 + modules/vsprintf-posix-tests | 1 + tests/test-ceilf1.c | 16 ++-------------- tests/test-floorf1.c | 16 ++-------------- tests/test-frexp.c | 14 +------------- tests/test-isnand.c | 17 +++-------------- tests/test-isnanf.c | 19 ++++--------------- tests/test-math.c | 10 ++++++++-- tests/test-round1.c | 16 ++-------------- tests/test-roundf1.c | 18 +++--------------- tests/test-snprintf-posix.h | 32 +++++++++++--------------------- tests/test-sprintf-posix.h | 30 ++++++++++-------------------- tests/test-trunc1.c | 14 +------------- tests/test-truncf1.c | 16 ++-------------- tests/test-vasnprintf-posix.c | 33 +++++++++++---------------------- tests/test-vasprintf-posix.c | 33 +++++++++++---------------------- 28 files changed, 139 insertions(+), 216 deletions(-) diff --git a/ChangeLog b/ChangeLog index 2202e8e..c02f097 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,34 @@ +2008-03-31 Eric Blake <[EMAIL PROTECTED]> + + Guarantee a definition of NAN. + * lib/math.in.h (NAN): Define if missing. + * tests/test-math.c (main): Test it. + * doc/posix-headers/math.texi (math.h): Document this. + * lib/isnan.c (rpl_isnand): Use it. + * tests/test-ceilf1.c (NaN): Delete, and use NAN instead. + * tests/test-floorf1.c (NaN): Likewise. + * tests/test-frexp.c (NaN): Likewise. + * tests/test-isnand.c (NaN): Likewise. + * tests/test-isnanf.c (NaN): Likewise. + * tests/test-round1.c (NaN): Likewise. + * tests/test-roundf1.c (NaN): Likewise. + * tests/test-snprintf-posix.h (NaN): Likewise. + * tests/test-sprintf-posix.h (NaN): Likewise. + * tests/test-trunc1.c (NaN): Likewise. + * tests/test-truncf1.c (NaN): Likewise. + * tests/test-vasnprintf-posix.c (NaN): Likewise. + * tests/test-vasprintf-posix.c (NaN): Likewise. + * modules/isnand-nolibm (Depends-on): Add math. + * modules/isnanf-nolibm (Depends-on): Likewise. + * modules/isnanl (Depends-on): Likewise. + * modules/isnanl-nolibm (Depends-on): Likewise. + * modules/snprintf-posix-tests (Depends-on): Likewise. + * modules/sprintf-posix-tests (Depends-on): Likewise. + * modules/vsnprintf-posix-tests (Depends-on): Likewise. + * modules/vsprintf-posix-tests (Depends-on): Likewise. + * modules/vasnprintf-posix-tests (Depends-on): Likewise. + * modules/vasprintf-posix-tests (Depends-on): Likewise. + 2008-03-31 Bruno Haible <[EMAIL PROTECTED]> * tests/test-strtod.c (main): Update results for OSF/1 platforms. diff --git a/doc/posix-headers/math.texi b/doc/posix-headers/math.texi index dde9cd0..a207e16 100644 --- a/doc/posix-headers/math.texi +++ b/doc/posix-headers/math.texi @@ -7,8 +7,14 @@ Gnulib module: math Portability problems fixed by Gnulib: @itemize [EMAIL PROTECTED] +Some platforms do not provide a definition of NAN: +Solaris 8. + @end itemize Portability problems not fixed by Gnulib: @itemize +NAN is not a compile time constant with some broken compilers: +Compaq (ex-DEC) C 6.4 @end itemize diff --git a/lib/isnan.c b/lib/isnan.c index a5ca38d..81f394d 100644 --- a/lib/isnan.c +++ b/lib/isnan.c @@ -19,6 +19,7 @@ #include <config.h> #include <float.h> +#include <math.h> #include <string.h> #include "float+.h" @@ -111,11 +112,10 @@ 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 = zero / zero; + nan.value = NAN; # else static memory_double nan = { L_(0.0) / L_(0.0) }; static DOUBLE plus_inf = L_(1.0) / L_(0.0); diff --git a/lib/math.in.h b/lib/math.in.h index c3515d7..bb715ae 100644 --- a/lib/math.in.h +++ b/lib/math.in.h @@ -1,6 +1,6 @@ /* A GNU-like <math.h>. - Copyright (C) 2002-2003, 2007 Free Software Foundation, Inc. + Copyright (C) 2002-2003, 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 @@ -32,6 +32,24 @@ extern "C" { #endif +/* POSIX allows platforms that don't support NAN. But all major + machines in the past 15 years have supported something close to + IEEE NaN, so we define this unconditionally. */ +#ifndef NAN + /* The Compaq (ex-DEC) C 6.4 compiler chokes on the expression 0.0 / 0.0. */ +# ifdef __DECC +static float +_NaN () +{ + static float zero = 0.0f; + return zero / zero; +} +# define NAN (_NaN()) +# else +# define NAN (0.0f / 0.0f) +# endif +#endif + /* Write x as x = mantissa * 2^exp where diff --git a/modules/isnand-nolibm b/modules/isnand-nolibm index 6bb8c7d..cab173d 100644 --- a/modules/isnand-nolibm +++ b/modules/isnand-nolibm @@ -10,6 +10,7 @@ m4/isnand.m4 Depends-on: fpieee +math configure.ac: gl_FUNC_ISNAND_NO_LIBM diff --git a/modules/isnanf-nolibm b/modules/isnanf-nolibm index 3f90629..1489e30 100644 --- a/modules/isnanf-nolibm +++ b/modules/isnanf-nolibm @@ -10,6 +10,7 @@ m4/isnanf.m4 Depends-on: fpieee +math configure.ac: gl_FUNC_ISNANF_NO_LIBM diff --git a/modules/isnanl b/modules/isnanl index 026981f..6ba1ee4 100644 --- a/modules/isnanl +++ b/modules/isnanl @@ -11,6 +11,7 @@ m4/isnanl.m4 Depends-on: float fpieee +math configure.ac: gl_FUNC_ISNANL diff --git a/modules/isnanl-nolibm b/modules/isnanl-nolibm index 9250fef..783dc77 100644 --- a/modules/isnanl-nolibm +++ b/modules/isnanl-nolibm @@ -11,6 +11,7 @@ m4/isnanl.m4 Depends-on: float fpieee +math configure.ac: gl_FUNC_ISNANL_NO_LIBM diff --git a/modules/snprintf-posix-tests b/modules/snprintf-posix-tests index 72303bd..3826051 100644 --- a/modules/snprintf-posix-tests +++ b/modules/snprintf-posix-tests @@ -4,6 +4,7 @@ tests/test-snprintf-posix.h tests/test-snprintf.c Depends-on: +math stdint configure.ac: diff --git a/modules/sprintf-posix-tests b/modules/sprintf-posix-tests index 69673d4..5df186a 100644 --- a/modules/sprintf-posix-tests +++ b/modules/sprintf-posix-tests @@ -3,6 +3,7 @@ tests/test-sprintf-posix.c tests/test-sprintf-posix.h Depends-on: +math stdint configure.ac: diff --git a/modules/vasnprintf-posix-tests b/modules/vasnprintf-posix-tests index 65c1351..d8a39d4 100644 --- a/modules/vasnprintf-posix-tests +++ b/modules/vasnprintf-posix-tests @@ -5,6 +5,7 @@ tests/test-vasnprintf-posix2.c m4/locale-fr.m4 Depends-on: +math stdint configure.ac: diff --git a/modules/vasprintf-posix-tests b/modules/vasprintf-posix-tests index 485e513..391c6a1 100644 --- a/modules/vasprintf-posix-tests +++ b/modules/vasprintf-posix-tests @@ -2,6 +2,7 @@ Files: tests/test-vasprintf-posix.c Depends-on: +math stdint configure.ac: diff --git a/modules/vsnprintf-posix-tests b/modules/vsnprintf-posix-tests index f60a7b6..1604b1e 100644 --- a/modules/vsnprintf-posix-tests +++ b/modules/vsnprintf-posix-tests @@ -4,6 +4,7 @@ tests/test-snprintf-posix.h tests/test-vsnprintf.c Depends-on: +math stdint configure.ac: diff --git a/modules/vsprintf-posix-tests b/modules/vsprintf-posix-tests index 37be4fc..7c42039 100644 --- a/modules/vsprintf-posix-tests +++ b/modules/vsprintf-posix-tests @@ -3,6 +3,7 @@ tests/test-vsprintf-posix.c tests/test-sprintf-posix.h Depends-on: +math stdint configure.ac: diff --git a/tests/test-ceilf1.c b/tests/test-ceilf1.c index 36a1163..b323227 100644 --- a/tests/test-ceilf1.c +++ b/tests/test-ceilf1.c @@ -1,5 +1,5 @@ /* Test of rounding towards positive infinity. - Copyright (C) 2007 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 @@ -36,18 +36,6 @@ } \ while (0) -/* The Compaq (ex-DEC) C 6.4 compiler chokes on the expression 0.0 / 0.0. */ -#ifdef __DECC -static float -NaN () -{ - static float zero = 0.0f; - return zero / zero; -} -#else -# define NaN() (0.0f / 0.0f) -#endif - int main () { @@ -79,7 +67,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 (NAN))); return 0; } diff --git a/tests/test-floorf1.c b/tests/test-floorf1.c index afd006b..a45bcfc 100644 --- a/tests/test-floorf1.c +++ b/tests/test-floorf1.c @@ -1,5 +1,5 @@ /* Test of rounding towards negative infinity. - Copyright (C) 2007 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 @@ -36,18 +36,6 @@ } \ while (0) -/* The Compaq (ex-DEC) C 6.4 compiler chokes on the expression 0.0 / 0.0. */ -#ifdef __DECC -static float -NaN () -{ - static float zero = 0.0f; - return zero / zero; -} -#else -# define NaN() (0.0f / 0.0f) -#endif - int main () { @@ -79,7 +67,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 (NAN))); return 0; } diff --git a/tests/test-frexp.c b/tests/test-frexp.c index 47db2be..cb80f56 100644 --- a/tests/test-frexp.c +++ b/tests/test-frexp.c @@ -37,18 +37,6 @@ } \ while (0) -/* The Compaq (ex-DEC) C 6.4 compiler chokes on the expression 0.0 / 0.0. */ -#ifdef __DECC -static double -NaN () -{ - static double zero = 0.0; - return zero / zero; -} -#else -# define NaN() (0.0 / 0.0) -#endif - static double my_ldexp (double x, int d) { @@ -73,7 +61,7 @@ main () { /* NaN. */ int exp = -9999; double mantissa; - x = NaN (); + x = NAN; mantissa = frexp (x, &exp); ASSERT (isnand (mantissa)); } diff --git a/tests/test-isnand.c b/tests/test-isnand.c index 0bc0a26..1dc9238 100644 --- a/tests/test-isnand.c +++ b/tests/test-isnand.c @@ -21,6 +21,7 @@ #include "isnand.h" #include <limits.h> +#include <math.h> #include <stdio.h> #include <stdlib.h> @@ -35,18 +36,6 @@ } \ while (0) -/* The Compaq (ex-DEC) C 6.4 compiler chokes on the expression 0.0 / 0.0. */ -#ifdef __DECC -static double -NaN () -{ - static double zero = 0.0; - return zero / zero; -} -#else -# define NaN() (0.0 / 0.0) -#endif - int main () { @@ -63,7 +52,7 @@ main () ASSERT (!isnand (1.0 / 0.0)); ASSERT (!isnand (-1.0 / 0.0)); /* Quiet NaN. */ - ASSERT (isnand (NaN ())); + ASSERT (isnand (NAN)); #if defined DBL_EXPBIT0_WORD && defined DBL_EXPBIT0_BIT /* Signalling NaN. */ { @@ -71,7 +60,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 = NAN; # 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 c433089..6c084ac 100644 --- a/tests/test-isnanf.c +++ b/tests/test-isnanf.c @@ -1,5 +1,5 @@ /* Test of isnanf() substitute. - Copyright (C) 2007 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,6 +21,7 @@ #include "isnanf.h" #include <limits.h> +#include <math.h> #include <stdio.h> #include <stdlib.h> @@ -35,18 +36,6 @@ } \ while (0) -/* The Compaq (ex-DEC) C 6.4 compiler chokes on the expression 0.0 / 0.0. */ -#ifdef __DECC -static float -NaN () -{ - static float zero = 0.0f; - return zero / zero; -} -#else -# define NaN() (0.0f / 0.0f) -#endif - int main () { @@ -63,7 +52,7 @@ main () ASSERT (!isnanf (1.0f / 0.0f)); ASSERT (!isnanf (-1.0f / 0.0f)); /* Quiet NaN. */ - ASSERT (isnanf (NaN ())); + ASSERT (isnanf (NAN)); #if defined FLT_EXPBIT0_WORD && defined FLT_EXPBIT0_BIT /* Signalling NaN. */ { @@ -71,7 +60,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 = NAN; # 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 893ca81..5c00581 100644 --- a/tests/test-math.c +++ b/tests/test-math.c @@ -1,5 +1,5 @@ /* Test of <math.h> substitute. - Copyright (C) 2007 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 @@ -20,8 +20,14 @@ #include <math.h> +#ifndef NAN +# error NAN should be defined +choke me +#endif + int main () { - return 0; + double d = NAN; + return d == d; } diff --git a/tests/test-round1.c b/tests/test-round1.c index 625b9ff..704e1da 100644 --- a/tests/test-round1.c +++ b/tests/test-round1.c @@ -3,7 +3,7 @@ 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 2, or (at your option) + the Free Software Foundation; either version 3, or (at your option) any later version. This program is distributed in the hope that it will be useful, @@ -38,18 +38,6 @@ } \ while (0) -/* The Compaq (ex-DEC) C 6.4 compiler chokes on the expression 0.0 / 0.0. */ -#ifdef __DECC -static double -NaN () -{ - static double zero = 0.0; - return zero / zero; -} -#else -# define NaN() (0.0 / 0.0) -#endif - int main () { @@ -86,7 +74,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 (NAN))); return 0; } diff --git a/tests/test-roundf1.c b/tests/test-roundf1.c index 67d5c7f..aeee3b1 100644 --- a/tests/test-roundf1.c +++ b/tests/test-roundf1.c @@ -1,9 +1,9 @@ /* Test of rounding to nearest, breaking ties away from zero. - Copyright (C) 2007 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 - the Free Software Foundation; either version 2, or (at your option) + the Free Software Foundation; either version 3, or (at your option) any later version. This program is distributed in the hope that it will be useful, @@ -38,18 +38,6 @@ } \ while (0) -/* The Compaq (ex-DEC) C 6.4 compiler chokes on the expression 0.0 / 0.0. */ -#ifdef __DECC -static float -NaN () -{ - static float zero = 0.0f; - return zero / zero; -} -#else -# define NaN() (0.0f / 0.0f) -#endif - int main () { @@ -86,7 +74,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 (NAN))); return 0; } diff --git a/tests/test-snprintf-posix.h b/tests/test-snprintf-posix.h index 94f5e67..4d69267 100644 --- a/tests/test-snprintf-posix.h +++ b/tests/test-snprintf-posix.h @@ -16,17 +16,7 @@ /* Written by Bruno Haible <[EMAIL PROTECTED]>, 2007. */ -/* The Compaq (ex-DEC) C 6.4 compiler chokes on the expression 0.0 / 0.0. */ -#ifdef __DECC -static double -NaN () -{ - static double zero = 0.0; - return zero / zero; -} -#else -# define NaN() (0.0 / 0.0) -#endif +#include <math.h> /* The SGI MIPS floating-point format does not distinguish 0.0 and -0.0. */ static int @@ -81,7 +71,7 @@ strisnan (const char *string, size_t start_index, size_t end_index, int uppercas } return 0; } - + static void test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) { @@ -207,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", NAN, 33, 44, 55); ASSERT (strlen (result) >= 3 + 3 && strisnan (result, 0, strlen (result) - 3, 0) && strcmp (result + strlen (result) - 3, " 33") == 0); @@ -404,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", NAN, 33, 44, 55); /* "0000000nan 33" is not a valid result; see <http://lists.gnu.org/archive/html/bug-gnulib/2007-04/msg00107.html> */ ASSERT (strlen (result) == 50 + 3 @@ -918,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", NAN, 33, 44, 55); ASSERT (strlen (result) >= 3 + 3 && strisnan (result, 0, strlen (result) - 3, 0) && strcmp (result + strlen (result) - 3, " 33") == 0); @@ -999,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", NAN, 33, 44, 55); ASSERT (strlen (result) == 50 + 3 && strisnan (result, strspn (result, " "), strlen (result) - 3, 0) && strcmp (result + strlen (result) - 3, " 33") == 0); @@ -1414,7 +1404,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", NAN, 33, 44, 55); ASSERT (strlen (result) >= 3 + 3 && strisnan (result, 0, strlen (result) - 3, 1) && strcmp (result + strlen (result) - 3, " 33") == 0); @@ -1708,7 +1698,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", NAN, 33, 44, 55); ASSERT (strlen (result) >= 3 + 3 && strisnan (result, 0, strlen (result) - 3, 0) && strcmp (result + strlen (result) - 3, " 33") == 0); @@ -1799,7 +1789,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", NAN, 33, 44, 55); ASSERT (strlen (result) == 50 + 3 && strisnan (result, strspn (result, " "), strlen (result) - 3, 0) && strcmp (result + strlen (result) - 3, " 33") == 0); @@ -2316,7 +2306,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", NAN, 33, 44, 55); ASSERT (strlen (result) >= 3 + 3 && strisnan (result, 0, strlen (result) - 3, 0) && strcmp (result + strlen (result) - 3, " 33") == 0); @@ -2400,7 +2390,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", NAN, 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 35e9d47..ac2afcf 100644 --- a/tests/test-sprintf-posix.h +++ b/tests/test-sprintf-posix.h @@ -16,17 +16,7 @@ /* Written by Bruno Haible <[EMAIL PROTECTED]>, 2007. */ -/* The Compaq (ex-DEC) C 6.4 compiler chokes on the expression 0.0 / 0.0. */ -#ifdef __DECC -static double -NaN () -{ - static double zero = 0.0; - return zero / zero; -} -#else -# define NaN() (0.0 / 0.0) -#endif +#include <math.h> /* The SGI MIPS floating-point format does not distinguish 0.0 and -0.0. */ static int @@ -193,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", NAN, 33, 44, 55); ASSERT (strlen (result) >= 3 + 3 && strisnan (result, 0, strlen (result) - 3, 0) && strcmp (result + strlen (result) - 3, " 33") == 0); @@ -390,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", NAN, 33, 44, 55); /* "0000000nan 33" is not a valid result; see <http://lists.gnu.org/archive/html/bug-gnulib/2007-04/msg00107.html> */ ASSERT (strlen (result) == 50 + 3 @@ -904,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", NAN, 33, 44, 55); ASSERT (strlen (result) >= 3 + 3 && strisnan (result, 0, strlen (result) - 3, 0) && strcmp (result + strlen (result) - 3, " 33") == 0); @@ -979,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", NAN, 33, 44, 55); ASSERT (strlen (result) == 50 + 3 && strisnan (result, strspn (result, " "), strlen (result) - 3, 0) && strcmp (result + strlen (result) - 3, " 33") == 0); @@ -1388,7 +1378,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", NAN, 33, 44, 55); ASSERT (strlen (result) >= 3 + 3 && strisnan (result, 0, strlen (result) - 3, 1) && strcmp (result + strlen (result) - 3, " 33") == 0); @@ -1682,7 +1672,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", NAN, 33, 44, 55); ASSERT (strlen (result) >= 3 + 3 && strisnan (result, 0, strlen (result) - 3, 0) && strcmp (result + strlen (result) - 3, " 33") == 0); @@ -1773,7 +1763,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", NAN, 33, 44, 55); ASSERT (strlen (result) == 50 + 3 && strisnan (result, strspn (result, " "), strlen (result) - 3, 0) && strcmp (result + strlen (result) - 3, " 33") == 0); @@ -2290,7 +2280,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", NAN, 33, 44, 55); ASSERT (strlen (result) >= 3 + 3 && strisnan (result, 0, strlen (result) - 3, 0) && strcmp (result + strlen (result) - 3, " 33") == 0); @@ -2374,7 +2364,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", NAN, 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 a2d6dd4..6b28363 100644 --- a/tests/test-trunc1.c +++ b/tests/test-trunc1.c @@ -36,18 +36,6 @@ } \ while (0) -/* The Compaq (ex-DEC) C 6.4 compiler chokes on the expression 0.0 / 0.0. */ -#ifdef __DECC -static double -NaN () -{ - static double zero = 0.0; - return zero / zero; -} -#else -# define NaN() (0.0 / 0.0) -#endif - int main () { @@ -78,7 +66,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 (NAN))); return 0; } diff --git a/tests/test-truncf1.c b/tests/test-truncf1.c index 8915f9f..9d36576 100644 --- a/tests/test-truncf1.c +++ b/tests/test-truncf1.c @@ -1,5 +1,5 @@ /* Test of rounding towards zero. - Copyright (C) 2007 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 @@ -36,18 +36,6 @@ } \ while (0) -/* The Compaq (ex-DEC) C 6.4 compiler chokes on the expression 0.0 / 0.0. */ -#ifdef __DECC -static float -NaN () -{ - static float zero = 0.0f; - return zero / zero; -} -#else -# define NaN() (0.0f / 0.0f) -#endif - int main () { @@ -78,7 +66,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 (NAN))); return 0; } diff --git a/tests/test-vasnprintf-posix.c b/tests/test-vasnprintf-posix.c index e947cc7..c29546a 100644 --- a/tests/test-vasnprintf-posix.c +++ b/tests/test-vasnprintf-posix.c @@ -21,6 +21,7 @@ #include "vasnprintf.h" #include <float.h> +#include <math.h> #include <stdarg.h> #include <stddef.h> #include <stdio.h> @@ -40,18 +41,6 @@ } \ while (0) -/* The Compaq (ex-DEC) C 6.4 compiler chokes on the expression 0.0 / 0.0. */ -#ifdef __DECC -static double -NaN () -{ - static double zero = 0.0; - return zero / zero; -} -#else -# define NaN() (0.0 / 0.0) -#endif - /* The SGI MIPS floating-point format does not distinguish 0.0 and -0.0. */ static int have_minus_zero () @@ -105,7 +94,7 @@ strisnan (const char *string, size_t start_index, size_t end_index, int uppercas } return 0; } - + static void test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) { @@ -257,7 +246,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", NAN, 33, 44, 55); ASSERT (result != NULL); ASSERT (strlen (result) >= 3 + 3 && strisnan (result, 0, strlen (result) - 3, 0) @@ -490,7 +479,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", NAN, 33, 44, 55); ASSERT (result != NULL); /* "0000000nan 33" is not a valid result; see <http://lists.gnu.org/archive/html/bug-gnulib/2007-04/msg00107.html> */ @@ -1086,7 +1075,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", NAN, 33, 44, 55); ASSERT (result != NULL); ASSERT (strlen (result) >= 3 + 3 && strisnan (result, 0, strlen (result) - 3, 0) @@ -1179,7 +1168,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", NAN, 33, 44, 55); ASSERT (result != NULL); ASSERT (strlen (result) == 50 + 3 && strisnan (result, strspn (result, " "), strlen (result) - 3, 0) @@ -1658,7 +1647,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", NAN, 33, 44, 55); ASSERT (result != NULL); ASSERT (strlen (result) >= 3 + 3 && strisnan (result, 0, strlen (result) - 3, 1) @@ -1997,7 +1986,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", NAN, 33, 44, 55); ASSERT (result != NULL); ASSERT (strlen (result) >= 3 + 3 && strisnan (result, 0, strlen (result) - 3, 0) @@ -2108,7 +2097,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", NAN, 33, 44, 55); ASSERT (result != NULL); ASSERT (strlen (result) == 50 + 3 && strisnan (result, strspn (result, " "), strlen (result) - 3, 0) @@ -2699,7 +2688,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", NAN, 33, 44, 55); ASSERT (result != NULL); ASSERT (strlen (result) >= 3 + 3 && strisnan (result, 0, strlen (result) - 3, 0) @@ -2803,7 +2792,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", NAN, 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 68da28c..806ce74 100644 --- a/tests/test-vasprintf-posix.c +++ b/tests/test-vasprintf-posix.c @@ -21,6 +21,7 @@ #include <stdio.h> #include <float.h> +#include <math.h> #include <stdarg.h> #include <stddef.h> #include <stdio.h> @@ -40,18 +41,6 @@ } \ while (0) -/* The Compaq (ex-DEC) C 6.4 compiler chokes on the expression 0.0 / 0.0. */ -#ifdef __DECC -static double -NaN () -{ - static double zero = 0.0; - return zero / zero; -} -#else -# define NaN() (0.0 / 0.0) -#endif - /* The SGI MIPS floating-point format does not distinguish 0.0 and -0.0. */ static int have_minus_zero () @@ -105,7 +94,7 @@ strisnan (const char *string, size_t start_index, size_t end_index, int uppercas } return 0; } - + static void test_function (int (*my_asprintf) (char **, const char *, ...)) { @@ -238,7 +227,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", NAN, 33, 44, 55); ASSERT (result != NULL); ASSERT (strlen (result) >= 3 + 3 && strisnan (result, 0, strlen (result) - 3, 0) @@ -471,7 +460,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", NAN, 33, 44, 55); ASSERT (result != NULL); /* "0000000nan 33" is not a valid result; see <http://lists.gnu.org/archive/html/bug-gnulib/2007-04/msg00107.html> */ @@ -1067,7 +1056,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", NAN, 33, 44, 55); ASSERT (result != NULL); ASSERT (strlen (result) >= 3 + 3 && strisnan (result, 0, strlen (result) - 3, 0) @@ -1160,7 +1149,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", NAN, 33, 44, 55); ASSERT (result != NULL); ASSERT (strlen (result) == 50 + 3 && strisnan (result, strspn (result, " "), strlen (result) - 3, 0) @@ -1639,7 +1628,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", NAN, 33, 44, 55); ASSERT (result != NULL); ASSERT (strlen (result) >= 3 + 3 && strisnan (result, 0, strlen (result) - 3, 1) @@ -1978,7 +1967,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", NAN, 33, 44, 55); ASSERT (result != NULL); ASSERT (strlen (result) >= 3 + 3 && strisnan (result, 0, strlen (result) - 3, 0) @@ -2089,7 +2078,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", NAN, 33, 44, 55); ASSERT (result != NULL); ASSERT (strlen (result) == 50 + 3 && strisnan (result, strspn (result, " "), strlen (result) - 3, 0) @@ -2680,7 +2669,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", NAN, 33, 44, 55); ASSERT (result != NULL); ASSERT (strlen (result) >= 3 + 3 && strisnan (result, 0, strlen (result) - 3, 0) @@ -2784,7 +2773,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", NAN, 33, 44, 55); ASSERT (result != NULL); ASSERT (strlen (result) == 50 + 3 && strisnan (result, strspn (result, " "), strlen (result) - 3, 0) -- 1.5.4