Update powerpc-fpu ULPs.
[glibc.git] / stdio-common / tstdiomisc.c
blob2e0663a5e5a22b211b3e952c67920a495391cb5d
1 #include <float.h>
2 #include <math.h>
3 #include <stdio.h>
4 #include <string.h>
5 #include <wchar.h>
7 static int
8 t1 (void)
10 int n = -1;
11 sscanf ("abc ", "abc %n", &n);
12 printf ("t1: count=%d\n", n);
14 return n != 5;
17 static int
18 t2 (void)
20 int result = 0;
21 int n;
22 long N;
23 int retval;
24 #define SCAN(INPUT, FORMAT, VAR, EXP_RES, EXP_VAL) \
25 VAR = -1; \
26 retval = sscanf (INPUT, FORMAT, &VAR); \
27 printf ("sscanf (\"%s\", \"%s\", &x) => %d, x = %ld\n", \
28 INPUT, FORMAT, retval, (long int) VAR); \
29 result |= retval != EXP_RES || VAR != EXP_VAL
31 SCAN ("12345", "%ld", N, 1, 12345);
32 SCAN ("12345", "%llllld", N, 0, -1);
33 SCAN ("12345", "%LLLLLd", N, 0, -1);
34 SCAN ("test ", "%*s%n", n, 0, 4);
35 SCAN ("test ", "%2*s%n", n, 0, -1);
36 SCAN ("12 ", "%l2d", n, 0, -1);
37 SCAN ("12 ", "%2ld", N, 1, 12);
39 n = -1;
40 N = -1;
41 retval = sscanf ("1 1", "%d %Z", &n, &N);
42 printf ("sscanf (\"1 1\", \"%%d %%Z\", &n, &N) => %d, n = %d, N = %ld\n", \
43 retval, n, N); \
44 result |= retval != 1 || n != 1 || N != -1;
46 return result;
49 static int
50 t3 (void)
52 char buf[80];
53 wchar_t wbuf[80];
54 int result = 0;
55 int retval;
57 retval = sprintf (buf, "%p", (char *) NULL);
58 result |= retval != 5 || strcmp (buf, "(nil)") != 0;
60 retval = swprintf (wbuf, sizeof (wbuf) / sizeof (wbuf[0]),
61 L"%p", (char *) NULL);
62 result |= retval != 5 || wcscmp (wbuf, L"(nil)") != 0;
64 return result;
67 volatile double qnanval;
68 volatile long double lqnanval;
69 /* A sNaN is only guaranteed to be representable in variables with static (or
70 thread-local) storage duration. */
71 static volatile double snanval = __builtin_nans ("");
72 static volatile double msnanval = -__builtin_nans ("");
73 static volatile long double lsnanval = __builtin_nansl ("");
74 static volatile long double lmsnanval = -__builtin_nansl ("");
75 volatile double infval;
76 volatile long double linfval;
79 static int
80 F (void)
82 char buf[80];
83 wchar_t wbuf[40];
84 int result = 0;
86 qnanval = NAN;
88 snprintf (buf, sizeof buf, "%a %A %e %E %f %F %g %G",
89 qnanval, qnanval, qnanval, qnanval,
90 qnanval, qnanval, qnanval, qnanval);
91 result |= strcmp (buf, "nan NAN nan NAN nan NAN nan NAN") != 0;
92 printf ("expected \"nan NAN nan NAN nan NAN nan NAN\", got \"%s\"\n", buf);
94 snprintf (buf, sizeof buf, "%a %A %e %E %f %F %g %G",
95 -qnanval, -qnanval, -qnanval, -qnanval,
96 -qnanval, -qnanval, -qnanval, -qnanval);
97 result |= strcmp (buf, "-nan -NAN -nan -NAN -nan -NAN -nan -NAN") != 0;
98 printf ("expected \"-nan -NAN -nan -NAN -nan -NAN -nan -NAN\", got \"%s\"\n",
99 buf);
101 snprintf (buf, sizeof buf, "%a %A %e %E %f %F %g %G",
102 snanval, snanval, snanval, snanval,
103 snanval, snanval, snanval, snanval);
104 result |= strcmp (buf, "nan NAN nan NAN nan NAN nan NAN") != 0;
105 printf ("expected \"nan NAN nan NAN nan NAN nan NAN\", got \"%s\"\n", buf);
107 snprintf (buf, sizeof buf, "%a %A %e %E %f %F %g %G",
108 msnanval, msnanval, msnanval, msnanval,
109 msnanval, msnanval, msnanval, msnanval);
110 result |= strcmp (buf, "-nan -NAN -nan -NAN -nan -NAN -nan -NAN") != 0;
111 printf ("expected \"-nan -NAN -nan -NAN -nan -NAN -nan -NAN\", got \"%s\"\n",
112 buf);
114 infval = DBL_MAX * DBL_MAX;
116 snprintf (buf, sizeof buf, "%a %A %e %E %f %F %g %G",
117 infval, infval, infval, infval, infval, infval, infval, infval);
118 result |= strcmp (buf, "inf INF inf INF inf INF inf INF") != 0;
119 printf ("expected \"inf INF inf INF inf INF inf INF\", got \"%s\"\n", buf);
121 snprintf (buf, sizeof buf, "%a %A %e %E %f %F %g %G",
122 -infval, -infval, -infval, -infval,
123 -infval, -infval, -infval, -infval);
124 result |= strcmp (buf, "-inf -INF -inf -INF -inf -INF -inf -INF") != 0;
125 printf ("expected \"-inf -INF -inf -INF -inf -INF -inf -INF\", got \"%s\"\n",
126 buf);
128 swprintf (wbuf, sizeof wbuf / sizeof (wbuf[0]), L"%a %A %e %E %f %F %g %G",
129 qnanval, qnanval, qnanval, qnanval,
130 qnanval, qnanval, qnanval, qnanval);
131 result |= wcscmp (wbuf, L"nan NAN nan NAN nan NAN nan NAN") != 0;
132 printf ("expected L\"nan NAN nan NAN nan NAN nan NAN\", got L\"%S\"\n", wbuf);
134 swprintf (wbuf, sizeof wbuf / sizeof (wbuf[0]), L"%a %A %e %E %f %F %g %G",
135 -qnanval, -qnanval, -qnanval, -qnanval,
136 -qnanval, -qnanval, -qnanval, -qnanval);
137 result |= wcscmp (wbuf, L"-nan -NAN -nan -NAN -nan -NAN -nan -NAN") != 0;
138 printf ("expected L\"-nan -NAN -nan -NAN -nan -NAN -nan -NAN\", got L\"%S\"\n",
139 wbuf);
141 swprintf (wbuf, sizeof wbuf / sizeof (wbuf[0]), L"%a %A %e %E %f %F %g %G",
142 snanval, snanval, snanval, snanval,
143 snanval, snanval, snanval, snanval);
144 result |= wcscmp (wbuf, L"nan NAN nan NAN nan NAN nan NAN") != 0;
145 printf ("expected L\"nan NAN nan NAN nan NAN nan NAN\", got L\"%S\"\n", wbuf);
147 swprintf (wbuf, sizeof wbuf / sizeof (wbuf[0]), L"%a %A %e %E %f %F %g %G",
148 msnanval, msnanval, msnanval, msnanval,
149 msnanval, msnanval, msnanval, msnanval);
150 result |= wcscmp (wbuf, L"-nan -NAN -nan -NAN -nan -NAN -nan -NAN") != 0;
151 printf ("expected L\"-nan -NAN -nan -NAN -nan -NAN -nan -NAN\", got L\"%S\"\n",
152 wbuf);
154 swprintf (wbuf, sizeof wbuf / sizeof (wbuf[0]), L"%a %A %e %E %f %F %g %G",
155 infval, infval, infval, infval, infval, infval, infval, infval);
156 result |= wcscmp (wbuf, L"inf INF inf INF inf INF inf INF") != 0;
157 printf ("expected L\"inf INF inf INF inf INF inf INF\", got L\"%S\"\n", wbuf);
159 swprintf (wbuf, sizeof wbuf / sizeof (wbuf[0]), L"%a %A %e %E %f %F %g %G",
160 -infval, -infval, -infval, -infval,
161 -infval, -infval, -infval, -infval);
162 result |= wcscmp (wbuf, L"-inf -INF -inf -INF -inf -INF -inf -INF") != 0;
163 printf ("expected L\"-inf -INF -inf -INF -inf -INF -inf -INF\", got L\"%S\"\n",
164 wbuf);
166 lqnanval = NAN;
168 snprintf (buf, sizeof buf, "%La %LA %Le %LE %Lf %LF %Lg %LG",
169 lqnanval, lqnanval, lqnanval, lqnanval,
170 lqnanval, lqnanval, lqnanval, lqnanval);
171 result |= strcmp (buf, "nan NAN nan NAN nan NAN nan NAN") != 0;
172 printf ("expected \"nan NAN nan NAN nan NAN nan NAN\", got \"%s\"\n", buf);
174 snprintf (buf, sizeof buf, "%La %LA %Le %LE %Lf %LF %Lg %LG",
175 -lqnanval, -lqnanval, -lqnanval, -lqnanval,
176 -lqnanval, -lqnanval, -lqnanval, -lqnanval);
177 result |= strcmp (buf, "-nan -NAN -nan -NAN -nan -NAN -nan -NAN") != 0;
178 printf ("expected \"-nan -NAN -nan -NAN -nan -NAN -nan -NAN\", got \"%s\"\n",
179 buf);
181 snprintf (buf, sizeof buf, "%La %LA %Le %LE %Lf %LF %Lg %LG",
182 lsnanval, lsnanval, lsnanval, lsnanval,
183 lsnanval, lsnanval, lsnanval, lsnanval);
184 result |= strcmp (buf, "nan NAN nan NAN nan NAN nan NAN") != 0;
185 printf ("expected \"nan NAN nan NAN nan NAN nan NAN\", got \"%s\"\n", buf);
187 snprintf (buf, sizeof buf, "%La %LA %Le %LE %Lf %LF %Lg %LG",
188 lmsnanval, lmsnanval, lmsnanval, lmsnanval,
189 lmsnanval, lmsnanval, lmsnanval, lmsnanval);
190 result |= strcmp (buf, "-nan -NAN -nan -NAN -nan -NAN -nan -NAN") != 0;
191 printf ("expected \"-nan -NAN -nan -NAN -nan -NAN -nan -NAN\", got \"%s\"\n",
192 buf);
194 linfval = LDBL_MAX * LDBL_MAX;
196 snprintf (buf, sizeof buf, "%La %LA %Le %LE %Lf %LF %Lg %LG",
197 linfval, linfval, linfval, linfval,
198 linfval, linfval, linfval, linfval);
199 result |= strcmp (buf, "inf INF inf INF inf INF inf INF") != 0;
200 printf ("expected \"inf INF inf INF inf INF inf INF\", got \"%s\"\n", buf);
202 snprintf (buf, sizeof buf, "%La %LA %Le %LE %Lf %LF %Lg %LG",
203 -linfval, -linfval, -linfval, -linfval,
204 -linfval, -linfval, -linfval, -linfval);
205 result |= strcmp (buf, "-inf -INF -inf -INF -inf -INF -inf -INF") != 0;
206 printf ("expected \"-inf -INF -inf -INF -inf -INF -inf -INF\", got \"%s\"\n",
207 buf);
209 swprintf (wbuf, sizeof wbuf / sizeof (wbuf[0]),
210 L"%La %LA %Le %LE %Lf %LF %Lg %LG",
211 lqnanval, lqnanval, lqnanval, lqnanval,
212 lqnanval, lqnanval, lqnanval, lqnanval);
213 result |= wcscmp (wbuf, L"nan NAN nan NAN nan NAN nan NAN") != 0;
214 printf ("expected L\"nan NAN nan NAN nan NAN nan NAN\", got L\"%S\"\n", wbuf);
216 swprintf (wbuf, sizeof wbuf / sizeof (wbuf[0]),
217 L"%La %LA %Le %LE %Lf %LF %Lg %LG",
218 -lqnanval, -lqnanval, -lqnanval, -lqnanval,
219 -lqnanval, -lqnanval, -lqnanval, -lqnanval);
220 result |= wcscmp (wbuf, L"-nan -NAN -nan -NAN -nan -NAN -nan -NAN") != 0;
221 printf ("expected L\"-nan -NAN -nan -NAN -nan -NAN -nan -NAN\", got L\"%S\"\n",
222 wbuf);
224 swprintf (wbuf, sizeof wbuf / sizeof (wbuf[0]),
225 L"%La %LA %Le %LE %Lf %LF %Lg %LG",
226 lsnanval, lsnanval, lsnanval, lsnanval,
227 lsnanval, lsnanval, lsnanval, lsnanval);
228 result |= wcscmp (wbuf, L"nan NAN nan NAN nan NAN nan NAN") != 0;
229 printf ("expected L\"nan NAN nan NAN nan NAN nan NAN\", got L\"%S\"\n", wbuf);
231 swprintf (wbuf, sizeof wbuf / sizeof (wbuf[0]),
232 L"%La %LA %Le %LE %Lf %LF %Lg %LG",
233 lmsnanval, lmsnanval, lmsnanval, lmsnanval,
234 lmsnanval, lmsnanval, lmsnanval, lmsnanval);
235 result |= wcscmp (wbuf, L"-nan -NAN -nan -NAN -nan -NAN -nan -NAN") != 0;
236 printf ("expected L\"-nan -NAN -nan -NAN -nan -NAN -nan -NAN\", got L\"%S\"\n",
237 wbuf);
239 swprintf (wbuf, sizeof wbuf / sizeof (wbuf[0]),
240 L"%La %LA %Le %LE %Lf %LF %Lg %LG",
241 linfval, linfval, linfval, linfval,
242 linfval, linfval, linfval, linfval);
243 result |= wcscmp (wbuf, L"inf INF inf INF inf INF inf INF") != 0;
244 printf ("expected L\"inf INF inf INF inf INF inf INF\", got L\"%S\"\n", wbuf);
246 swprintf (wbuf, sizeof wbuf / sizeof (wbuf[0]),
247 L"%La %LA %Le %LE %Lf %LF %Lg %LG",
248 -linfval, -linfval, -linfval, -linfval,
249 -linfval, -linfval, -linfval, -linfval);
250 result |= wcscmp (wbuf, L"-inf -INF -inf -INF -inf -INF -inf -INF") != 0;
251 printf ("expected L\"-inf -INF -inf -INF -inf -INF -inf -INF\", got L\"%S\"\n",
252 wbuf);
254 return result;
258 main (int argc, char *argv[])
260 int result = 0;
262 result |= t1 ();
263 result |= t2 ();
264 result |= t3 ();
265 result |= F ();
267 result |= fflush (stdout) == EOF;
269 return result;