comparison tests/test-vasnprintf-posix.c @ 9850:7f3ed6b093be

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 <ebb9@byu.net>
author Eric Blake <ebb9@byu.net>
date Mon, 31 Mar 2008 20:56:25 -0600
parents b69f1141e94f
children baba3b346ab2
comparison
equal deleted inserted replaced
9849:ab48b8591214 9850:7f3ed6b093be
19 #include <config.h> 19 #include <config.h>
20 20
21 #include "vasnprintf.h" 21 #include "vasnprintf.h"
22 22
23 #include <float.h> 23 #include <float.h>
24 #include <math.h>
24 #include <stdarg.h> 25 #include <stdarg.h>
25 #include <stddef.h> 26 #include <stddef.h>
26 #include <stdio.h> 27 #include <stdio.h>
27 #include <stdint.h> 28 #include <stdint.h>
28 #include <stdlib.h> 29 #include <stdlib.h>
37 fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ 38 fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \
38 abort (); \ 39 abort (); \
39 } \ 40 } \
40 } \ 41 } \
41 while (0) 42 while (0)
42
43 /* The Compaq (ex-DEC) C 6.4 compiler chokes on the expression 0.0 / 0.0. */
44 #ifdef __DECC
45 static double
46 NaN ()
47 {
48 static double zero = 0.0;
49 return zero / zero;
50 }
51 #else
52 # define NaN() (0.0 / 0.0)
53 #endif
54 43
55 /* The SGI MIPS floating-point format does not distinguish 0.0 and -0.0. */ 44 /* The SGI MIPS floating-point format does not distinguish 0.0 and -0.0. */
56 static int 45 static int
57 have_minus_zero () 46 have_minus_zero ()
58 { 47 {
103 return 1; 92 return 1;
104 } 93 }
105 } 94 }
106 return 0; 95 return 0;
107 } 96 }
108 97
109 static void 98 static void
110 test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) 99 test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...))
111 { 100 {
112 char buf[8]; 101 char buf[8];
113 int size; 102 int size;
255 } 244 }
256 245
257 { /* NaN. */ 246 { /* NaN. */
258 size_t length; 247 size_t length;
259 char *result = 248 char *result =
260 my_asnprintf (NULL, &length, "%a %d", NaN (), 33, 44, 55); 249 my_asnprintf (NULL, &length, "%a %d", NAN, 33, 44, 55);
261 ASSERT (result != NULL); 250 ASSERT (result != NULL);
262 ASSERT (strlen (result) >= 3 + 3 251 ASSERT (strlen (result) >= 3 + 3
263 && strisnan (result, 0, strlen (result) - 3, 0) 252 && strisnan (result, 0, strlen (result) - 3, 0)
264 && strcmp (result + strlen (result) - 3, " 33") == 0); 253 && strcmp (result + strlen (result) - 3, " 33") == 0);
265 ASSERT (length == strlen (result)); 254 ASSERT (length == strlen (result));
488 } 477 }
489 478
490 { /* FLAG_ZERO with NaN. */ 479 { /* FLAG_ZERO with NaN. */
491 size_t length; 480 size_t length;
492 char *result = 481 char *result =
493 my_asnprintf (NULL, &length, "%050a %d", NaN (), 33, 44, 55); 482 my_asnprintf (NULL, &length, "%050a %d", NAN, 33, 44, 55);
494 ASSERT (result != NULL); 483 ASSERT (result != NULL);
495 /* "0000000nan 33" is not a valid result; see 484 /* "0000000nan 33" is not a valid result; see
496 <http://lists.gnu.org/archive/html/bug-gnulib/2007-04/msg00107.html> */ 485 <http://lists.gnu.org/archive/html/bug-gnulib/2007-04/msg00107.html> */
497 ASSERT (strlen (result) == 50 + 3 486 ASSERT (strlen (result) == 50 + 3
498 && strisnan (result, strspn (result, " "), strlen (result) - 3, 0) 487 && strisnan (result, strspn (result, " "), strlen (result) - 3, 0)
1084 } 1073 }
1085 1074
1086 { /* NaN. */ 1075 { /* NaN. */
1087 size_t length; 1076 size_t length;
1088 char *result = 1077 char *result =
1089 my_asnprintf (NULL, &length, "%f %d", NaN (), 33, 44, 55); 1078 my_asnprintf (NULL, &length, "%f %d", NAN, 33, 44, 55);
1090 ASSERT (result != NULL); 1079 ASSERT (result != NULL);
1091 ASSERT (strlen (result) >= 3 + 3 1080 ASSERT (strlen (result) >= 3 + 3
1092 && strisnan (result, 0, strlen (result) - 3, 0) 1081 && strisnan (result, 0, strlen (result) - 3, 0)
1093 && strcmp (result + strlen (result) - 3, " 33") == 0); 1082 && strcmp (result + strlen (result) - 3, " 33") == 0);
1094 ASSERT (length == strlen (result)); 1083 ASSERT (length == strlen (result));
1177 } 1166 }
1178 1167
1179 { /* FLAG_ZERO with NaN. */ 1168 { /* FLAG_ZERO with NaN. */
1180 size_t length; 1169 size_t length;
1181 char *result = 1170 char *result =
1182 my_asnprintf (NULL, &length, "%050f %d", NaN (), 33, 44, 55); 1171 my_asnprintf (NULL, &length, "%050f %d", NAN, 33, 44, 55);
1183 ASSERT (result != NULL); 1172 ASSERT (result != NULL);
1184 ASSERT (strlen (result) == 50 + 3 1173 ASSERT (strlen (result) == 50 + 3
1185 && strisnan (result, strspn (result, " "), strlen (result) - 3, 0) 1174 && strisnan (result, strspn (result, " "), strlen (result) - 3, 0)
1186 && strcmp (result + strlen (result) - 3, " 33") == 0); 1175 && strcmp (result + strlen (result) - 3, " 33") == 0);
1187 ASSERT (length == strlen (result)); 1176 ASSERT (length == strlen (result));
1656 } 1645 }
1657 1646
1658 { /* NaN. */ 1647 { /* NaN. */
1659 size_t length; 1648 size_t length;
1660 char *result = 1649 char *result =
1661 my_asnprintf (NULL, &length, "%F %d", NaN (), 33, 44, 55); 1650 my_asnprintf (NULL, &length, "%F %d", NAN, 33, 44, 55);
1662 ASSERT (result != NULL); 1651 ASSERT (result != NULL);
1663 ASSERT (strlen (result) >= 3 + 3 1652 ASSERT (strlen (result) >= 3 + 3
1664 && strisnan (result, 0, strlen (result) - 3, 1) 1653 && strisnan (result, 0, strlen (result) - 3, 1)
1665 && strcmp (result + strlen (result) - 3, " 33") == 0); 1654 && strcmp (result + strlen (result) - 3, " 33") == 0);
1666 ASSERT (length == strlen (result)); 1655 ASSERT (length == strlen (result));
1995 } 1984 }
1996 1985
1997 { /* NaN. */ 1986 { /* NaN. */
1998 size_t length; 1987 size_t length;
1999 char *result = 1988 char *result =
2000 my_asnprintf (NULL, &length, "%e %d", NaN (), 33, 44, 55); 1989 my_asnprintf (NULL, &length, "%e %d", NAN, 33, 44, 55);
2001 ASSERT (result != NULL); 1990 ASSERT (result != NULL);
2002 ASSERT (strlen (result) >= 3 + 3 1991 ASSERT (strlen (result) >= 3 + 3
2003 && strisnan (result, 0, strlen (result) - 3, 0) 1992 && strisnan (result, 0, strlen (result) - 3, 0)
2004 && strcmp (result + strlen (result) - 3, " 33") == 0); 1993 && strcmp (result + strlen (result) - 3, " 33") == 0);
2005 ASSERT (length == strlen (result)); 1994 ASSERT (length == strlen (result));
2106 } 2095 }
2107 2096
2108 { /* FLAG_ZERO with NaN. */ 2097 { /* FLAG_ZERO with NaN. */
2109 size_t length; 2098 size_t length;
2110 char *result = 2099 char *result =
2111 my_asnprintf (NULL, &length, "%050e %d", NaN (), 33, 44, 55); 2100 my_asnprintf (NULL, &length, "%050e %d", NAN, 33, 44, 55);
2112 ASSERT (result != NULL); 2101 ASSERT (result != NULL);
2113 ASSERT (strlen (result) == 50 + 3 2102 ASSERT (strlen (result) == 50 + 3
2114 && strisnan (result, strspn (result, " "), strlen (result) - 3, 0) 2103 && strisnan (result, strspn (result, " "), strlen (result) - 3, 0)
2115 && strcmp (result + strlen (result) - 3, " 33") == 0); 2104 && strcmp (result + strlen (result) - 3, " 33") == 0);
2116 ASSERT (length == strlen (result)); 2105 ASSERT (length == strlen (result));
2697 } 2686 }
2698 2687
2699 { /* NaN. */ 2688 { /* NaN. */
2700 size_t length; 2689 size_t length;
2701 char *result = 2690 char *result =
2702 my_asnprintf (NULL, &length, "%g %d", NaN (), 33, 44, 55); 2691 my_asnprintf (NULL, &length, "%g %d", NAN, 33, 44, 55);
2703 ASSERT (result != NULL); 2692 ASSERT (result != NULL);
2704 ASSERT (strlen (result) >= 3 + 3 2693 ASSERT (strlen (result) >= 3 + 3
2705 && strisnan (result, 0, strlen (result) - 3, 0) 2694 && strisnan (result, 0, strlen (result) - 3, 0)
2706 && strcmp (result + strlen (result) - 3, " 33") == 0); 2695 && strcmp (result + strlen (result) - 3, " 33") == 0);
2707 ASSERT (length == strlen (result)); 2696 ASSERT (length == strlen (result));
2801 } 2790 }
2802 2791
2803 { /* FLAG_ZERO with NaN. */ 2792 { /* FLAG_ZERO with NaN. */
2804 size_t length; 2793 size_t length;
2805 char *result = 2794 char *result =
2806 my_asnprintf (NULL, &length, "%050g %d", NaN (), 33, 44, 55); 2795 my_asnprintf (NULL, &length, "%050g %d", NAN, 33, 44, 55);
2807 ASSERT (result != NULL); 2796 ASSERT (result != NULL);
2808 ASSERT (strlen (result) == 50 + 3 2797 ASSERT (strlen (result) == 50 + 3
2809 && strisnan (result, strspn (result, " "), strlen (result) - 3, 0) 2798 && strisnan (result, strspn (result, " "), strlen (result) - 3, 0)
2810 && strcmp (result + strlen (result) - 3, " 33") == 0); 2799 && strcmp (result + strlen (result) - 3, " 33") == 0);
2811 ASSERT (length == strlen (result)); 2800 ASSERT (length == strlen (result));