From: Bruno Haible Date: Sun, 25 Mar 2007 19:56:22 +0000 (+0000) Subject: Work around a DEC C compiler bug. X-Git-Tag: cvs-readonly~675 X-Git-Url: http://erislabs.org.uk/gitweb/?a=commitdiff_plain;h=6136fd62a3342532f17ccfd5f24db97764978448;p=gnulib.git Work around a DEC C compiler bug. --- diff --git a/ChangeLog b/ChangeLog index ff4bf3c48..842ecccc7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,22 @@ 2007-03-25 Bruno Haible + * tests/test-frexp.c (NaN): New function/macro. + (main): Use it instead of 0.0 / 0.0. + * tests/test-isnan.c (NaN): New function/macro. + (main): Use it instead of 0.0 / 0.0. + * tests/test-vasnprintf-posix.c (NaN): New function/macro. + (test_function): Use it instead of 0.0 / 0.0. + * tests/test-vasprintf-posix.c (NaN): New function/macro. + (test_function): Use it instead of 0.0 / 0.0. + * tests/test-snprintf-posix.h (NaN): New function/macro. + (test_function): Use it instead of 0.0 / 0.0. + * tests/test-sprintf-posix.h (NaN): New function/macro. + (test_function): Use it instead of 0.0 / 0.0. + * tests/test-fprintf-posix.h (NaN): New function/macro. + (test_function): Use it instead of 0.0 / 0.0. + * tests/test-printf-posix.h (NaN): New function/macro. + (test_function): Use it instead of 0.0 / 0.0. + * lib/isnan.c (FUNC): Work around a DEC C compiler bug. 2007-03-25 Bruno Haible diff --git a/tests/test-fprintf-posix.h b/tests/test-fprintf-posix.h index 9f1e3fa8e..2d5eb9303 100644 --- a/tests/test-fprintf-posix.h +++ b/tests/test-fprintf-posix.h @@ -17,6 +17,18 @@ /* Written by Bruno Haible , 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 + static void test_function (int (*my_fprintf) (FILE *, const char *, ...)) { @@ -47,13 +59,13 @@ test_function (int (*my_fprintf) (FILE *, const char *, ...)) my_fprintf (stdout, "%a %d\n", -1.0 / 0.0, 33, 44, 55); /* NaN. */ - my_fprintf (stdout, "%a %d\n", 0.0 / 0.0, 33, 44, 55); + my_fprintf (stdout, "%a %d\n", NaN (), 33, 44, 55); /* FLAG_ZERO with infinite number. */ my_fprintf (stdout, "%010a %d\n", 1.0 / 0.0, 33, 44, 55); /* FLAG_ZERO with NaN. */ - my_fprintf (stdout, "%010a %d\n", 0.0 / 0.0, 33, 44, 55); + my_fprintf (stdout, "%010a %d\n", NaN (), 33, 44, 55); /* Test the support of the POSIX/XSI format strings with positions. */ diff --git a/tests/test-frexp.c b/tests/test-frexp.c index 3c2ea806b..912ba200c 100644 --- a/tests/test-frexp.c +++ b/tests/test-frexp.c @@ -26,6 +26,18 @@ #define ASSERT(expr) if (!(expr)) abort (); +/* 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) { @@ -50,7 +62,7 @@ main () { /* NaN. */ int exp = -9999; double mantissa; - x = 0.0 / 0.0; + x = NaN (); mantissa = frexp (x, &exp); ASSERT (mantissa != mantissa); } diff --git a/tests/test-isnan.c b/tests/test-isnan.c index 445c30a3f..0897a55b3 100644 --- a/tests/test-isnan.c +++ b/tests/test-isnan.c @@ -26,6 +26,18 @@ #define ASSERT(expr) if (!(expr)) abort (); +/* 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 () { @@ -40,7 +52,7 @@ main () ASSERT (!isnan (1.0 / 0.0)); ASSERT (!isnan (-1.0 / 0.0)); /* Quiet NaN. */ - ASSERT (isnan (0.0 / 0.0)); + ASSERT (isnan (NaN ())); #if defined DBL_EXPBIT0_WORD && defined DBL_EXPBIT0_BIT /* Signalling NaN. */ { @@ -48,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 = 0.0 / 0.0; + 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-printf-posix.h b/tests/test-printf-posix.h index 04d3e550d..cd79a93c3 100644 --- a/tests/test-printf-posix.h +++ b/tests/test-printf-posix.h @@ -17,6 +17,18 @@ /* Written by Bruno Haible , 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 + static void test_function (int (*my_printf) (const char *, ...)) { @@ -47,13 +59,13 @@ test_function (int (*my_printf) (const char *, ...)) my_printf ("%a %d\n", -1.0 / 0.0, 33, 44, 55); /* NaN. */ - my_printf ("%a %d\n", 0.0 / 0.0, 33, 44, 55); + my_printf ("%a %d\n", NaN (), 33, 44, 55); /* FLAG_ZERO with infinite number. */ my_printf ("%010a %d\n", 1.0 / 0.0, 33, 44, 55); /* FLAG_ZERO with NaN. */ - my_printf ("%010a %d\n", 0.0 / 0.0, 33, 44, 55); + my_printf ("%010a %d\n", NaN (), 33, 44, 55); /* Test the support of the POSIX/XSI format strings with positions. */ diff --git a/tests/test-snprintf-posix.h b/tests/test-snprintf-posix.h index a32e33d8d..52ad5ece8 100644 --- a/tests/test-snprintf-posix.h +++ b/tests/test-snprintf-posix.h @@ -17,6 +17,18 @@ /* Written by Bruno Haible , 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 + static void test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) { @@ -143,7 +155,7 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) { /* NaN. */ char result[100]; int retval = - my_snprintf (result, sizeof (result), "%a %d", 0.0 / 0.0, 33, 44, 55); + my_snprintf (result, sizeof (result), "%a %d", NaN (), 33, 44, 55); ASSERT (strcmp (result, "nan 33") == 0); ASSERT (retval == strlen (result)); } @@ -336,7 +348,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), "%010a %d", 0.0 / 0.0, 33, 44, 55); + my_snprintf (result, sizeof (result), "%010a %d", NaN (), 33, 44, 55); ASSERT (strcmp (result, " nan 33") == 0); ASSERT (retval == strlen (result)); } diff --git a/tests/test-sprintf-posix.h b/tests/test-sprintf-posix.h index 1efd931e7..b5153c528 100644 --- a/tests/test-sprintf-posix.h +++ b/tests/test-sprintf-posix.h @@ -17,6 +17,18 @@ /* Written by Bruno Haible , 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 + static void test_function (int (*my_sprintf) (char *, const char *, ...)) { @@ -129,7 +141,7 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) { /* NaN. */ char result[1000]; int retval = - my_sprintf (result, "%a %d", 0.0 / 0.0, 33, 44, 55); + my_sprintf (result, "%a %d", NaN (), 33, 44, 55); ASSERT (strcmp (result, "nan 33") == 0); ASSERT (retval == strlen (result)); } @@ -322,7 +334,7 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) { /* FLAG_ZERO with NaN. */ char result[1000]; int retval = - my_sprintf (result, "%010a %d", 0.0 / 0.0, 33, 44, 55); + my_sprintf (result, "%010a %d", NaN (), 33, 44, 55); ASSERT (strcmp (result, " nan 33") == 0); ASSERT (retval == strlen (result)); } diff --git a/tests/test-vasnprintf-posix.c b/tests/test-vasnprintf-posix.c index 791d6c72c..9b3785c8d 100644 --- a/tests/test-vasnprintf-posix.c +++ b/tests/test-vasnprintf-posix.c @@ -31,6 +31,18 @@ #define ASSERT(expr) if (!(expr)) abort (); +/* 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 void test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) { @@ -183,7 +195,7 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) { /* NaN. */ size_t length; char *result = - my_asnprintf (NULL, &length, "%a %d", 0.0 / 0.0, 33, 44, 55); + my_asnprintf (NULL, &length, "%a %d", NaN (), 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "nan 33") == 0); ASSERT (length == strlen (result)); @@ -412,7 +424,7 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) { /* FLAG_ZERO with NaN. */ size_t length; char *result = - my_asnprintf (NULL, &length, "%010a %d", 0.0 / 0.0, 33, 44, 55); + my_asnprintf (NULL, &length, "%010a %d", NaN (), 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, " nan 33") == 0); ASSERT (length == strlen (result)); diff --git a/tests/test-vasprintf-posix.c b/tests/test-vasprintf-posix.c index 5b4389127..f903efb15 100644 --- a/tests/test-vasprintf-posix.c +++ b/tests/test-vasprintf-posix.c @@ -31,6 +31,18 @@ #define ASSERT(expr) if (!(expr)) abort (); +/* 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 void test_function (int (*my_asprintf) (char **, const char *, ...)) { @@ -164,7 +176,7 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) { /* NaN. */ char *result; int retval = - my_asprintf (&result, "%a %d", 0.0 / 0.0, 33, 44, 55); + my_asprintf (&result, "%a %d", NaN (), 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "nan 33") == 0); ASSERT (retval == strlen (result)); @@ -393,7 +405,7 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) { /* FLAG_ZERO with NaN. */ char *result; int retval = - my_asprintf (&result, "%010a %d", 0.0 / 0.0, 33, 44, 55); + my_asprintf (&result, "%010a %d", NaN (), 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, " nan 33") == 0); ASSERT (retval == strlen (result));