openat: don’t close (-1)
[gnulib.git] / tests / test-snprintf-posix.h
blobcf6392daa202484725b59020be9956eca6fa4972
1 /* Test of POSIX compatible vsnprintf() and snprintf() functions.
2 Copyright (C) 2007-2024 Free Software Foundation, Inc.
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17 /* Written by Bruno Haible <bruno@clisp.org>, 2007. */
19 #include "minus-zero.h"
20 #include "infinity.h"
21 #include "nan.h"
22 #include "snan.h"
24 /* The SGI MIPS floating-point format does not distinguish 0.0 and -0.0. */
25 static int
26 have_minus_zero ()
28 static double plus_zero = 0.0;
29 double minus_zero = minus_zerod;
30 return memcmp (&plus_zero, &minus_zero, sizeof (double)) != 0;
33 /* Representation of an 80-bit 'long double' as an initializer for a sequence
34 of 'unsigned int' words. */
35 #ifdef WORDS_BIGENDIAN
36 # define LDBL80_WORDS(exponent,manthi,mantlo) \
37 { ((unsigned int) (exponent) << 16) | ((unsigned int) (manthi) >> 16), \
38 ((unsigned int) (manthi) << 16) | ((unsigned int) (mantlo) >> 16), \
39 (unsigned int) (mantlo) << 16 \
41 #else
42 # define LDBL80_WORDS(exponent,manthi,mantlo) \
43 { mantlo, manthi, exponent }
44 #endif
46 static int
47 strmatch (const char *pattern, const char *string)
49 if (strlen (pattern) != strlen (string))
50 return 0;
51 for (; *pattern != '\0'; pattern++, string++)
52 if (*pattern != '*' && *string != *pattern)
53 return 0;
54 return 1;
57 /* Test whether string[start_index..end_index-1] is a valid textual
58 representation of NaN. */
59 static int
60 strisnan (const char *string, size_t start_index, size_t end_index, int uppercase)
62 if (start_index < end_index)
64 if (string[start_index] == '-')
65 start_index++;
66 if (start_index + 3 <= end_index
67 && memcmp (string + start_index, uppercase ? "NAN" : "nan", 3) == 0)
69 start_index += 3;
70 if (start_index == end_index
71 || (string[start_index] == '(' && string[end_index - 1] == ')'))
72 return 1;
75 return 0;
78 static void
79 test_function (int (*my_snprintf) (char *, size_t, const char *, ...))
81 char buf[8];
82 int size;
83 char result[5000];
85 /* Test return value convention. */
87 for (size = 0; size <= 8; size++)
89 int retval;
91 memcpy (buf, "DEADBEEF", 8);
92 retval = my_snprintf (buf, size, "%d", 12345);
93 ASSERT (retval == 5);
94 if (size < 6)
96 if (size > 0)
98 ASSERT (memcmp (buf, "12345", size - 1) == 0);
99 ASSERT (buf[size - 1] == '\0');
101 ASSERT (memcmp (buf + size, &"DEADBEEF"[size], 8 - size) == 0);
103 else
105 ASSERT (memcmp (buf, "12345\0EF", 8) == 0);
109 /* Test support of size specifiers as in C99. */
112 int retval =
113 my_snprintf (result, sizeof (result), "%ju %d", (uintmax_t) 12345671, 33, 44, 55);
114 ASSERT (strcmp (result, "12345671 33") == 0);
115 ASSERT (retval == strlen (result));
119 int retval =
120 my_snprintf (result, sizeof (result), "%zu %d", (size_t) 12345672, 33, 44, 55);
121 ASSERT (strcmp (result, "12345672 33") == 0);
122 ASSERT (retval == strlen (result));
126 int retval =
127 my_snprintf (result, sizeof (result), "%tu %d", (ptrdiff_t) 12345673, 33, 44, 55);
128 ASSERT (strcmp (result, "12345673 33") == 0);
129 ASSERT (retval == strlen (result));
133 int retval =
134 my_snprintf (result, sizeof (result), "%Lg %d", (long double) 1.5, 33, 44, 55);
135 ASSERT (strcmp (result, "1.5 33") == 0);
136 ASSERT (retval == strlen (result));
139 /* Test the support of the 'a' and 'A' conversion specifier for hexadecimal
140 output of floating-point numbers. */
142 { /* A positive number. */
143 int retval =
144 my_snprintf (result, sizeof (result), "%a %d", 3.1416015625, 33, 44, 55);
145 ASSERT (strcmp (result, "0x1.922p+1 33") == 0
146 || strcmp (result, "0x3.244p+0 33") == 0
147 || strcmp (result, "0x6.488p-1 33") == 0
148 || strcmp (result, "0xc.91p-2 33") == 0);
149 ASSERT (retval == strlen (result));
152 { /* A negative number. */
153 int retval =
154 my_snprintf (result, sizeof (result), "%A %d", -3.1416015625, 33, 44, 55);
155 ASSERT (strcmp (result, "-0X1.922P+1 33") == 0
156 || strcmp (result, "-0X3.244P+0 33") == 0
157 || strcmp (result, "-0X6.488P-1 33") == 0
158 || strcmp (result, "-0XC.91P-2 33") == 0);
159 ASSERT (retval == strlen (result));
162 { /* Positive zero. */
163 int retval =
164 my_snprintf (result, sizeof (result), "%a %d", 0.0, 33, 44, 55);
165 ASSERT (strcmp (result, "0x0p+0 33") == 0);
166 ASSERT (retval == strlen (result));
169 { /* Negative zero. */
170 int retval =
171 my_snprintf (result, sizeof (result), "%a %d", minus_zerod, 33, 44, 55);
172 if (have_minus_zero ())
173 ASSERT (strcmp (result, "-0x0p+0 33") == 0);
174 ASSERT (retval == strlen (result));
177 { /* Positive infinity. */
178 int retval =
179 my_snprintf (result, sizeof (result), "%a %d", Infinityd (), 33, 44, 55);
180 ASSERT (strcmp (result, "inf 33") == 0);
181 ASSERT (retval == strlen (result));
184 { /* Negative infinity. */
185 int retval =
186 my_snprintf (result, sizeof (result), "%a %d", - Infinityd (), 33, 44, 55);
187 ASSERT (strcmp (result, "-inf 33") == 0);
188 ASSERT (retval == strlen (result));
191 { /* NaN. */
192 int retval =
193 my_snprintf (result, sizeof (result), "%a %d", NaNd (), 33, 44, 55);
194 ASSERT (strlen (result) >= 3 + 3
195 && strisnan (result, 0, strlen (result) - 3, 0)
196 && strcmp (result + strlen (result) - 3, " 33") == 0);
197 ASSERT (retval == strlen (result));
199 #if HAVE_SNAND
200 { /* Signalling NaN. */
201 int retval =
202 my_snprintf (result, sizeof (result), "%a %d", SNaNd (), 33, 44, 55);
203 ASSERT (strlen (result) >= 3 + 3
204 && strisnan (result, 0, strlen (result) - 3, 0)
205 && strcmp (result + strlen (result) - 3, " 33") == 0);
206 ASSERT (retval == strlen (result));
208 #endif
210 { /* Rounding near the decimal point. */
211 int retval =
212 my_snprintf (result, sizeof (result), "%.0a %d", 1.5, 33, 44, 55);
213 ASSERT (strcmp (result, "0x2p+0 33") == 0
214 || strcmp (result, "0x3p-1 33") == 0
215 || strcmp (result, "0x6p-2 33") == 0
216 || strcmp (result, "0xcp-3 33") == 0);
217 ASSERT (retval == strlen (result));
220 { /* Rounding with precision 0. */
221 int retval =
222 my_snprintf (result, sizeof (result), "%.0a %d", 1.51, 33, 44, 55);
223 ASSERT (strcmp (result, "0x2p+0 33") == 0
224 || strcmp (result, "0x3p-1 33") == 0
225 || strcmp (result, "0x6p-2 33") == 0
226 || strcmp (result, "0xcp-3 33") == 0);
227 ASSERT (retval == strlen (result));
230 { /* Rounding with precision 1. */
231 int retval =
232 my_snprintf (result, sizeof (result), "%.1a %d", 1.51, 33, 44, 55);
233 ASSERT (strcmp (result, "0x1.8p+0 33") == 0
234 || strcmp (result, "0x3.0p-1 33") == 0
235 || strcmp (result, "0x6.1p-2 33") == 0
236 || strcmp (result, "0xc.1p-3 33") == 0);
237 ASSERT (retval == strlen (result));
240 { /* Rounding with precision 2. */
241 int retval =
242 my_snprintf (result, sizeof (result), "%.2a %d", 1.51, 33, 44, 55);
243 ASSERT (strcmp (result, "0x1.83p+0 33") == 0
244 || strcmp (result, "0x3.05p-1 33") == 0
245 || strcmp (result, "0x6.0ap-2 33") == 0
246 || strcmp (result, "0xc.14p-3 33") == 0);
247 ASSERT (retval == strlen (result));
250 { /* Rounding with precision 3. */
251 int retval =
252 my_snprintf (result, sizeof (result), "%.3a %d", 1.51, 33, 44, 55);
253 ASSERT (strcmp (result, "0x1.829p+0 33") == 0
254 || strcmp (result, "0x3.052p-1 33") == 0
255 || strcmp (result, "0x6.0a4p-2 33") == 0
256 || strcmp (result, "0xc.148p-3 33") == 0);
257 ASSERT (retval == strlen (result));
260 { /* Rounding can turn a ...FFF into a ...000. */
261 int retval =
262 my_snprintf (result, sizeof (result), "%.3a %d", 1.49999, 33, 44, 55);
263 ASSERT (strcmp (result, "0x1.800p+0 33") == 0
264 || strcmp (result, "0x3.000p-1 33") == 0
265 || strcmp (result, "0x6.000p-2 33") == 0
266 || strcmp (result, "0xc.000p-3 33") == 0);
267 ASSERT (retval == strlen (result));
270 { /* Rounding can turn a ...FFF into a ...000.
271 This shows a Mac OS X 10.3.9 (Darwin 7.9) bug. */
272 int retval =
273 my_snprintf (result, sizeof (result), "%.1a %d", 1.999, 33, 44, 55);
274 ASSERT (strcmp (result, "0x1.0p+1 33") == 0
275 || strcmp (result, "0x2.0p+0 33") == 0
276 || strcmp (result, "0x4.0p-1 33") == 0
277 || strcmp (result, "0x8.0p-2 33") == 0);
278 ASSERT (retval == strlen (result));
281 { /* Width. */
282 int retval =
283 my_snprintf (result, sizeof (result), "%10a %d", 1.75, 33, 44, 55);
284 ASSERT (strcmp (result, " 0x1.cp+0 33") == 0
285 || strcmp (result, " 0x3.8p-1 33") == 0
286 || strcmp (result, " 0x7p-2 33") == 0
287 || strcmp (result, " 0xep-3 33") == 0);
288 ASSERT (retval == strlen (result));
291 { /* Width given as argument. */
292 int retval =
293 my_snprintf (result, sizeof (result), "%*a %d", 10, 1.75, 33, 44, 55);
294 ASSERT (strcmp (result, " 0x1.cp+0 33") == 0
295 || strcmp (result, " 0x3.8p-1 33") == 0
296 || strcmp (result, " 0x7p-2 33") == 0
297 || strcmp (result, " 0xep-3 33") == 0);
298 ASSERT (retval == strlen (result));
301 { /* Negative width given as argument (cf. FLAG_LEFT below). */
302 int retval =
303 my_snprintf (result, sizeof (result), "%*a %d", -10, 1.75, 33, 44, 55);
304 ASSERT (strcmp (result, "0x1.cp+0 33") == 0
305 || strcmp (result, "0x3.8p-1 33") == 0
306 || strcmp (result, "0x7p-2 33") == 0
307 || strcmp (result, "0xep-3 33") == 0);
308 ASSERT (retval == strlen (result));
311 { /* Small precision. */
312 int retval =
313 my_snprintf (result, sizeof (result), "%.10a %d", 1.75, 33, 44, 55);
314 ASSERT (strcmp (result, "0x1.c000000000p+0 33") == 0
315 || strcmp (result, "0x3.8000000000p-1 33") == 0
316 || strcmp (result, "0x7.0000000000p-2 33") == 0
317 || strcmp (result, "0xe.0000000000p-3 33") == 0);
318 ASSERT (retval == strlen (result));
321 { /* Large precision. */
322 int retval =
323 my_snprintf (result, sizeof (result), "%.50a %d", 1.75, 33, 44, 55);
324 ASSERT (strcmp (result, "0x1.c0000000000000000000000000000000000000000000000000p+0 33") == 0
325 || strcmp (result, "0x3.80000000000000000000000000000000000000000000000000p-1 33") == 0
326 || strcmp (result, "0x7.00000000000000000000000000000000000000000000000000p-2 33") == 0
327 || strcmp (result, "0xe.00000000000000000000000000000000000000000000000000p-3 33") == 0);
328 ASSERT (retval == strlen (result));
331 { /* FLAG_LEFT. */
332 int retval =
333 my_snprintf (result, sizeof (result), "%-10a %d", 1.75, 33, 44, 55);
334 ASSERT (strcmp (result, "0x1.cp+0 33") == 0
335 || strcmp (result, "0x3.8p-1 33") == 0
336 || strcmp (result, "0x7p-2 33") == 0
337 || strcmp (result, "0xep-3 33") == 0);
338 ASSERT (retval == strlen (result));
341 { /* FLAG_SHOWSIGN. */
342 int retval =
343 my_snprintf (result, sizeof (result), "%+a %d", 1.75, 33, 44, 55);
344 ASSERT (strcmp (result, "+0x1.cp+0 33") == 0
345 || strcmp (result, "+0x3.8p-1 33") == 0
346 || strcmp (result, "+0x7p-2 33") == 0
347 || strcmp (result, "+0xep-3 33") == 0);
348 ASSERT (retval == strlen (result));
351 { /* FLAG_SPACE. */
352 int retval =
353 my_snprintf (result, sizeof (result), "% a %d", 1.75, 33, 44, 55);
354 ASSERT (strcmp (result, " 0x1.cp+0 33") == 0
355 || strcmp (result, " 0x3.8p-1 33") == 0
356 || strcmp (result, " 0x7p-2 33") == 0
357 || strcmp (result, " 0xep-3 33") == 0);
358 ASSERT (retval == strlen (result));
361 { /* FLAG_ALT. */
362 int retval =
363 my_snprintf (result, sizeof (result), "%#a %d", 1.75, 33, 44, 55);
364 ASSERT (strcmp (result, "0x1.cp+0 33") == 0
365 || strcmp (result, "0x3.8p-1 33") == 0
366 || strcmp (result, "0x7.p-2 33") == 0
367 || strcmp (result, "0xe.p-3 33") == 0);
368 ASSERT (retval == strlen (result));
371 { /* FLAG_ALT. */
372 int retval =
373 my_snprintf (result, sizeof (result), "%#a %d", 1.0, 33, 44, 55);
374 ASSERT (strcmp (result, "0x1.p+0 33") == 0
375 || strcmp (result, "0x2.p-1 33") == 0
376 || strcmp (result, "0x4.p-2 33") == 0
377 || strcmp (result, "0x8.p-3 33") == 0);
378 ASSERT (retval == strlen (result));
381 { /* FLAG_ZERO with finite number. */
382 int retval =
383 my_snprintf (result, sizeof (result), "%010a %d", 1.75, 33, 44, 55);
384 ASSERT (strcmp (result, "0x001.cp+0 33") == 0
385 || strcmp (result, "0x003.8p-1 33") == 0
386 || strcmp (result, "0x00007p-2 33") == 0
387 || strcmp (result, "0x0000ep-3 33") == 0);
388 ASSERT (retval == strlen (result));
391 { /* FLAG_ZERO with infinite number. */
392 int retval =
393 my_snprintf (result, sizeof (result), "%010a %d", Infinityd (), 33, 44, 55);
394 /* "0000000inf 33" is not a valid result; see
395 <https://lists.gnu.org/r/bug-gnulib/2007-04/msg00107.html> */
396 ASSERT (strcmp (result, " inf 33") == 0);
397 ASSERT (retval == strlen (result));
400 { /* FLAG_ZERO with NaN. */
401 int retval =
402 my_snprintf (result, sizeof (result), "%050a %d", NaNd (), 33, 44, 55);
403 /* "0000000nan 33" is not a valid result; see
404 <https://lists.gnu.org/r/bug-gnulib/2007-04/msg00107.html> */
405 ASSERT (strlen (result) == 50 + 3
406 && strisnan (result, strspn (result, " "), strlen (result) - 3, 0)
407 && strcmp (result + strlen (result) - 3, " 33") == 0);
408 ASSERT (retval == strlen (result));
411 { /* A positive number. */
412 int retval =
413 my_snprintf (result, sizeof (result), "%La %d", 3.1416015625L, 33, 44, 55);
414 ASSERT (strcmp (result, "0x1.922p+1 33") == 0
415 || strcmp (result, "0x3.244p+0 33") == 0
416 || strcmp (result, "0x6.488p-1 33") == 0
417 || strcmp (result, "0xc.91p-2 33") == 0);
418 ASSERT (retval == strlen (result));
421 { /* A negative number. */
422 int retval =
423 my_snprintf (result, sizeof (result), "%LA %d", -3.1416015625L, 33, 44, 55);
424 ASSERT (strcmp (result, "-0X1.922P+1 33") == 0
425 || strcmp (result, "-0X3.244P+0 33") == 0
426 || strcmp (result, "-0X6.488P-1 33") == 0
427 || strcmp (result, "-0XC.91P-2 33") == 0);
428 ASSERT (retval == strlen (result));
431 { /* Positive zero. */
432 int retval =
433 my_snprintf (result, sizeof (result), "%La %d", 0.0L, 33, 44, 55);
434 ASSERT (strcmp (result, "0x0p+0 33") == 0);
435 ASSERT (retval == strlen (result));
438 { /* Negative zero. */
439 int retval =
440 my_snprintf (result, sizeof (result), "%La %d", minus_zerol, 33, 44, 55);
441 if (have_minus_zero ())
442 ASSERT (strcmp (result, "-0x0p+0 33") == 0);
443 ASSERT (retval == strlen (result));
446 { /* Positive infinity. */
447 int retval =
448 my_snprintf (result, sizeof (result), "%La %d", Infinityl (), 33, 44, 55);
449 /* Note: This assertion fails under valgrind.
450 Reported at <https://bugs.kde.org/show_bug.cgi?id=424044>. */
451 ASSERT (strcmp (result, "inf 33") == 0);
452 ASSERT (retval == strlen (result));
455 { /* Negative infinity. */
456 int retval =
457 my_snprintf (result, sizeof (result), "%La %d", - Infinityl (), 33, 44, 55);
458 ASSERT (strcmp (result, "-inf 33") == 0);
459 ASSERT (retval == strlen (result));
462 { /* NaN. */
463 int retval =
464 my_snprintf (result, sizeof (result), "%La %d", NaNl (), 33, 44, 55);
465 ASSERT (strlen (result) >= 3 + 3
466 && strisnan (result, 0, strlen (result) - 3, 0)
467 && strcmp (result + strlen (result) - 3, " 33") == 0);
468 ASSERT (retval == strlen (result));
470 #if HAVE_SNANL
471 { /* Signalling NaN. */
472 int retval =
473 my_snprintf (result, sizeof (result), "%La %d", SNaNl (), 33, 44, 55);
474 ASSERT (strlen (result) >= 3 + 3
475 && strisnan (result, 0, strlen (result) - 3, 0)
476 && strcmp (result + strlen (result) - 3, " 33") == 0);
477 ASSERT (retval == strlen (result));
479 #endif
480 #if CHECK_PRINTF_SAFE && ((defined __ia64 && LDBL_MANT_DIG == 64) || (defined __x86_64__ || defined __amd64__) || (defined __i386 || defined __i386__ || defined _I386 || defined _M_IX86 || defined _X86_)) && !HAVE_SAME_LONG_DOUBLE_AS_DOUBLE
481 { /* Quiet NaN. */
482 static union { unsigned int word[4]; long double value; } x =
483 { .word = LDBL80_WORDS (0xFFFF, 0xC3333333, 0x00000000) };
484 int retval =
485 my_snprintf (result, sizeof (result), "%La %d", x.value, 33, 44, 55);
486 ASSERT (strlen (result) >= 3 + 3
487 && strisnan (result, 0, strlen (result) - 3, 0)
488 && strcmp (result + strlen (result) - 3, " 33") == 0);
489 ASSERT (retval == strlen (result));
492 /* Signalling NaN. */
493 static union { unsigned int word[4]; long double value; } x =
494 { .word = LDBL80_WORDS (0xFFFF, 0x83333333, 0x00000000) };
495 int retval =
496 my_snprintf (result, sizeof (result), "%La %d", x.value, 33, 44, 55);
497 ASSERT (strlen (result) >= 3 + 3
498 && strisnan (result, 0, strlen (result) - 3, 0)
499 && strcmp (result + strlen (result) - 3, " 33") == 0);
500 ASSERT (retval == strlen (result));
502 /* snprintf should print something for noncanonical values. */
503 { /* Pseudo-NaN. */
504 static union { unsigned int word[4]; long double value; } x =
505 { .word = LDBL80_WORDS (0xFFFF, 0x40000001, 0x00000000) };
506 int retval =
507 my_snprintf (result, sizeof (result), "%La %d", x.value, 33, 44, 55);
508 ASSERT (retval == strlen (result));
509 ASSERT (3 < retval && strcmp (result + retval - 3, " 33") == 0);
511 { /* Pseudo-Infinity. */
512 static union { unsigned int word[4]; long double value; } x =
513 { .word = LDBL80_WORDS (0xFFFF, 0x00000000, 0x00000000) };
514 int retval =
515 my_snprintf (result, sizeof (result), "%La %d", x.value, 33, 44, 55);
516 ASSERT (retval == strlen (result));
517 ASSERT (3 < retval && strcmp (result + retval - 3, " 33") == 0);
519 { /* Pseudo-Zero. */
520 static union { unsigned int word[4]; long double value; } x =
521 { .word = LDBL80_WORDS (0x4004, 0x00000000, 0x00000000) };
522 int retval =
523 my_snprintf (result, sizeof (result), "%La %d", x.value, 33, 44, 55);
524 ASSERT (retval == strlen (result));
525 ASSERT (3 < retval && strcmp (result + retval - 3, " 33") == 0);
527 { /* Unnormalized number. */
528 static union { unsigned int word[4]; long double value; } x =
529 { .word = LDBL80_WORDS (0x4000, 0x63333333, 0x00000000) };
530 int retval =
531 my_snprintf (result, sizeof (result), "%La %d", x.value, 33, 44, 55);
532 ASSERT (retval == strlen (result));
533 ASSERT (3 < retval && strcmp (result + retval - 3, " 33") == 0);
535 { /* Pseudo-Denormal. */
536 static union { unsigned int word[4]; long double value; } x =
537 { .word = LDBL80_WORDS (0x0000, 0x83333333, 0x00000000) };
538 int retval =
539 my_snprintf (result, sizeof (result), "%La %d", x.value, 33, 44, 55);
540 ASSERT (retval == strlen (result));
541 ASSERT (3 < retval && strcmp (result + retval - 3, " 33") == 0);
543 #endif
545 { /* Rounding near the decimal point. */
546 int retval =
547 my_snprintf (result, sizeof (result), "%.0La %d", 1.5L, 33, 44, 55);
548 ASSERT (strcmp (result, "0x2p+0 33") == 0
549 || strcmp (result, "0x3p-1 33") == 0
550 || strcmp (result, "0x6p-2 33") == 0
551 || strcmp (result, "0xcp-3 33") == 0);
552 ASSERT (retval == strlen (result));
555 { /* Rounding with precision 0. */
556 int retval =
557 my_snprintf (result, sizeof (result), "%.0La %d", 1.51L, 33, 44, 55);
558 ASSERT (strcmp (result, "0x2p+0 33") == 0
559 || strcmp (result, "0x3p-1 33") == 0
560 || strcmp (result, "0x6p-2 33") == 0
561 || strcmp (result, "0xcp-3 33") == 0);
562 ASSERT (retval == strlen (result));
565 { /* Rounding with precision 1. */
566 int retval =
567 my_snprintf (result, sizeof (result), "%.1La %d", 1.51L, 33, 44, 55);
568 ASSERT (strcmp (result, "0x1.8p+0 33") == 0
569 || strcmp (result, "0x3.0p-1 33") == 0
570 || strcmp (result, "0x6.1p-2 33") == 0
571 || strcmp (result, "0xc.1p-3 33") == 0);
572 ASSERT (retval == strlen (result));
575 { /* Rounding with precision 2. */
576 int retval =
577 my_snprintf (result, sizeof (result), "%.2La %d", 1.51L, 33, 44, 55);
578 ASSERT (strcmp (result, "0x1.83p+0 33") == 0
579 || strcmp (result, "0x3.05p-1 33") == 0
580 || strcmp (result, "0x6.0ap-2 33") == 0
581 || strcmp (result, "0xc.14p-3 33") == 0);
582 ASSERT (retval == strlen (result));
585 { /* Rounding with precision 3. */
586 int retval =
587 my_snprintf (result, sizeof (result), "%.3La %d", 1.51L, 33, 44, 55);
588 ASSERT (strcmp (result, "0x1.829p+0 33") == 0
589 || strcmp (result, "0x3.052p-1 33") == 0
590 || strcmp (result, "0x6.0a4p-2 33") == 0
591 || strcmp (result, "0xc.148p-3 33") == 0);
592 ASSERT (retval == strlen (result));
595 { /* Rounding can turn a ...FFF into a ...000. */
596 int retval =
597 my_snprintf (result, sizeof (result), "%.3La %d", 1.49999L, 33, 44, 55);
598 ASSERT (strcmp (result, "0x1.800p+0 33") == 0
599 || strcmp (result, "0x3.000p-1 33") == 0
600 || strcmp (result, "0x6.000p-2 33") == 0
601 || strcmp (result, "0xc.000p-3 33") == 0);
602 ASSERT (retval == strlen (result));
605 { /* Rounding can turn a ...FFF into a ...000.
606 This shows a Mac OS X 10.3.9 (Darwin 7.9) bug and a
607 glibc 2.4 bug <https://sourceware.org/bugzilla/show_bug.cgi?id=2908>. */
608 int retval =
609 my_snprintf (result, sizeof (result), "%.1La %d", 1.999L, 33, 44, 55);
610 ASSERT (strcmp (result, "0x1.0p+1 33") == 0
611 || strcmp (result, "0x2.0p+0 33") == 0
612 || strcmp (result, "0x4.0p-1 33") == 0
613 || strcmp (result, "0x8.0p-2 33") == 0);
614 ASSERT (retval == strlen (result));
617 { /* Width. */
618 int retval =
619 my_snprintf (result, sizeof (result), "%10La %d", 1.75L, 33, 44, 55);
620 ASSERT (strcmp (result, " 0x1.cp+0 33") == 0
621 || strcmp (result, " 0x3.8p-1 33") == 0
622 || strcmp (result, " 0x7p-2 33") == 0
623 || strcmp (result, " 0xep-3 33") == 0);
624 ASSERT (retval == strlen (result));
627 { /* Width given as argument. */
628 int retval =
629 my_snprintf (result, sizeof (result), "%*La %d", 10, 1.75L, 33, 44, 55);
630 ASSERT (strcmp (result, " 0x1.cp+0 33") == 0
631 || strcmp (result, " 0x3.8p-1 33") == 0
632 || strcmp (result, " 0x7p-2 33") == 0
633 || strcmp (result, " 0xep-3 33") == 0);
634 ASSERT (retval == strlen (result));
637 { /* Negative width given as argument (cf. FLAG_LEFT below). */
638 int retval =
639 my_snprintf (result, sizeof (result), "%*La %d", -10, 1.75L, 33, 44, 55);
640 ASSERT (strcmp (result, "0x1.cp+0 33") == 0
641 || strcmp (result, "0x3.8p-1 33") == 0
642 || strcmp (result, "0x7p-2 33") == 0
643 || strcmp (result, "0xep-3 33") == 0);
644 ASSERT (retval == strlen (result));
647 { /* Small precision. */
648 int retval =
649 my_snprintf (result, sizeof (result), "%.10La %d", 1.75L, 33, 44, 55);
650 ASSERT (strcmp (result, "0x1.c000000000p+0 33") == 0
651 || strcmp (result, "0x3.8000000000p-1 33") == 0
652 || strcmp (result, "0x7.0000000000p-2 33") == 0
653 || strcmp (result, "0xe.0000000000p-3 33") == 0);
654 ASSERT (retval == strlen (result));
657 { /* Large precision. */
658 int retval =
659 my_snprintf (result, sizeof (result), "%.50La %d", 1.75L, 33, 44, 55);
660 ASSERT (strcmp (result, "0x1.c0000000000000000000000000000000000000000000000000p+0 33") == 0
661 || strcmp (result, "0x3.80000000000000000000000000000000000000000000000000p-1 33") == 0
662 || strcmp (result, "0x7.00000000000000000000000000000000000000000000000000p-2 33") == 0
663 || strcmp (result, "0xe.00000000000000000000000000000000000000000000000000p-3 33") == 0);
664 ASSERT (retval == strlen (result));
667 { /* FLAG_LEFT. */
668 int retval =
669 my_snprintf (result, sizeof (result), "%-10La %d", 1.75L, 33, 44, 55);
670 ASSERT (strcmp (result, "0x1.cp+0 33") == 0
671 || strcmp (result, "0x3.8p-1 33") == 0
672 || strcmp (result, "0x7p-2 33") == 0
673 || strcmp (result, "0xep-3 33") == 0);
674 ASSERT (retval == strlen (result));
677 { /* FLAG_SHOWSIGN. */
678 int retval =
679 my_snprintf (result, sizeof (result), "%+La %d", 1.75L, 33, 44, 55);
680 ASSERT (strcmp (result, "+0x1.cp+0 33") == 0
681 || strcmp (result, "+0x3.8p-1 33") == 0
682 || strcmp (result, "+0x7p-2 33") == 0
683 || strcmp (result, "+0xep-3 33") == 0);
684 ASSERT (retval == strlen (result));
687 { /* FLAG_SPACE. */
688 int retval =
689 my_snprintf (result, sizeof (result), "% La %d", 1.75L, 33, 44, 55);
690 ASSERT (strcmp (result, " 0x1.cp+0 33") == 0
691 || strcmp (result, " 0x3.8p-1 33") == 0
692 || strcmp (result, " 0x7p-2 33") == 0
693 || strcmp (result, " 0xep-3 33") == 0);
694 ASSERT (retval == strlen (result));
697 { /* FLAG_ALT. */
698 int retval =
699 my_snprintf (result, sizeof (result), "%#La %d", 1.75L, 33, 44, 55);
700 ASSERT (strcmp (result, "0x1.cp+0 33") == 0
701 || strcmp (result, "0x3.8p-1 33") == 0
702 || strcmp (result, "0x7.p-2 33") == 0
703 || strcmp (result, "0xe.p-3 33") == 0);
704 ASSERT (retval == strlen (result));
707 { /* FLAG_ALT. */
708 int retval =
709 my_snprintf (result, sizeof (result), "%#La %d", 1.0L, 33, 44, 55);
710 ASSERT (strcmp (result, "0x1.p+0 33") == 0
711 || strcmp (result, "0x2.p-1 33") == 0
712 || strcmp (result, "0x4.p-2 33") == 0
713 || strcmp (result, "0x8.p-3 33") == 0);
714 ASSERT (retval == strlen (result));
717 { /* FLAG_ZERO with finite number. */
718 int retval =
719 my_snprintf (result, sizeof (result), "%010La %d", 1.75L, 33, 44, 55);
720 ASSERT (strcmp (result, "0x001.cp+0 33") == 0
721 || strcmp (result, "0x003.8p-1 33") == 0
722 || strcmp (result, "0x00007p-2 33") == 0
723 || strcmp (result, "0x0000ep-3 33") == 0);
724 ASSERT (retval == strlen (result));
727 { /* FLAG_ZERO with infinite number. */
728 int retval =
729 my_snprintf (result, sizeof (result), "%010La %d", Infinityl (), 33, 44, 55);
730 /* "0000000inf 33" is not a valid result; see
731 <https://lists.gnu.org/r/bug-gnulib/2007-04/msg00107.html> */
732 ASSERT (strcmp (result, " inf 33") == 0);
733 ASSERT (retval == strlen (result));
736 { /* FLAG_ZERO with NaN. */
737 int retval =
738 my_snprintf (result, sizeof (result), "%050La %d", NaNl (), 33, 44, 55);
739 /* "0000000nan 33" is not a valid result; see
740 <https://lists.gnu.org/r/bug-gnulib/2007-04/msg00107.html> */
741 ASSERT (strlen (result) == 50 + 3
742 && strisnan (result, strspn (result, " "), strlen (result) - 3, 0)
743 && strcmp (result + strlen (result) - 3, " 33") == 0);
744 ASSERT (retval == strlen (result));
747 /* Test the support of the %f format directive. */
749 { /* A positive number. */
750 int retval =
751 my_snprintf (result, sizeof (result), "%f %d", 12.75, 33, 44, 55);
752 ASSERT (strcmp (result, "12.750000 33") == 0);
753 ASSERT (retval == strlen (result));
756 { /* A larger positive number. */
757 int retval =
758 my_snprintf (result, sizeof (result), "%f %d", 1234567.0, 33, 44, 55);
759 ASSERT (strcmp (result, "1234567.000000 33") == 0);
760 ASSERT (retval == strlen (result));
763 { /* Small and large positive numbers. */
764 static struct { double value; const char *string; } data[] =
766 { 1.234321234321234e-37, "0.000000" },
767 { 1.234321234321234e-36, "0.000000" },
768 { 1.234321234321234e-35, "0.000000" },
769 { 1.234321234321234e-34, "0.000000" },
770 { 1.234321234321234e-33, "0.000000" },
771 { 1.234321234321234e-32, "0.000000" },
772 { 1.234321234321234e-31, "0.000000" },
773 { 1.234321234321234e-30, "0.000000" },
774 { 1.234321234321234e-29, "0.000000" },
775 { 1.234321234321234e-28, "0.000000" },
776 { 1.234321234321234e-27, "0.000000" },
777 { 1.234321234321234e-26, "0.000000" },
778 { 1.234321234321234e-25, "0.000000" },
779 { 1.234321234321234e-24, "0.000000" },
780 { 1.234321234321234e-23, "0.000000" },
781 { 1.234321234321234e-22, "0.000000" },
782 { 1.234321234321234e-21, "0.000000" },
783 { 1.234321234321234e-20, "0.000000" },
784 { 1.234321234321234e-19, "0.000000" },
785 { 1.234321234321234e-18, "0.000000" },
786 { 1.234321234321234e-17, "0.000000" },
787 { 1.234321234321234e-16, "0.000000" },
788 { 1.234321234321234e-15, "0.000000" },
789 { 1.234321234321234e-14, "0.000000" },
790 { 1.234321234321234e-13, "0.000000" },
791 { 1.234321234321234e-12, "0.000000" },
792 { 1.234321234321234e-11, "0.000000" },
793 { 1.234321234321234e-10, "0.000000" },
794 { 1.234321234321234e-9, "0.000000" },
795 { 1.234321234321234e-8, "0.000000" },
796 { 1.234321234321234e-7, "0.000000" },
797 { 1.234321234321234e-6, "0.000001" },
798 { 1.234321234321234e-5, "0.000012" },
799 { 1.234321234321234e-4, "0.000123" },
800 { 1.234321234321234e-3, "0.001234" },
801 { 1.234321234321234e-2, "0.012343" },
802 { 1.234321234321234e-1, "0.123432" },
803 { 1.234321234321234, "1.234321" },
804 { 1.234321234321234e1, "12.343212" },
805 { 1.234321234321234e2, "123.432123" },
806 { 1.234321234321234e3, "1234.321234" },
807 { 1.234321234321234e4, "12343.212343" },
808 { 1.234321234321234e5, "123432.123432" },
809 { 1.234321234321234e6, "1234321.234321" },
810 { 1.234321234321234e7, "12343212.343212" },
811 { 1.234321234321234e8, "123432123.432123" },
812 { 1.234321234321234e9, "1234321234.321234" },
813 { 1.234321234321234e10, "12343212343.2123**" },
814 { 1.234321234321234e11, "123432123432.123***" },
815 { 1.234321234321234e12, "1234321234321.23****" },
816 { 1.234321234321234e13, "12343212343212.3*****" },
817 { 1.234321234321234e14, "123432123432123.******" },
818 { 1.234321234321234e15, "1234321234321234.000000" },
819 { 1.234321234321234e16, "123432123432123**.000000" },
820 { 1.234321234321234e17, "123432123432123***.000000" },
821 { 1.234321234321234e18, "123432123432123****.000000" },
822 { 1.234321234321234e19, "123432123432123*****.000000" },
823 { 1.234321234321234e20, "123432123432123******.000000" },
824 { 1.234321234321234e21, "123432123432123*******.000000" },
825 { 1.234321234321234e22, "123432123432123********.000000" },
826 { 1.234321234321234e23, "123432123432123*********.000000" },
827 { 1.234321234321234e24, "123432123432123**********.000000" },
828 { 1.234321234321234e25, "123432123432123***********.000000" },
829 { 1.234321234321234e26, "123432123432123************.000000" },
830 { 1.234321234321234e27, "123432123432123*************.000000" },
831 { 1.234321234321234e28, "123432123432123**************.000000" },
832 { 1.234321234321234e29, "123432123432123***************.000000" },
833 { 1.234321234321234e30, "123432123432123****************.000000" },
834 { 1.234321234321234e31, "123432123432123*****************.000000" },
835 { 1.234321234321234e32, "123432123432123******************.000000" },
836 { 1.234321234321234e33, "123432123432123*******************.000000" },
837 { 1.234321234321234e34, "123432123432123********************.000000" },
838 { 1.234321234321234e35, "123432123432123*********************.000000" },
839 { 1.234321234321234e36, "123432123432123**********************.000000" }
841 size_t k;
842 for (k = 0; k < SIZEOF (data); k++)
844 int retval =
845 my_snprintf (result, sizeof (result), "%f", data[k].value);
846 ASSERT (strmatch (data[k].string, result));
847 ASSERT (retval == strlen (result));
851 { /* A negative number. */
852 int retval =
853 my_snprintf (result, sizeof (result), "%f %d", -0.03125, 33, 44, 55);
854 ASSERT (strcmp (result, "-0.031250 33") == 0);
855 ASSERT (retval == strlen (result));
858 { /* Positive zero. */
859 int retval =
860 my_snprintf (result, sizeof (result), "%f %d", 0.0, 33, 44, 55);
861 ASSERT (strcmp (result, "0.000000 33") == 0);
862 ASSERT (retval == strlen (result));
865 { /* Negative zero. */
866 int retval =
867 my_snprintf (result, sizeof (result), "%f %d", minus_zerod, 33, 44, 55);
868 if (have_minus_zero ())
869 ASSERT (strcmp (result, "-0.000000 33") == 0);
870 ASSERT (retval == strlen (result));
873 { /* Positive infinity. */
874 int retval =
875 my_snprintf (result, sizeof (result), "%f %d", Infinityd (), 33, 44, 55);
876 ASSERT (strcmp (result, "inf 33") == 0
877 || strcmp (result, "infinity 33") == 0);
878 ASSERT (retval == strlen (result));
881 { /* Negative infinity. */
882 int retval =
883 my_snprintf (result, sizeof (result), "%f %d", - Infinityd (), 33, 44, 55);
884 ASSERT (strcmp (result, "-inf 33") == 0
885 || strcmp (result, "-infinity 33") == 0);
886 ASSERT (retval == strlen (result));
889 { /* NaN. */
890 int retval =
891 my_snprintf (result, sizeof (result), "%f %d", NaNd (), 33, 44, 55);
892 ASSERT (strlen (result) >= 3 + 3
893 && strisnan (result, 0, strlen (result) - 3, 0)
894 && strcmp (result + strlen (result) - 3, " 33") == 0);
895 ASSERT (retval == strlen (result));
897 #if HAVE_SNAND
898 { /* Signalling NaN. */
899 int retval =
900 my_snprintf (result, sizeof (result), "%f %d", SNaNd (), 33, 44, 55);
901 ASSERT (strlen (result) >= 3 + 3
902 && strisnan (result, 0, strlen (result) - 3, 0)
903 && strcmp (result + strlen (result) - 3, " 33") == 0);
904 ASSERT (retval == strlen (result));
906 #endif
908 { /* Width. */
909 int retval =
910 my_snprintf (result, sizeof (result), "%10f %d", 1.75, 33, 44, 55);
911 ASSERT (strcmp (result, " 1.750000 33") == 0);
912 ASSERT (retval == strlen (result));
915 { /* Width given as argument. */
916 int retval =
917 my_snprintf (result, sizeof (result), "%*f %d", 10, 1.75, 33, 44, 55);
918 ASSERT (strcmp (result, " 1.750000 33") == 0);
919 ASSERT (retval == strlen (result));
922 { /* Negative width given as argument (cf. FLAG_LEFT below). */
923 int retval =
924 my_snprintf (result, sizeof (result), "%*f %d", -10, 1.75, 33, 44, 55);
925 ASSERT (strcmp (result, "1.750000 33") == 0);
926 ASSERT (retval == strlen (result));
929 { /* FLAG_LEFT. */
930 int retval =
931 my_snprintf (result, sizeof (result), "%-10f %d", 1.75, 33, 44, 55);
932 ASSERT (strcmp (result, "1.750000 33") == 0);
933 ASSERT (retval == strlen (result));
936 { /* FLAG_SHOWSIGN. */
937 int retval =
938 my_snprintf (result, sizeof (result), "%+f %d", 1.75, 33, 44, 55);
939 ASSERT (strcmp (result, "+1.750000 33") == 0);
940 ASSERT (retval == strlen (result));
943 { /* FLAG_SPACE. */
944 int retval =
945 my_snprintf (result, sizeof (result), "% f %d", 1.75, 33, 44, 55);
946 ASSERT (strcmp (result, " 1.750000 33") == 0);
947 ASSERT (retval == strlen (result));
950 { /* FLAG_ALT. */
951 int retval =
952 my_snprintf (result, sizeof (result), "%#f %d", 1.75, 33, 44, 55);
953 ASSERT (strcmp (result, "1.750000 33") == 0);
954 ASSERT (retval == strlen (result));
957 { /* FLAG_ALT. */
958 int retval =
959 my_snprintf (result, sizeof (result), "%#.f %d", 1.75, 33, 44, 55);
960 ASSERT (strcmp (result, "2. 33") == 0);
961 ASSERT (retval == strlen (result));
964 { /* FLAG_ZERO with finite number. */
965 int retval =
966 my_snprintf (result, sizeof (result), "%015f %d", 1234.0, 33, 44, 55);
967 ASSERT (strcmp (result, "00001234.000000 33") == 0);
968 ASSERT (retval == strlen (result));
971 { /* FLAG_ZERO with infinite number. */
972 int retval =
973 my_snprintf (result, sizeof (result), "%015f %d", - Infinityd (), 33, 44, 55);
974 ASSERT (strcmp (result, " -inf 33") == 0
975 || strcmp (result, " -infinity 33") == 0);
976 ASSERT (retval == strlen (result));
979 { /* FLAG_ZERO with NaN. */
980 int retval =
981 my_snprintf (result, sizeof (result), "%050f %d", NaNd (), 33, 44, 55);
982 ASSERT (strlen (result) == 50 + 3
983 && strisnan (result, strspn (result, " "), strlen (result) - 3, 0)
984 && strcmp (result + strlen (result) - 3, " 33") == 0);
985 ASSERT (retval == strlen (result));
988 { /* Precision. */
989 int retval =
990 my_snprintf (result, sizeof (result), "%.f %d", 1234.0, 33, 44, 55);
991 ASSERT (strcmp (result, "1234 33") == 0);
992 ASSERT (retval == strlen (result));
995 { /* Precision with no rounding. */
996 int retval =
997 my_snprintf (result, sizeof (result), "%.2f %d", 999.951, 33, 44, 55);
998 ASSERT (strcmp (result, "999.95 33") == 0);
999 ASSERT (retval == strlen (result));
1002 { /* Precision with rounding. */
1003 int retval =
1004 my_snprintf (result, sizeof (result), "%.2f %d", 999.996, 33, 44, 55);
1005 ASSERT (strcmp (result, "1000.00 33") == 0);
1006 ASSERT (retval == strlen (result));
1009 { /* A positive number. */
1010 int retval =
1011 my_snprintf (result, sizeof (result), "%Lf %d", 12.75L, 33, 44, 55);
1012 ASSERT (strcmp (result, "12.750000 33") == 0);
1013 ASSERT (retval == strlen (result));
1016 { /* A larger positive number. */
1017 int retval =
1018 my_snprintf (result, sizeof (result), "%Lf %d", 1234567.0L, 33, 44, 55);
1019 ASSERT (strcmp (result, "1234567.000000 33") == 0);
1020 ASSERT (retval == strlen (result));
1023 { /* Small and large positive numbers. */
1024 static struct { long double value; const char *string; } data[] =
1026 { 1.234321234321234e-37L, "0.000000" },
1027 { 1.234321234321234e-36L, "0.000000" },
1028 { 1.234321234321234e-35L, "0.000000" },
1029 { 1.234321234321234e-34L, "0.000000" },
1030 { 1.234321234321234e-33L, "0.000000" },
1031 { 1.234321234321234e-32L, "0.000000" },
1032 { 1.234321234321234e-31L, "0.000000" },
1033 { 1.234321234321234e-30L, "0.000000" },
1034 { 1.234321234321234e-29L, "0.000000" },
1035 { 1.234321234321234e-28L, "0.000000" },
1036 { 1.234321234321234e-27L, "0.000000" },
1037 { 1.234321234321234e-26L, "0.000000" },
1038 { 1.234321234321234e-25L, "0.000000" },
1039 { 1.234321234321234e-24L, "0.000000" },
1040 { 1.234321234321234e-23L, "0.000000" },
1041 { 1.234321234321234e-22L, "0.000000" },
1042 { 1.234321234321234e-21L, "0.000000" },
1043 { 1.234321234321234e-20L, "0.000000" },
1044 { 1.234321234321234e-19L, "0.000000" },
1045 { 1.234321234321234e-18L, "0.000000" },
1046 { 1.234321234321234e-17L, "0.000000" },
1047 { 1.234321234321234e-16L, "0.000000" },
1048 { 1.234321234321234e-15L, "0.000000" },
1049 { 1.234321234321234e-14L, "0.000000" },
1050 { 1.234321234321234e-13L, "0.000000" },
1051 { 1.234321234321234e-12L, "0.000000" },
1052 { 1.234321234321234e-11L, "0.000000" },
1053 { 1.234321234321234e-10L, "0.000000" },
1054 { 1.234321234321234e-9L, "0.000000" },
1055 { 1.234321234321234e-8L, "0.000000" },
1056 { 1.234321234321234e-7L, "0.000000" },
1057 { 1.234321234321234e-6L, "0.000001" },
1058 { 1.234321234321234e-5L, "0.000012" },
1059 { 1.234321234321234e-4L, "0.000123" },
1060 { 1.234321234321234e-3L, "0.001234" },
1061 { 1.234321234321234e-2L, "0.012343" },
1062 { 1.234321234321234e-1L, "0.123432" },
1063 { 1.234321234321234L, "1.234321" },
1064 { 1.234321234321234e1L, "12.343212" },
1065 { 1.234321234321234e2L, "123.432123" },
1066 { 1.234321234321234e3L, "1234.321234" },
1067 { 1.234321234321234e4L, "12343.212343" },
1068 { 1.234321234321234e5L, "123432.123432" },
1069 { 1.234321234321234e6L, "1234321.234321" },
1070 { 1.234321234321234e7L, "12343212.343212" },
1071 { 1.234321234321234e8L, "123432123.432123" },
1072 { 1.234321234321234e9L, "1234321234.321234" },
1073 { 1.234321234321234e10L, "12343212343.2123**" },
1074 { 1.234321234321234e11L, "123432123432.123***" },
1075 { 1.234321234321234e12L, "1234321234321.23****" },
1076 { 1.234321234321234e13L, "12343212343212.3*****" },
1077 { 1.234321234321234e14L, "123432123432123.******" },
1078 { 1.234321234321234e15L, "1234321234321234.000000" },
1079 { 1.234321234321234e16L, "123432123432123**.000000" },
1080 { 1.234321234321234e17L, "123432123432123***.000000" },
1081 { 1.234321234321234e18L, "123432123432123****.000000" },
1082 { 1.234321234321234e19L, "123432123432123*****.000000" },
1083 { 1.234321234321234e20L, "123432123432123******.000000" },
1084 { 1.234321234321234e21L, "123432123432123*******.000000" },
1085 { 1.234321234321234e22L, "123432123432123********.000000" },
1086 { 1.234321234321234e23L, "123432123432123*********.000000" },
1087 { 1.234321234321234e24L, "123432123432123**********.000000" },
1088 { 1.234321234321234e25L, "123432123432123***********.000000" },
1089 { 1.234321234321234e26L, "123432123432123************.000000" },
1090 { 1.234321234321234e27L, "123432123432123*************.000000" },
1091 { 1.234321234321234e28L, "123432123432123**************.000000" },
1092 { 1.234321234321234e29L, "123432123432123***************.000000" },
1093 { 1.234321234321234e30L, "123432123432123****************.000000" },
1094 { 1.234321234321234e31L, "123432123432123*****************.000000" },
1095 { 1.234321234321234e32L, "123432123432123******************.000000" },
1096 { 1.234321234321234e33L, "123432123432123*******************.000000" },
1097 { 1.234321234321234e34L, "123432123432123********************.000000" },
1098 { 1.234321234321234e35L, "123432123432123*********************.000000" },
1099 { 1.234321234321234e36L, "123432123432123**********************.000000" }
1101 size_t k;
1102 for (k = 0; k < SIZEOF (data); k++)
1104 int retval =
1105 my_snprintf (result, sizeof (result), "%Lf", data[k].value);
1106 ASSERT (strmatch (data[k].string, result));
1107 ASSERT (retval == strlen (result));
1111 { /* A negative number. */
1112 int retval =
1113 my_snprintf (result, sizeof (result), "%Lf %d", -0.03125L, 33, 44, 55);
1114 ASSERT (strcmp (result, "-0.031250 33") == 0);
1115 ASSERT (retval == strlen (result));
1118 { /* Positive zero. */
1119 int retval =
1120 my_snprintf (result, sizeof (result), "%Lf %d", 0.0L, 33, 44, 55);
1121 ASSERT (strcmp (result, "0.000000 33") == 0);
1122 ASSERT (retval == strlen (result));
1125 { /* Negative zero. */
1126 int retval =
1127 my_snprintf (result, sizeof (result), "%Lf %d", minus_zerol, 33, 44, 55);
1128 if (have_minus_zero ())
1129 ASSERT (strcmp (result, "-0.000000 33") == 0);
1130 ASSERT (retval == strlen (result));
1133 { /* Positive infinity. */
1134 int retval =
1135 my_snprintf (result, sizeof (result), "%Lf %d", Infinityl (), 33, 44, 55);
1136 ASSERT (strcmp (result, "inf 33") == 0
1137 || strcmp (result, "infinity 33") == 0);
1138 ASSERT (retval == strlen (result));
1141 { /* Negative infinity. */
1142 int retval =
1143 my_snprintf (result, sizeof (result), "%Lf %d", - Infinityl (), 33, 44, 55);
1144 ASSERT (strcmp (result, "-inf 33") == 0
1145 || strcmp (result, "-infinity 33") == 0);
1146 ASSERT (retval == strlen (result));
1149 { /* NaN. */
1150 int retval =
1151 my_snprintf (result, sizeof (result), "%Lf %d", NaNl (), 33, 44, 55);
1152 ASSERT (strlen (result) >= 3 + 3
1153 && strisnan (result, 0, strlen (result) - 3, 0)
1154 && strcmp (result + strlen (result) - 3, " 33") == 0);
1155 ASSERT (retval == strlen (result));
1157 #if HAVE_SNANL
1158 { /* Signalling NaN. */
1159 int retval =
1160 my_snprintf (result, sizeof (result), "%Lf %d", SNaNl (), 33, 44, 55);
1161 ASSERT (strlen (result) >= 3 + 3
1162 && strisnan (result, 0, strlen (result) - 3, 0)
1163 && strcmp (result + strlen (result) - 3, " 33") == 0);
1164 ASSERT (retval == strlen (result));
1166 #endif
1167 #if CHECK_PRINTF_SAFE && ((defined __ia64 && LDBL_MANT_DIG == 64) || (defined __x86_64__ || defined __amd64__) || (defined __i386 || defined __i386__ || defined _I386 || defined _M_IX86 || defined _X86_)) && !HAVE_SAME_LONG_DOUBLE_AS_DOUBLE
1168 { /* Quiet NaN. */
1169 static union { unsigned int word[4]; long double value; } x =
1170 { .word = LDBL80_WORDS (0xFFFF, 0xC3333333, 0x00000000) };
1171 int retval =
1172 my_snprintf (result, sizeof (result), "%Lf %d", x.value, 33, 44, 55);
1173 ASSERT (strlen (result) >= 3 + 3
1174 && strisnan (result, 0, strlen (result) - 3, 0)
1175 && strcmp (result + strlen (result) - 3, " 33") == 0);
1176 ASSERT (retval == strlen (result));
1179 /* Signalling NaN. */
1180 static union { unsigned int word[4]; long double value; } x =
1181 { .word = LDBL80_WORDS (0xFFFF, 0x83333333, 0x00000000) };
1182 int retval =
1183 my_snprintf (result, sizeof (result), "%Lf %d", x.value, 33, 44, 55);
1184 ASSERT (strlen (result) >= 3 + 3
1185 && strisnan (result, 0, strlen (result) - 3, 0)
1186 && strcmp (result + strlen (result) - 3, " 33") == 0);
1187 ASSERT (retval == strlen (result));
1189 /* snprintf should print something for noncanonical values. */
1190 { /* Pseudo-NaN. */
1191 static union { unsigned int word[4]; long double value; } x =
1192 { .word = LDBL80_WORDS (0xFFFF, 0x40000001, 0x00000000) };
1193 int retval =
1194 my_snprintf (result, sizeof (result), "%Lf %d", x.value, 33, 44, 55);
1195 ASSERT (retval == strlen (result));
1196 ASSERT (3 < retval && strcmp (result + retval - 3, " 33") == 0);
1198 { /* Pseudo-Infinity. */
1199 static union { unsigned int word[4]; long double value; } x =
1200 { .word = LDBL80_WORDS (0xFFFF, 0x00000000, 0x00000000) };
1201 int retval =
1202 my_snprintf (result, sizeof (result), "%Lf %d", x.value, 33, 44, 55);
1203 ASSERT (retval == strlen (result));
1204 ASSERT (3 < retval && strcmp (result + retval - 3, " 33") == 0);
1206 { /* Pseudo-Zero. */
1207 static union { unsigned int word[4]; long double value; } x =
1208 { .word = LDBL80_WORDS (0x4004, 0x00000000, 0x00000000) };
1209 int retval =
1210 my_snprintf (result, sizeof (result), "%Lf %d", x.value, 33, 44, 55);
1211 ASSERT (retval == strlen (result));
1212 ASSERT (3 < retval && strcmp (result + retval - 3, " 33") == 0);
1214 { /* Unnormalized number. */
1215 static union { unsigned int word[4]; long double value; } x =
1216 { .word = LDBL80_WORDS (0x4000, 0x63333333, 0x00000000) };
1217 int retval =
1218 my_snprintf (result, sizeof (result), "%Lf %d", x.value, 33, 44, 55);
1219 ASSERT (retval == strlen (result));
1220 ASSERT (3 < retval && strcmp (result + retval - 3, " 33") == 0);
1222 { /* Pseudo-Denormal. */
1223 static union { unsigned int word[4]; long double value; } x =
1224 { .word = LDBL80_WORDS (0x0000, 0x83333333, 0x00000000) };
1225 int retval =
1226 my_snprintf (result, sizeof (result), "%Lf %d", x.value, 33, 44, 55);
1227 ASSERT (retval == strlen (result));
1228 ASSERT (3 < retval && strcmp (result + retval - 3, " 33") == 0);
1230 #endif
1232 { /* Width. */
1233 int retval =
1234 my_snprintf (result, sizeof (result), "%10Lf %d", 1.75L, 33, 44, 55);
1235 ASSERT (strcmp (result, " 1.750000 33") == 0);
1236 ASSERT (retval == strlen (result));
1239 { /* Width given as argument. */
1240 int retval =
1241 my_snprintf (result, sizeof (result), "%*Lf %d", 10, 1.75L, 33, 44, 55);
1242 ASSERT (strcmp (result, " 1.750000 33") == 0);
1243 ASSERT (retval == strlen (result));
1246 { /* Negative width given as argument (cf. FLAG_LEFT below). */
1247 int retval =
1248 my_snprintf (result, sizeof (result), "%*Lf %d", -10, 1.75L, 33, 44, 55);
1249 ASSERT (strcmp (result, "1.750000 33") == 0);
1250 ASSERT (retval == strlen (result));
1253 { /* FLAG_LEFT. */
1254 int retval =
1255 my_snprintf (result, sizeof (result), "%-10Lf %d", 1.75L, 33, 44, 55);
1256 ASSERT (strcmp (result, "1.750000 33") == 0);
1257 ASSERT (retval == strlen (result));
1260 { /* FLAG_SHOWSIGN. */
1261 int retval =
1262 my_snprintf (result, sizeof (result), "%+Lf %d", 1.75L, 33, 44, 55);
1263 ASSERT (strcmp (result, "+1.750000 33") == 0);
1264 ASSERT (retval == strlen (result));
1267 { /* FLAG_SPACE. */
1268 int retval =
1269 my_snprintf (result, sizeof (result), "% Lf %d", 1.75L, 33, 44, 55);
1270 ASSERT (strcmp (result, " 1.750000 33") == 0);
1271 ASSERT (retval == strlen (result));
1274 { /* FLAG_ALT. */
1275 int retval =
1276 my_snprintf (result, sizeof (result), "%#Lf %d", 1.75L, 33, 44, 55);
1277 ASSERT (strcmp (result, "1.750000 33") == 0);
1278 ASSERT (retval == strlen (result));
1281 { /* FLAG_ALT. */
1282 int retval =
1283 my_snprintf (result, sizeof (result), "%#.Lf %d", 1.75L, 33, 44, 55);
1284 ASSERT (strcmp (result, "2. 33") == 0);
1285 ASSERT (retval == strlen (result));
1288 { /* FLAG_ZERO with finite number. */
1289 int retval =
1290 my_snprintf (result, sizeof (result), "%015Lf %d", 1234.0L, 33, 44, 55);
1291 ASSERT (strcmp (result, "00001234.000000 33") == 0);
1292 ASSERT (retval == strlen (result));
1295 { /* FLAG_ZERO with infinite number. */
1296 int retval =
1297 my_snprintf (result, sizeof (result), "%015Lf %d", - Infinityl (), 33, 44, 55);
1298 ASSERT (strcmp (result, " -inf 33") == 0
1299 || strcmp (result, " -infinity 33") == 0);
1300 ASSERT (retval == strlen (result));
1303 { /* FLAG_ZERO with NaN. */
1304 int retval =
1305 my_snprintf (result, sizeof (result), "%050Lf %d", NaNl (), 33, 44, 55);
1306 ASSERT (strlen (result) == 50 + 3
1307 && strisnan (result, strspn (result, " "), strlen (result) - 3, 0)
1308 && strcmp (result + strlen (result) - 3, " 33") == 0);
1309 ASSERT (retval == strlen (result));
1312 { /* Precision. */
1313 int retval =
1314 my_snprintf (result, sizeof (result), "%.Lf %d", 1234.0L, 33, 44, 55);
1315 ASSERT (strcmp (result, "1234 33") == 0);
1316 ASSERT (retval == strlen (result));
1319 { /* Precision with no rounding. */
1320 int retval =
1321 my_snprintf (result, sizeof (result), "%.2Lf %d", 999.951L, 33, 44, 55);
1322 ASSERT (strcmp (result, "999.95 33") == 0);
1323 ASSERT (retval == strlen (result));
1326 { /* Precision with rounding. */
1327 int retval =
1328 my_snprintf (result, sizeof (result), "%.2Lf %d", 999.996L, 33, 44, 55);
1329 ASSERT (strcmp (result, "1000.00 33") == 0);
1330 ASSERT (retval == strlen (result));
1333 /* Test the support of the %F format directive. */
1335 { /* A positive number. */
1336 int retval =
1337 my_snprintf (result, sizeof (result), "%F %d", 12.75, 33, 44, 55);
1338 ASSERT (strcmp (result, "12.750000 33") == 0);
1339 ASSERT (retval == strlen (result));
1342 { /* A larger positive number. */
1343 int retval =
1344 my_snprintf (result, sizeof (result), "%F %d", 1234567.0, 33, 44, 55);
1345 ASSERT (strcmp (result, "1234567.000000 33") == 0);
1346 ASSERT (retval == strlen (result));
1349 { /* A negative number. */
1350 int retval =
1351 my_snprintf (result, sizeof (result), "%F %d", -0.03125, 33, 44, 55);
1352 ASSERT (strcmp (result, "-0.031250 33") == 0);
1353 ASSERT (retval == strlen (result));
1356 { /* Positive zero. */
1357 int retval =
1358 my_snprintf (result, sizeof (result), "%F %d", 0.0, 33, 44, 55);
1359 ASSERT (strcmp (result, "0.000000 33") == 0);
1360 ASSERT (retval == strlen (result));
1363 { /* Negative zero. */
1364 int retval =
1365 my_snprintf (result, sizeof (result), "%F %d", minus_zerod, 33, 44, 55);
1366 if (have_minus_zero ())
1367 ASSERT (strcmp (result, "-0.000000 33") == 0);
1368 ASSERT (retval == strlen (result));
1371 { /* Positive infinity. */
1372 int retval =
1373 my_snprintf (result, sizeof (result), "%F %d", Infinityd (), 33, 44, 55);
1374 ASSERT (strcmp (result, "INF 33") == 0
1375 || strcmp (result, "INFINITY 33") == 0);
1376 ASSERT (retval == strlen (result));
1379 { /* Negative infinity. */
1380 int retval =
1381 my_snprintf (result, sizeof (result), "%F %d", - Infinityd (), 33, 44, 55);
1382 ASSERT (strcmp (result, "-INF 33") == 0
1383 || strcmp (result, "-INFINITY 33") == 0);
1384 ASSERT (retval == strlen (result));
1387 { /* NaN. */
1388 int retval =
1389 my_snprintf (result, sizeof (result), "%F %d", NaNd (), 33, 44, 55);
1390 ASSERT (strlen (result) >= 3 + 3
1391 && strisnan (result, 0, strlen (result) - 3, 1)
1392 && strcmp (result + strlen (result) - 3, " 33") == 0);
1393 ASSERT (retval == strlen (result));
1395 #if HAVE_SNAND
1396 { /* Signalling NaN. */
1397 int retval =
1398 my_snprintf (result, sizeof (result), "%F %d", SNaNd (), 33, 44, 55);
1399 ASSERT (strlen (result) >= 3 + 3
1400 && strisnan (result, 0, strlen (result) - 3, 1)
1401 && strcmp (result + strlen (result) - 3, " 33") == 0);
1402 ASSERT (retval == strlen (result));
1404 #endif
1406 { /* FLAG_ZERO. */
1407 int retval =
1408 my_snprintf (result, sizeof (result), "%015F %d", 1234.0, 33, 44, 55);
1409 ASSERT (strcmp (result, "00001234.000000 33") == 0);
1410 ASSERT (retval == strlen (result));
1413 { /* FLAG_ZERO with infinite number. */
1414 int retval =
1415 my_snprintf (result, sizeof (result), "%015F %d", - Infinityd (), 33, 44, 55);
1416 ASSERT (strcmp (result, " -INF 33") == 0
1417 || strcmp (result, " -INFINITY 33") == 0);
1418 ASSERT (retval == strlen (result));
1421 { /* Precision. */
1422 int retval =
1423 my_snprintf (result, sizeof (result), "%.F %d", 1234.0, 33, 44, 55);
1424 ASSERT (strcmp (result, "1234 33") == 0);
1425 ASSERT (retval == strlen (result));
1428 { /* Precision with no rounding. */
1429 int retval =
1430 my_snprintf (result, sizeof (result), "%.2F %d", 999.951, 33, 44, 55);
1431 ASSERT (strcmp (result, "999.95 33") == 0);
1432 ASSERT (retval == strlen (result));
1435 { /* Precision with rounding. */
1436 int retval =
1437 my_snprintf (result, sizeof (result), "%.2F %d", 999.996, 33, 44, 55);
1438 ASSERT (strcmp (result, "1000.00 33") == 0);
1439 ASSERT (retval == strlen (result));
1442 { /* A positive number. */
1443 int retval =
1444 my_snprintf (result, sizeof (result), "%LF %d", 12.75L, 33, 44, 55);
1445 ASSERT (strcmp (result, "12.750000 33") == 0);
1446 ASSERT (retval == strlen (result));
1449 { /* A larger positive number. */
1450 int retval =
1451 my_snprintf (result, sizeof (result), "%LF %d", 1234567.0L, 33, 44, 55);
1452 ASSERT (strcmp (result, "1234567.000000 33") == 0);
1453 ASSERT (retval == strlen (result));
1456 { /* A negative number. */
1457 int retval =
1458 my_snprintf (result, sizeof (result), "%LF %d", -0.03125L, 33, 44, 55);
1459 ASSERT (strcmp (result, "-0.031250 33") == 0);
1460 ASSERT (retval == strlen (result));
1463 { /* Positive zero. */
1464 int retval =
1465 my_snprintf (result, sizeof (result), "%LF %d", 0.0L, 33, 44, 55);
1466 ASSERT (strcmp (result, "0.000000 33") == 0);
1467 ASSERT (retval == strlen (result));
1470 { /* Negative zero. */
1471 int retval =
1472 my_snprintf (result, sizeof (result), "%LF %d", minus_zerol, 33, 44, 55);
1473 if (have_minus_zero ())
1474 ASSERT (strcmp (result, "-0.000000 33") == 0);
1475 ASSERT (retval == strlen (result));
1478 { /* Positive infinity. */
1479 int retval =
1480 my_snprintf (result, sizeof (result), "%LF %d", Infinityl (), 33, 44, 55);
1481 ASSERT (strcmp (result, "INF 33") == 0
1482 || strcmp (result, "INFINITY 33") == 0);
1483 ASSERT (retval == strlen (result));
1486 { /* Negative infinity. */
1487 int retval =
1488 my_snprintf (result, sizeof (result), "%LF %d", - Infinityl (), 33, 44, 55);
1489 ASSERT (strcmp (result, "-INF 33") == 0
1490 || strcmp (result, "-INFINITY 33") == 0);
1491 ASSERT (retval == strlen (result));
1494 { /* NaN. */
1495 int retval =
1496 my_snprintf (result, sizeof (result), "%LF %d", NaNl (), 33, 44, 55);
1497 ASSERT (strlen (result) >= 3 + 3
1498 && strisnan (result, 0, strlen (result) - 3, 1)
1499 && strcmp (result + strlen (result) - 3, " 33") == 0);
1500 ASSERT (retval == strlen (result));
1502 #if HAVE_SNANL
1503 { /* Signalling NaN. */
1504 int retval =
1505 my_snprintf (result, sizeof (result), "%LF %d", SNaNl (), 33, 44, 55);
1506 ASSERT (strlen (result) >= 3 + 3
1507 && strisnan (result, 0, strlen (result) - 3, 1)
1508 && strcmp (result + strlen (result) - 3, " 33") == 0);
1509 ASSERT (retval == strlen (result));
1511 #endif
1513 { /* FLAG_ZERO. */
1514 int retval =
1515 my_snprintf (result, sizeof (result), "%015LF %d", 1234.0L, 33, 44, 55);
1516 ASSERT (strcmp (result, "00001234.000000 33") == 0);
1517 ASSERT (retval == strlen (result));
1520 { /* FLAG_ZERO with infinite number. */
1521 int retval =
1522 my_snprintf (result, sizeof (result), "%015LF %d", - Infinityl (), 33, 44, 55);
1523 ASSERT (strcmp (result, " -INF 33") == 0
1524 || strcmp (result, " -INFINITY 33") == 0);
1525 ASSERT (retval == strlen (result));
1528 { /* Precision. */
1529 int retval =
1530 my_snprintf (result, sizeof (result), "%.LF %d", 1234.0L, 33, 44, 55);
1531 ASSERT (strcmp (result, "1234 33") == 0);
1532 ASSERT (retval == strlen (result));
1535 { /* Precision with no rounding. */
1536 int retval =
1537 my_snprintf (result, sizeof (result), "%.2LF %d", 999.951L, 33, 44, 55);
1538 ASSERT (strcmp (result, "999.95 33") == 0);
1539 ASSERT (retval == strlen (result));
1542 { /* Precision with rounding. */
1543 int retval =
1544 my_snprintf (result, sizeof (result), "%.2LF %d", 999.996L, 33, 44, 55);
1545 ASSERT (strcmp (result, "1000.00 33") == 0);
1546 ASSERT (retval == strlen (result));
1549 /* Test the support of the %e format directive. */
1551 { /* A positive number. */
1552 int retval =
1553 my_snprintf (result, sizeof (result), "%e %d", 12.75, 33, 44, 55);
1554 ASSERT (strcmp (result, "1.275000e+01 33") == 0
1555 || strcmp (result, "1.275000e+001 33") == 0);
1556 ASSERT (retval == strlen (result));
1559 { /* A larger positive number. */
1560 int retval =
1561 my_snprintf (result, sizeof (result), "%e %d", 1234567.0, 33, 44, 55);
1562 ASSERT (strcmp (result, "1.234567e+06 33") == 0
1563 || strcmp (result, "1.234567e+006 33") == 0);
1564 ASSERT (retval == strlen (result));
1567 { /* Small and large positive numbers. */
1568 static struct { double value; const char *string; } data[] =
1570 { 1.234321234321234e-37, "1.234321e-37" },
1571 { 1.234321234321234e-36, "1.234321e-36" },
1572 { 1.234321234321234e-35, "1.234321e-35" },
1573 { 1.234321234321234e-34, "1.234321e-34" },
1574 { 1.234321234321234e-33, "1.234321e-33" },
1575 { 1.234321234321234e-32, "1.234321e-32" },
1576 { 1.234321234321234e-31, "1.234321e-31" },
1577 { 1.234321234321234e-30, "1.234321e-30" },
1578 { 1.234321234321234e-29, "1.234321e-29" },
1579 { 1.234321234321234e-28, "1.234321e-28" },
1580 { 1.234321234321234e-27, "1.234321e-27" },
1581 { 1.234321234321234e-26, "1.234321e-26" },
1582 { 1.234321234321234e-25, "1.234321e-25" },
1583 { 1.234321234321234e-24, "1.234321e-24" },
1584 { 1.234321234321234e-23, "1.234321e-23" },
1585 { 1.234321234321234e-22, "1.234321e-22" },
1586 { 1.234321234321234e-21, "1.234321e-21" },
1587 { 1.234321234321234e-20, "1.234321e-20" },
1588 { 1.234321234321234e-19, "1.234321e-19" },
1589 { 1.234321234321234e-18, "1.234321e-18" },
1590 { 1.234321234321234e-17, "1.234321e-17" },
1591 { 1.234321234321234e-16, "1.234321e-16" },
1592 { 1.234321234321234e-15, "1.234321e-15" },
1593 { 1.234321234321234e-14, "1.234321e-14" },
1594 { 1.234321234321234e-13, "1.234321e-13" },
1595 { 1.234321234321234e-12, "1.234321e-12" },
1596 { 1.234321234321234e-11, "1.234321e-11" },
1597 { 1.234321234321234e-10, "1.234321e-10" },
1598 { 1.234321234321234e-9, "1.234321e-09" },
1599 { 1.234321234321234e-8, "1.234321e-08" },
1600 { 1.234321234321234e-7, "1.234321e-07" },
1601 { 1.234321234321234e-6, "1.234321e-06" },
1602 { 1.234321234321234e-5, "1.234321e-05" },
1603 { 1.234321234321234e-4, "1.234321e-04" },
1604 { 1.234321234321234e-3, "1.234321e-03" },
1605 { 1.234321234321234e-2, "1.234321e-02" },
1606 { 1.234321234321234e-1, "1.234321e-01" },
1607 { 1.234321234321234, "1.234321e+00" },
1608 { 1.234321234321234e1, "1.234321e+01" },
1609 { 1.234321234321234e2, "1.234321e+02" },
1610 { 1.234321234321234e3, "1.234321e+03" },
1611 { 1.234321234321234e4, "1.234321e+04" },
1612 { 1.234321234321234e5, "1.234321e+05" },
1613 { 1.234321234321234e6, "1.234321e+06" },
1614 { 1.234321234321234e7, "1.234321e+07" },
1615 { 1.234321234321234e8, "1.234321e+08" },
1616 { 1.234321234321234e9, "1.234321e+09" },
1617 { 1.234321234321234e10, "1.234321e+10" },
1618 { 1.234321234321234e11, "1.234321e+11" },
1619 { 1.234321234321234e12, "1.234321e+12" },
1620 { 1.234321234321234e13, "1.234321e+13" },
1621 { 1.234321234321234e14, "1.234321e+14" },
1622 { 1.234321234321234e15, "1.234321e+15" },
1623 { 1.234321234321234e16, "1.234321e+16" },
1624 { 1.234321234321234e17, "1.234321e+17" },
1625 { 1.234321234321234e18, "1.234321e+18" },
1626 { 1.234321234321234e19, "1.234321e+19" },
1627 { 1.234321234321234e20, "1.234321e+20" },
1628 { 1.234321234321234e21, "1.234321e+21" },
1629 { 1.234321234321234e22, "1.234321e+22" },
1630 { 1.234321234321234e23, "1.234321e+23" },
1631 { 1.234321234321234e24, "1.234321e+24" },
1632 { 1.234321234321234e25, "1.234321e+25" },
1633 { 1.234321234321234e26, "1.234321e+26" },
1634 { 1.234321234321234e27, "1.234321e+27" },
1635 { 1.234321234321234e28, "1.234321e+28" },
1636 { 1.234321234321234e29, "1.234321e+29" },
1637 { 1.234321234321234e30, "1.234321e+30" },
1638 { 1.234321234321234e31, "1.234321e+31" },
1639 { 1.234321234321234e32, "1.234321e+32" },
1640 { 1.234321234321234e33, "1.234321e+33" },
1641 { 1.234321234321234e34, "1.234321e+34" },
1642 { 1.234321234321234e35, "1.234321e+35" },
1643 { 1.234321234321234e36, "1.234321e+36" }
1645 size_t k;
1646 for (k = 0; k < SIZEOF (data); k++)
1648 int retval =
1649 my_snprintf (result, sizeof (result), "%e", data[k].value);
1650 const char *expected = data[k].string;
1651 ASSERT (strcmp (result, expected) == 0
1652 /* Some implementations produce exponents with 3 digits. */
1653 || (strlen (result) == strlen (expected) + 1
1654 && memcmp (result, expected, strlen (expected) - 2) == 0
1655 && result[strlen (expected) - 2] == '0'
1656 && strcmp (result + strlen (expected) - 1,
1657 expected + strlen (expected) - 2)
1658 == 0));
1659 ASSERT (retval == strlen (result));
1663 { /* A negative number. */
1664 int retval =
1665 my_snprintf (result, sizeof (result), "%e %d", -0.03125, 33, 44, 55);
1666 ASSERT (strcmp (result, "-3.125000e-02 33") == 0
1667 || strcmp (result, "-3.125000e-002 33") == 0);
1668 ASSERT (retval == strlen (result));
1671 { /* Positive zero. */
1672 int retval =
1673 my_snprintf (result, sizeof (result), "%e %d", 0.0, 33, 44, 55);
1674 ASSERT (strcmp (result, "0.000000e+00 33") == 0
1675 || strcmp (result, "0.000000e+000 33") == 0);
1676 ASSERT (retval == strlen (result));
1679 { /* Negative zero. */
1680 int retval =
1681 my_snprintf (result, sizeof (result), "%e %d", minus_zerod, 33, 44, 55);
1682 if (have_minus_zero ())
1683 ASSERT (strcmp (result, "-0.000000e+00 33") == 0
1684 || strcmp (result, "-0.000000e+000 33") == 0);
1685 ASSERT (retval == strlen (result));
1688 { /* Positive infinity. */
1689 int retval =
1690 my_snprintf (result, sizeof (result), "%e %d", Infinityd (), 33, 44, 55);
1691 ASSERT (strcmp (result, "inf 33") == 0
1692 || strcmp (result, "infinity 33") == 0);
1693 ASSERT (retval == strlen (result));
1696 { /* Negative infinity. */
1697 int retval =
1698 my_snprintf (result, sizeof (result), "%e %d", - Infinityd (), 33, 44, 55);
1699 ASSERT (strcmp (result, "-inf 33") == 0
1700 || strcmp (result, "-infinity 33") == 0);
1701 ASSERT (retval == strlen (result));
1704 { /* NaN. */
1705 int retval =
1706 my_snprintf (result, sizeof (result), "%e %d", NaNd (), 33, 44, 55);
1707 ASSERT (strlen (result) >= 3 + 3
1708 && strisnan (result, 0, strlen (result) - 3, 0)
1709 && strcmp (result + strlen (result) - 3, " 33") == 0);
1710 ASSERT (retval == strlen (result));
1712 #if HAVE_SNAND
1713 { /* Signalling NaN. */
1714 int retval =
1715 my_snprintf (result, sizeof (result), "%e %d", SNaNd (), 33, 44, 55);
1716 ASSERT (strlen (result) >= 3 + 3
1717 && strisnan (result, 0, strlen (result) - 3, 0)
1718 && strcmp (result + strlen (result) - 3, " 33") == 0);
1719 ASSERT (retval == strlen (result));
1721 #endif
1723 { /* Width. */
1724 int retval =
1725 my_snprintf (result, sizeof (result), "%15e %d", 1.75, 33, 44, 55);
1726 ASSERT (strcmp (result, " 1.750000e+00 33") == 0
1727 || strcmp (result, " 1.750000e+000 33") == 0);
1728 ASSERT (retval == strlen (result));
1731 { /* Width given as argument. */
1732 int retval =
1733 my_snprintf (result, sizeof (result), "%*e %d", 15, 1.75, 33, 44, 55);
1734 ASSERT (strcmp (result, " 1.750000e+00 33") == 0
1735 || strcmp (result, " 1.750000e+000 33") == 0);
1736 ASSERT (retval == strlen (result));
1739 { /* Negative width given as argument (cf. FLAG_LEFT below). */
1740 int retval =
1741 my_snprintf (result, sizeof (result), "%*e %d", -15, 1.75, 33, 44, 55);
1742 ASSERT (strcmp (result, "1.750000e+00 33") == 0
1743 || strcmp (result, "1.750000e+000 33") == 0);
1744 ASSERT (retval == strlen (result));
1747 { /* FLAG_LEFT. */
1748 int retval =
1749 my_snprintf (result, sizeof (result), "%-15e %d", 1.75, 33, 44, 55);
1750 ASSERT (strcmp (result, "1.750000e+00 33") == 0
1751 || strcmp (result, "1.750000e+000 33") == 0);
1752 ASSERT (retval == strlen (result));
1755 { /* FLAG_SHOWSIGN. */
1756 int retval =
1757 my_snprintf (result, sizeof (result), "%+e %d", 1.75, 33, 44, 55);
1758 ASSERT (strcmp (result, "+1.750000e+00 33") == 0
1759 || strcmp (result, "+1.750000e+000 33") == 0);
1760 ASSERT (retval == strlen (result));
1763 { /* FLAG_SPACE. */
1764 int retval =
1765 my_snprintf (result, sizeof (result), "% e %d", 1.75, 33, 44, 55);
1766 ASSERT (strcmp (result, " 1.750000e+00 33") == 0
1767 || strcmp (result, " 1.750000e+000 33") == 0);
1768 ASSERT (retval == strlen (result));
1771 { /* FLAG_ALT. */
1772 int retval =
1773 my_snprintf (result, sizeof (result), "%#e %d", 1.75, 33, 44, 55);
1774 ASSERT (strcmp (result, "1.750000e+00 33") == 0
1775 || strcmp (result, "1.750000e+000 33") == 0);
1776 ASSERT (retval == strlen (result));
1779 { /* FLAG_ALT. */
1780 int retval =
1781 my_snprintf (result, sizeof (result), "%#.e %d", 1.75, 33, 44, 55);
1782 ASSERT (strcmp (result, "2.e+00 33") == 0
1783 || strcmp (result, "2.e+000 33") == 0);
1784 ASSERT (retval == strlen (result));
1787 { /* FLAG_ALT. */
1788 int retval =
1789 my_snprintf (result, sizeof (result), "%#.e %d", 9.75, 33, 44, 55);
1790 ASSERT (strcmp (result, "1.e+01 33") == 0
1791 || strcmp (result, "1.e+001 33") == 0);
1792 ASSERT (retval == strlen (result));
1795 { /* FLAG_ZERO with finite number. */
1796 int retval =
1797 my_snprintf (result, sizeof (result), "%015e %d", 1234.0, 33, 44, 55);
1798 ASSERT (strcmp (result, "0001.234000e+03 33") == 0
1799 || strcmp (result, "001.234000e+003 33") == 0);
1800 ASSERT (retval == strlen (result));
1803 { /* FLAG_ZERO with infinite number. */
1804 int retval =
1805 my_snprintf (result, sizeof (result), "%015e %d", - Infinityd (), 33, 44, 55);
1806 ASSERT (strcmp (result, " -inf 33") == 0
1807 || strcmp (result, " -infinity 33") == 0);
1808 ASSERT (retval == strlen (result));
1811 { /* FLAG_ZERO with NaN. */
1812 int retval =
1813 my_snprintf (result, sizeof (result), "%050e %d", NaNd (), 33, 44, 55);
1814 ASSERT (strlen (result) == 50 + 3
1815 && strisnan (result, strspn (result, " "), strlen (result) - 3, 0)
1816 && strcmp (result + strlen (result) - 3, " 33") == 0);
1817 ASSERT (retval == strlen (result));
1820 { /* Precision. */
1821 int retval =
1822 my_snprintf (result, sizeof (result), "%.e %d", 1234.0, 33, 44, 55);
1823 ASSERT (strcmp (result, "1e+03 33") == 0
1824 || strcmp (result, "1e+003 33") == 0);
1825 ASSERT (retval == strlen (result));
1828 { /* Precision with no rounding. */
1829 int retval =
1830 my_snprintf (result, sizeof (result), "%.4e %d", 999.951, 33, 44, 55);
1831 ASSERT (strcmp (result, "9.9995e+02 33") == 0
1832 || strcmp (result, "9.9995e+002 33") == 0);
1833 ASSERT (retval == strlen (result));
1836 { /* Precision with rounding. */
1837 int retval =
1838 my_snprintf (result, sizeof (result), "%.4e %d", 999.996, 33, 44, 55);
1839 ASSERT (strcmp (result, "1.0000e+03 33") == 0
1840 || strcmp (result, "1.0000e+003 33") == 0);
1841 ASSERT (retval == strlen (result));
1844 { /* A positive number. */
1845 int retval =
1846 my_snprintf (result, sizeof (result), "%Le %d", 12.75L, 33, 44, 55);
1847 ASSERT (strcmp (result, "1.275000e+01 33") == 0
1848 || strcmp (result, "1.275000e+001 33") == 0);
1849 ASSERT (retval == strlen (result));
1852 { /* A larger positive number. */
1853 int retval =
1854 my_snprintf (result, sizeof (result), "%Le %d", 1234567.0L, 33, 44, 55);
1855 ASSERT (strcmp (result, "1.234567e+06 33") == 0
1856 || strcmp (result, "1.234567e+006 33") == 0);
1857 ASSERT (retval == strlen (result));
1860 { /* Small and large positive numbers. */
1861 static struct { long double value; const char *string; } data[] =
1863 { 1.234321234321234e-37L, "1.234321e-37" },
1864 { 1.234321234321234e-36L, "1.234321e-36" },
1865 { 1.234321234321234e-35L, "1.234321e-35" },
1866 { 1.234321234321234e-34L, "1.234321e-34" },
1867 { 1.234321234321234e-33L, "1.234321e-33" },
1868 { 1.234321234321234e-32L, "1.234321e-32" },
1869 { 1.234321234321234e-31L, "1.234321e-31" },
1870 { 1.234321234321234e-30L, "1.234321e-30" },
1871 { 1.234321234321234e-29L, "1.234321e-29" },
1872 { 1.234321234321234e-28L, "1.234321e-28" },
1873 { 1.234321234321234e-27L, "1.234321e-27" },
1874 { 1.234321234321234e-26L, "1.234321e-26" },
1875 { 1.234321234321234e-25L, "1.234321e-25" },
1876 { 1.234321234321234e-24L, "1.234321e-24" },
1877 { 1.234321234321234e-23L, "1.234321e-23" },
1878 { 1.234321234321234e-22L, "1.234321e-22" },
1879 { 1.234321234321234e-21L, "1.234321e-21" },
1880 { 1.234321234321234e-20L, "1.234321e-20" },
1881 { 1.234321234321234e-19L, "1.234321e-19" },
1882 { 1.234321234321234e-18L, "1.234321e-18" },
1883 { 1.234321234321234e-17L, "1.234321e-17" },
1884 { 1.234321234321234e-16L, "1.234321e-16" },
1885 { 1.234321234321234e-15L, "1.234321e-15" },
1886 { 1.234321234321234e-14L, "1.234321e-14" },
1887 { 1.234321234321234e-13L, "1.234321e-13" },
1888 { 1.234321234321234e-12L, "1.234321e-12" },
1889 { 1.234321234321234e-11L, "1.234321e-11" },
1890 { 1.234321234321234e-10L, "1.234321e-10" },
1891 { 1.234321234321234e-9L, "1.234321e-09" },
1892 { 1.234321234321234e-8L, "1.234321e-08" },
1893 { 1.234321234321234e-7L, "1.234321e-07" },
1894 { 1.234321234321234e-6L, "1.234321e-06" },
1895 { 1.234321234321234e-5L, "1.234321e-05" },
1896 { 1.234321234321234e-4L, "1.234321e-04" },
1897 { 1.234321234321234e-3L, "1.234321e-03" },
1898 { 1.234321234321234e-2L, "1.234321e-02" },
1899 { 1.234321234321234e-1L, "1.234321e-01" },
1900 { 1.234321234321234L, "1.234321e+00" },
1901 { 1.234321234321234e1L, "1.234321e+01" },
1902 { 1.234321234321234e2L, "1.234321e+02" },
1903 { 1.234321234321234e3L, "1.234321e+03" },
1904 { 1.234321234321234e4L, "1.234321e+04" },
1905 { 1.234321234321234e5L, "1.234321e+05" },
1906 { 1.234321234321234e6L, "1.234321e+06" },
1907 { 1.234321234321234e7L, "1.234321e+07" },
1908 { 1.234321234321234e8L, "1.234321e+08" },
1909 { 1.234321234321234e9L, "1.234321e+09" },
1910 { 1.234321234321234e10L, "1.234321e+10" },
1911 { 1.234321234321234e11L, "1.234321e+11" },
1912 { 1.234321234321234e12L, "1.234321e+12" },
1913 { 1.234321234321234e13L, "1.234321e+13" },
1914 { 1.234321234321234e14L, "1.234321e+14" },
1915 { 1.234321234321234e15L, "1.234321e+15" },
1916 { 1.234321234321234e16L, "1.234321e+16" },
1917 { 1.234321234321234e17L, "1.234321e+17" },
1918 { 1.234321234321234e18L, "1.234321e+18" },
1919 { 1.234321234321234e19L, "1.234321e+19" },
1920 { 1.234321234321234e20L, "1.234321e+20" },
1921 { 1.234321234321234e21L, "1.234321e+21" },
1922 { 1.234321234321234e22L, "1.234321e+22" },
1923 { 1.234321234321234e23L, "1.234321e+23" },
1924 { 1.234321234321234e24L, "1.234321e+24" },
1925 { 1.234321234321234e25L, "1.234321e+25" },
1926 { 1.234321234321234e26L, "1.234321e+26" },
1927 { 1.234321234321234e27L, "1.234321e+27" },
1928 { 1.234321234321234e28L, "1.234321e+28" },
1929 { 1.234321234321234e29L, "1.234321e+29" },
1930 { 1.234321234321234e30L, "1.234321e+30" },
1931 { 1.234321234321234e31L, "1.234321e+31" },
1932 { 1.234321234321234e32L, "1.234321e+32" },
1933 { 1.234321234321234e33L, "1.234321e+33" },
1934 { 1.234321234321234e34L, "1.234321e+34" },
1935 { 1.234321234321234e35L, "1.234321e+35" },
1936 { 1.234321234321234e36L, "1.234321e+36" }
1938 size_t k;
1939 for (k = 0; k < SIZEOF (data); k++)
1941 int retval =
1942 my_snprintf (result, sizeof (result), "%Le", data[k].value);
1943 const char *expected = data[k].string;
1944 ASSERT (strcmp (result, expected) == 0
1945 /* Some implementations produce exponents with 3 digits. */
1946 || (strlen (result) == strlen (expected) + 1
1947 && memcmp (result, expected, strlen (expected) - 2) == 0
1948 && result[strlen (expected) - 2] == '0'
1949 && strcmp (result + strlen (expected) - 1,
1950 expected + strlen (expected) - 2)
1951 == 0));
1952 ASSERT (retval == strlen (result));
1956 { /* A negative number. */
1957 int retval =
1958 my_snprintf (result, sizeof (result), "%Le %d", -0.03125L, 33, 44, 55);
1959 ASSERT (strcmp (result, "-3.125000e-02 33") == 0
1960 || strcmp (result, "-3.125000e-002 33") == 0);
1961 ASSERT (retval == strlen (result));
1964 { /* Positive zero. */
1965 int retval =
1966 my_snprintf (result, sizeof (result), "%Le %d", 0.0L, 33, 44, 55);
1967 ASSERT (strcmp (result, "0.000000e+00 33") == 0
1968 || strcmp (result, "0.000000e+000 33") == 0);
1969 ASSERT (retval == strlen (result));
1972 { /* Negative zero. */
1973 int retval =
1974 my_snprintf (result, sizeof (result), "%Le %d", minus_zerol, 33, 44, 55);
1975 if (have_minus_zero ())
1976 ASSERT (strcmp (result, "-0.000000e+00 33") == 0
1977 || strcmp (result, "-0.000000e+000 33") == 0);
1978 ASSERT (retval == strlen (result));
1981 { /* Positive infinity. */
1982 int retval =
1983 my_snprintf (result, sizeof (result), "%Le %d", Infinityl (), 33, 44, 55);
1984 ASSERT (strcmp (result, "inf 33") == 0
1985 || strcmp (result, "infinity 33") == 0);
1986 ASSERT (retval == strlen (result));
1989 { /* Negative infinity. */
1990 int retval =
1991 my_snprintf (result, sizeof (result), "%Le %d", - Infinityl (), 33, 44, 55);
1992 ASSERT (strcmp (result, "-inf 33") == 0
1993 || strcmp (result, "-infinity 33") == 0);
1994 ASSERT (retval == strlen (result));
1997 { /* NaN. */
1998 int retval =
1999 my_snprintf (result, sizeof (result), "%Le %d", NaNl (), 33, 44, 55);
2000 ASSERT (strlen (result) >= 3 + 3
2001 && strisnan (result, 0, strlen (result) - 3, 0)
2002 && strcmp (result + strlen (result) - 3, " 33") == 0);
2003 ASSERT (retval == strlen (result));
2005 #if HAVE_SNANL
2006 { /* Signalling NaN. */
2007 int retval =
2008 my_snprintf (result, sizeof (result), "%Le %d", SNaNl (), 33, 44, 55);
2009 ASSERT (strlen (result) >= 3 + 3
2010 && strisnan (result, 0, strlen (result) - 3, 0)
2011 && strcmp (result + strlen (result) - 3, " 33") == 0);
2012 ASSERT (retval == strlen (result));
2014 #endif
2015 #if CHECK_PRINTF_SAFE && ((defined __ia64 && LDBL_MANT_DIG == 64) || (defined __x86_64__ || defined __amd64__) || (defined __i386 || defined __i386__ || defined _I386 || defined _M_IX86 || defined _X86_)) && !HAVE_SAME_LONG_DOUBLE_AS_DOUBLE
2016 { /* Quiet NaN. */
2017 static union { unsigned int word[4]; long double value; } x =
2018 { .word = LDBL80_WORDS (0xFFFF, 0xC3333333, 0x00000000) };
2019 int retval =
2020 my_snprintf (result, sizeof (result), "%Le %d", x.value, 33, 44, 55);
2021 ASSERT (strlen (result) >= 3 + 3
2022 && strisnan (result, 0, strlen (result) - 3, 0)
2023 && strcmp (result + strlen (result) - 3, " 33") == 0);
2024 ASSERT (retval == strlen (result));
2027 /* Signalling NaN. */
2028 static union { unsigned int word[4]; long double value; } x =
2029 { .word = LDBL80_WORDS (0xFFFF, 0x83333333, 0x00000000) };
2030 int retval =
2031 my_snprintf (result, sizeof (result), "%Le %d", x.value, 33, 44, 55);
2032 ASSERT (strlen (result) >= 3 + 3
2033 && strisnan (result, 0, strlen (result) - 3, 0)
2034 && strcmp (result + strlen (result) - 3, " 33") == 0);
2035 ASSERT (retval == strlen (result));
2037 /* snprintf should print something for noncanonical values. */
2038 { /* Pseudo-NaN. */
2039 static union { unsigned int word[4]; long double value; } x =
2040 { .word = LDBL80_WORDS (0xFFFF, 0x40000001, 0x00000000) };
2041 int retval =
2042 my_snprintf (result, sizeof (result), "%Le %d", x.value, 33, 44, 55);
2043 ASSERT (retval == strlen (result));
2044 ASSERT (3 < retval && strcmp (result + retval - 3, " 33") == 0);
2046 { /* Pseudo-Infinity. */
2047 static union { unsigned int word[4]; long double value; } x =
2048 { .word = LDBL80_WORDS (0xFFFF, 0x00000000, 0x00000000) };
2049 int retval =
2050 my_snprintf (result, sizeof (result), "%Le %d", x.value, 33, 44, 55);
2051 ASSERT (retval == strlen (result));
2052 ASSERT (3 < retval && strcmp (result + retval - 3, " 33") == 0);
2054 { /* Pseudo-Zero. */
2055 static union { unsigned int word[4]; long double value; } x =
2056 { .word = LDBL80_WORDS (0x4004, 0x00000000, 0x00000000) };
2057 int retval =
2058 my_snprintf (result, sizeof (result), "%Le %d", x.value, 33, 44, 55);
2059 ASSERT (retval == strlen (result));
2060 ASSERT (3 < retval && strcmp (result + retval - 3, " 33") == 0);
2062 { /* Unnormalized number. */
2063 static union { unsigned int word[4]; long double value; } x =
2064 { .word = LDBL80_WORDS (0x4000, 0x63333333, 0x00000000) };
2065 int retval =
2066 my_snprintf (result, sizeof (result), "%Le %d", x.value, 33, 44, 55);
2067 ASSERT (retval == strlen (result));
2068 ASSERT (3 < retval && strcmp (result + retval - 3, " 33") == 0);
2070 { /* Pseudo-Denormal. */
2071 static union { unsigned int word[4]; long double value; } x =
2072 { .word = LDBL80_WORDS (0x0000, 0x83333333, 0x00000000) };
2073 int retval =
2074 my_snprintf (result, sizeof (result), "%Le %d", x.value, 33, 44, 55);
2075 ASSERT (retval == strlen (result));
2076 ASSERT (3 < retval && strcmp (result + retval - 3, " 33") == 0);
2078 #endif
2080 { /* Width. */
2081 int retval =
2082 my_snprintf (result, sizeof (result), "%15Le %d", 1.75L, 33, 44, 55);
2083 ASSERT (strcmp (result, " 1.750000e+00 33") == 0
2084 || strcmp (result, " 1.750000e+000 33") == 0);
2085 ASSERT (retval == strlen (result));
2088 { /* Width given as argument. */
2089 int retval =
2090 my_snprintf (result, sizeof (result), "%*Le %d", 15, 1.75L, 33, 44, 55);
2091 ASSERT (strcmp (result, " 1.750000e+00 33") == 0
2092 || strcmp (result, " 1.750000e+000 33") == 0);
2093 ASSERT (retval == strlen (result));
2096 { /* Negative width given as argument (cf. FLAG_LEFT below). */
2097 int retval =
2098 my_snprintf (result, sizeof (result), "%*Le %d", -15, 1.75L, 33, 44, 55);
2099 ASSERT (strcmp (result, "1.750000e+00 33") == 0
2100 || strcmp (result, "1.750000e+000 33") == 0);
2101 ASSERT (retval == strlen (result));
2104 { /* FLAG_LEFT. */
2105 int retval =
2106 my_snprintf (result, sizeof (result), "%-15Le %d", 1.75L, 33, 44, 55);
2107 ASSERT (strcmp (result, "1.750000e+00 33") == 0
2108 || strcmp (result, "1.750000e+000 33") == 0);
2109 ASSERT (retval == strlen (result));
2112 { /* FLAG_SHOWSIGN. */
2113 int retval =
2114 my_snprintf (result, sizeof (result), "%+Le %d", 1.75L, 33, 44, 55);
2115 ASSERT (strcmp (result, "+1.750000e+00 33") == 0
2116 || strcmp (result, "+1.750000e+000 33") == 0);
2117 ASSERT (retval == strlen (result));
2120 { /* FLAG_SPACE. */
2121 int retval =
2122 my_snprintf (result, sizeof (result), "% Le %d", 1.75L, 33, 44, 55);
2123 ASSERT (strcmp (result, " 1.750000e+00 33") == 0
2124 || strcmp (result, " 1.750000e+000 33") == 0);
2125 ASSERT (retval == strlen (result));
2128 { /* FLAG_ALT. */
2129 int retval =
2130 my_snprintf (result, sizeof (result), "%#Le %d", 1.75L, 33, 44, 55);
2131 ASSERT (strcmp (result, "1.750000e+00 33") == 0
2132 || strcmp (result, "1.750000e+000 33") == 0);
2133 ASSERT (retval == strlen (result));
2136 { /* FLAG_ALT. */
2137 int retval =
2138 my_snprintf (result, sizeof (result), "%#.Le %d", 1.75L, 33, 44, 55);
2139 ASSERT (strcmp (result, "2.e+00 33") == 0
2140 || strcmp (result, "2.e+000 33") == 0);
2141 ASSERT (retval == strlen (result));
2144 { /* FLAG_ALT. */
2145 int retval =
2146 my_snprintf (result, sizeof (result), "%#.Le %d", 9.75L, 33, 44, 55);
2147 ASSERT (strcmp (result, "1.e+01 33") == 0
2148 || strcmp (result, "1.e+001 33") == 0);
2149 ASSERT (retval == strlen (result));
2152 { /* FLAG_ZERO with finite number. */
2153 int retval =
2154 my_snprintf (result, sizeof (result), "%015Le %d", 1234.0L, 33, 44, 55);
2155 ASSERT (strcmp (result, "0001.234000e+03 33") == 0
2156 || strcmp (result, "001.234000e+003 33") == 0);
2157 ASSERT (retval == strlen (result));
2160 { /* FLAG_ZERO with infinite number. */
2161 int retval =
2162 my_snprintf (result, sizeof (result), "%015Le %d", - Infinityl (), 33, 44, 55);
2163 ASSERT (strcmp (result, " -inf 33") == 0
2164 || strcmp (result, " -infinity 33") == 0);
2165 ASSERT (retval == strlen (result));
2168 { /* FLAG_ZERO with NaN. */
2169 int retval =
2170 my_snprintf (result, sizeof (result), "%050Le %d", NaNl (), 33, 44, 55);
2171 ASSERT (strlen (result) == 50 + 3
2172 && strisnan (result, strspn (result, " "), strlen (result) - 3, 0)
2173 && strcmp (result + strlen (result) - 3, " 33") == 0);
2174 ASSERT (retval == strlen (result));
2177 { /* Precision. */
2178 int retval =
2179 my_snprintf (result, sizeof (result), "%.Le %d", 1234.0L, 33, 44, 55);
2180 ASSERT (strcmp (result, "1e+03 33") == 0
2181 || strcmp (result, "1e+003 33") == 0);
2182 ASSERT (retval == strlen (result));
2185 { /* Precision with no rounding. */
2186 int retval =
2187 my_snprintf (result, sizeof (result), "%.4Le %d", 999.951L, 33, 44, 55);
2188 ASSERT (strcmp (result, "9.9995e+02 33") == 0
2189 || strcmp (result, "9.9995e+002 33") == 0);
2190 ASSERT (retval == strlen (result));
2193 { /* Precision with rounding. */
2194 int retval =
2195 my_snprintf (result, sizeof (result), "%.4Le %d", 999.996L, 33, 44, 55);
2196 ASSERT (strcmp (result, "1.0000e+03 33") == 0
2197 || strcmp (result, "1.0000e+003 33") == 0);
2198 ASSERT (retval == strlen (result));
2201 /* Test the support of the %g format directive. */
2203 { /* A positive number. */
2204 int retval =
2205 my_snprintf (result, sizeof (result), "%g %d", 12.75, 33, 44, 55);
2206 ASSERT (strcmp (result, "12.75 33") == 0);
2207 ASSERT (retval == strlen (result));
2210 { /* A larger positive number. */
2211 int retval =
2212 my_snprintf (result, sizeof (result), "%g %d", 1234567.0, 33, 44, 55);
2213 ASSERT (strcmp (result, "1.23457e+06 33") == 0
2214 || strcmp (result, "1.23457e+006 33") == 0);
2215 ASSERT (retval == strlen (result));
2218 { /* Small and large positive numbers. */
2219 static struct { double value; const char *string; } data[] =
2221 { 1.234321234321234e-37, "1.23432e-37" },
2222 { 1.234321234321234e-36, "1.23432e-36" },
2223 { 1.234321234321234e-35, "1.23432e-35" },
2224 { 1.234321234321234e-34, "1.23432e-34" },
2225 { 1.234321234321234e-33, "1.23432e-33" },
2226 { 1.234321234321234e-32, "1.23432e-32" },
2227 { 1.234321234321234e-31, "1.23432e-31" },
2228 { 1.234321234321234e-30, "1.23432e-30" },
2229 { 1.234321234321234e-29, "1.23432e-29" },
2230 { 1.234321234321234e-28, "1.23432e-28" },
2231 { 1.234321234321234e-27, "1.23432e-27" },
2232 { 1.234321234321234e-26, "1.23432e-26" },
2233 { 1.234321234321234e-25, "1.23432e-25" },
2234 { 1.234321234321234e-24, "1.23432e-24" },
2235 { 1.234321234321234e-23, "1.23432e-23" },
2236 { 1.234321234321234e-22, "1.23432e-22" },
2237 { 1.234321234321234e-21, "1.23432e-21" },
2238 { 1.234321234321234e-20, "1.23432e-20" },
2239 { 1.234321234321234e-19, "1.23432e-19" },
2240 { 1.234321234321234e-18, "1.23432e-18" },
2241 { 1.234321234321234e-17, "1.23432e-17" },
2242 { 1.234321234321234e-16, "1.23432e-16" },
2243 { 1.234321234321234e-15, "1.23432e-15" },
2244 { 1.234321234321234e-14, "1.23432e-14" },
2245 { 1.234321234321234e-13, "1.23432e-13" },
2246 { 1.234321234321234e-12, "1.23432e-12" },
2247 { 1.234321234321234e-11, "1.23432e-11" },
2248 { 1.234321234321234e-10, "1.23432e-10" },
2249 { 1.234321234321234e-9, "1.23432e-09" },
2250 { 1.234321234321234e-8, "1.23432e-08" },
2251 { 1.234321234321234e-7, "1.23432e-07" },
2252 { 1.234321234321234e-6, "1.23432e-06" },
2253 { 1.234321234321234e-5, "1.23432e-05" },
2254 { 1.234321234321234e-4, "0.000123432" },
2255 { 1.234321234321234e-3, "0.00123432" },
2256 { 1.234321234321234e-2, "0.0123432" },
2257 { 1.234321234321234e-1, "0.123432" },
2258 { 1.234321234321234, "1.23432" },
2259 { 1.234321234321234e1, "12.3432" },
2260 { 1.234321234321234e2, "123.432" },
2261 { 1.234321234321234e3, "1234.32" },
2262 { 1.234321234321234e4, "12343.2" },
2263 { 1.234321234321234e5, "123432" },
2264 { 1.234321234321234e6, "1.23432e+06" },
2265 { 1.234321234321234e7, "1.23432e+07" },
2266 { 1.234321234321234e8, "1.23432e+08" },
2267 { 1.234321234321234e9, "1.23432e+09" },
2268 { 1.234321234321234e10, "1.23432e+10" },
2269 { 1.234321234321234e11, "1.23432e+11" },
2270 { 1.234321234321234e12, "1.23432e+12" },
2271 { 1.234321234321234e13, "1.23432e+13" },
2272 { 1.234321234321234e14, "1.23432e+14" },
2273 { 1.234321234321234e15, "1.23432e+15" },
2274 { 1.234321234321234e16, "1.23432e+16" },
2275 { 1.234321234321234e17, "1.23432e+17" },
2276 { 1.234321234321234e18, "1.23432e+18" },
2277 { 1.234321234321234e19, "1.23432e+19" },
2278 { 1.234321234321234e20, "1.23432e+20" },
2279 { 1.234321234321234e21, "1.23432e+21" },
2280 { 1.234321234321234e22, "1.23432e+22" },
2281 { 1.234321234321234e23, "1.23432e+23" },
2282 { 1.234321234321234e24, "1.23432e+24" },
2283 { 1.234321234321234e25, "1.23432e+25" },
2284 { 1.234321234321234e26, "1.23432e+26" },
2285 { 1.234321234321234e27, "1.23432e+27" },
2286 { 1.234321234321234e28, "1.23432e+28" },
2287 { 1.234321234321234e29, "1.23432e+29" },
2288 { 1.234321234321234e30, "1.23432e+30" },
2289 { 1.234321234321234e31, "1.23432e+31" },
2290 { 1.234321234321234e32, "1.23432e+32" },
2291 { 1.234321234321234e33, "1.23432e+33" },
2292 { 1.234321234321234e34, "1.23432e+34" },
2293 { 1.234321234321234e35, "1.23432e+35" },
2294 { 1.234321234321234e36, "1.23432e+36" }
2296 size_t k;
2297 for (k = 0; k < SIZEOF (data); k++)
2299 int retval =
2300 my_snprintf (result, sizeof (result), "%g", data[k].value);
2301 const char *expected = data[k].string;
2302 ASSERT (strcmp (result, expected) == 0
2303 /* Some implementations produce exponents with 3 digits. */
2304 || (expected[strlen (expected) - 4] == 'e'
2305 && strlen (result) == strlen (expected) + 1
2306 && memcmp (result, expected, strlen (expected) - 2) == 0
2307 && result[strlen (expected) - 2] == '0'
2308 && strcmp (result + strlen (expected) - 1,
2309 expected + strlen (expected) - 2)
2310 == 0));
2311 ASSERT (retval == strlen (result));
2315 { /* A negative number. */
2316 int retval =
2317 my_snprintf (result, sizeof (result), "%g %d", -0.03125, 33, 44, 55);
2318 ASSERT (strcmp (result, "-0.03125 33") == 0);
2319 ASSERT (retval == strlen (result));
2322 { /* Positive zero. */
2323 int retval =
2324 my_snprintf (result, sizeof (result), "%g %d", 0.0, 33, 44, 55);
2325 ASSERT (strcmp (result, "0 33") == 0);
2326 ASSERT (retval == strlen (result));
2329 { /* Negative zero. */
2330 int retval =
2331 my_snprintf (result, sizeof (result), "%g %d", minus_zerod, 33, 44, 55);
2332 if (have_minus_zero ())
2333 ASSERT (strcmp (result, "-0 33") == 0);
2334 ASSERT (retval == strlen (result));
2337 { /* Positive infinity. */
2338 int retval =
2339 my_snprintf (result, sizeof (result), "%g %d", Infinityd (), 33, 44, 55);
2340 ASSERT (strcmp (result, "inf 33") == 0
2341 || strcmp (result, "infinity 33") == 0);
2342 ASSERT (retval == strlen (result));
2345 { /* Negative infinity. */
2346 int retval =
2347 my_snprintf (result, sizeof (result), "%g %d", - Infinityd (), 33, 44, 55);
2348 ASSERT (strcmp (result, "-inf 33") == 0
2349 || strcmp (result, "-infinity 33") == 0);
2350 ASSERT (retval == strlen (result));
2353 { /* NaN. */
2354 int retval =
2355 my_snprintf (result, sizeof (result), "%g %d", NaNd (), 33, 44, 55);
2356 ASSERT (strlen (result) >= 3 + 3
2357 && strisnan (result, 0, strlen (result) - 3, 0)
2358 && strcmp (result + strlen (result) - 3, " 33") == 0);
2359 ASSERT (retval == strlen (result));
2361 #if HAVE_SNAND
2362 { /* Signalling NaN. */
2363 int retval =
2364 my_snprintf (result, sizeof (result), "%g %d", SNaNd (), 33, 44, 55);
2365 ASSERT (strlen (result) >= 3 + 3
2366 && strisnan (result, 0, strlen (result) - 3, 0)
2367 && strcmp (result + strlen (result) - 3, " 33") == 0);
2368 ASSERT (retval == strlen (result));
2370 #endif
2372 { /* Width. */
2373 int retval =
2374 my_snprintf (result, sizeof (result), "%10g %d", 1.75, 33, 44, 55);
2375 ASSERT (strcmp (result, " 1.75 33") == 0);
2376 ASSERT (retval == strlen (result));
2379 { /* Width given as argument. */
2380 int retval =
2381 my_snprintf (result, sizeof (result), "%*g %d", 10, 1.75, 33, 44, 55);
2382 ASSERT (strcmp (result, " 1.75 33") == 0);
2383 ASSERT (retval == strlen (result));
2386 { /* Negative width given as argument (cf. FLAG_LEFT below). */
2387 int retval =
2388 my_snprintf (result, sizeof (result), "%*g %d", -10, 1.75, 33, 44, 55);
2389 ASSERT (strcmp (result, "1.75 33") == 0);
2390 ASSERT (retval == strlen (result));
2393 { /* FLAG_LEFT. */
2394 int retval =
2395 my_snprintf (result, sizeof (result), "%-10g %d", 1.75, 33, 44, 55);
2396 ASSERT (strcmp (result, "1.75 33") == 0);
2397 ASSERT (retval == strlen (result));
2400 { /* FLAG_SHOWSIGN. */
2401 int retval =
2402 my_snprintf (result, sizeof (result), "%+g %d", 1.75, 33, 44, 55);
2403 ASSERT (strcmp (result, "+1.75 33") == 0);
2404 ASSERT (retval == strlen (result));
2407 { /* FLAG_SPACE. */
2408 int retval =
2409 my_snprintf (result, sizeof (result), "% g %d", 1.75, 33, 44, 55);
2410 ASSERT (strcmp (result, " 1.75 33") == 0);
2411 ASSERT (retval == strlen (result));
2414 { /* FLAG_ALT. */
2415 int retval =
2416 my_snprintf (result, sizeof (result), "%#g %d", 1.75, 33, 44, 55);
2417 ASSERT (strcmp (result, "1.75000 33") == 0);
2418 ASSERT (retval == strlen (result));
2421 { /* FLAG_ALT. */
2422 int retval =
2423 my_snprintf (result, sizeof (result), "%#.g %d", 1.75, 33, 44, 55);
2424 ASSERT (strcmp (result, "2. 33") == 0);
2425 ASSERT (retval == strlen (result));
2428 { /* FLAG_ALT. */
2429 int retval =
2430 my_snprintf (result, sizeof (result), "%#.g %d", 9.75, 33, 44, 55);
2431 ASSERT (strcmp (result, "1.e+01 33") == 0
2432 || strcmp (result, "1.e+001 33") == 0);
2433 ASSERT (retval == strlen (result));
2436 { /* FLAG_ZERO with finite number. */
2437 int retval =
2438 my_snprintf (result, sizeof (result), "%010g %d", 1234.0, 33, 44, 55);
2439 ASSERT (strcmp (result, "0000001234 33") == 0);
2440 ASSERT (retval == strlen (result));
2443 { /* FLAG_ZERO with infinite number. */
2444 int retval =
2445 my_snprintf (result, sizeof (result), "%015g %d", - Infinityd (), 33, 44, 55);
2446 ASSERT (strcmp (result, " -inf 33") == 0
2447 || strcmp (result, " -infinity 33") == 0);
2448 ASSERT (retval == strlen (result));
2451 { /* FLAG_ZERO with NaN. */
2452 int retval =
2453 my_snprintf (result, sizeof (result), "%050g %d", NaNd (), 33, 44, 55);
2454 ASSERT (strlen (result) == 50 + 3
2455 && strisnan (result, strspn (result, " "), strlen (result) - 3, 0)
2456 && strcmp (result + strlen (result) - 3, " 33") == 0);
2457 ASSERT (retval == strlen (result));
2460 { /* Precision. */
2461 int retval =
2462 my_snprintf (result, sizeof (result), "%.g %d", 1234.0, 33, 44, 55);
2463 ASSERT (strcmp (result, "1e+03 33") == 0
2464 || strcmp (result, "1e+003 33") == 0);
2465 ASSERT (retval == strlen (result));
2468 { /* Precision with no rounding. */
2469 int retval =
2470 my_snprintf (result, sizeof (result), "%.5g %d", 999.951, 33, 44, 55);
2471 ASSERT (strcmp (result, "999.95 33") == 0);
2472 ASSERT (retval == strlen (result));
2475 { /* Precision with rounding. */
2476 int retval =
2477 my_snprintf (result, sizeof (result), "%.5g %d", 999.996, 33, 44, 55);
2478 ASSERT (strcmp (result, "1000 33") == 0);
2479 ASSERT (retval == strlen (result));
2482 { /* A positive number. */
2483 int retval =
2484 my_snprintf (result, sizeof (result), "%Lg %d", 12.75L, 33, 44, 55);
2485 ASSERT (strcmp (result, "12.75 33") == 0);
2486 ASSERT (retval == strlen (result));
2489 { /* A larger positive number. */
2490 int retval =
2491 my_snprintf (result, sizeof (result), "%Lg %d", 1234567.0L, 33, 44, 55);
2492 ASSERT (strcmp (result, "1.23457e+06 33") == 0
2493 || strcmp (result, "1.23457e+006 33") == 0);
2494 ASSERT (retval == strlen (result));
2497 { /* Small and large positive numbers. */
2498 static struct { long double value; const char *string; } data[] =
2500 { 1.234321234321234e-37L, "1.23432e-37" },
2501 { 1.234321234321234e-36L, "1.23432e-36" },
2502 { 1.234321234321234e-35L, "1.23432e-35" },
2503 { 1.234321234321234e-34L, "1.23432e-34" },
2504 { 1.234321234321234e-33L, "1.23432e-33" },
2505 { 1.234321234321234e-32L, "1.23432e-32" },
2506 { 1.234321234321234e-31L, "1.23432e-31" },
2507 { 1.234321234321234e-30L, "1.23432e-30" },
2508 { 1.234321234321234e-29L, "1.23432e-29" },
2509 { 1.234321234321234e-28L, "1.23432e-28" },
2510 { 1.234321234321234e-27L, "1.23432e-27" },
2511 { 1.234321234321234e-26L, "1.23432e-26" },
2512 { 1.234321234321234e-25L, "1.23432e-25" },
2513 { 1.234321234321234e-24L, "1.23432e-24" },
2514 { 1.234321234321234e-23L, "1.23432e-23" },
2515 { 1.234321234321234e-22L, "1.23432e-22" },
2516 { 1.234321234321234e-21L, "1.23432e-21" },
2517 { 1.234321234321234e-20L, "1.23432e-20" },
2518 { 1.234321234321234e-19L, "1.23432e-19" },
2519 { 1.234321234321234e-18L, "1.23432e-18" },
2520 { 1.234321234321234e-17L, "1.23432e-17" },
2521 { 1.234321234321234e-16L, "1.23432e-16" },
2522 { 1.234321234321234e-15L, "1.23432e-15" },
2523 { 1.234321234321234e-14L, "1.23432e-14" },
2524 { 1.234321234321234e-13L, "1.23432e-13" },
2525 { 1.234321234321234e-12L, "1.23432e-12" },
2526 { 1.234321234321234e-11L, "1.23432e-11" },
2527 { 1.234321234321234e-10L, "1.23432e-10" },
2528 { 1.234321234321234e-9L, "1.23432e-09" },
2529 { 1.234321234321234e-8L, "1.23432e-08" },
2530 { 1.234321234321234e-7L, "1.23432e-07" },
2531 { 1.234321234321234e-6L, "1.23432e-06" },
2532 { 1.234321234321234e-5L, "1.23432e-05" },
2533 { 1.234321234321234e-4L, "0.000123432" },
2534 { 1.234321234321234e-3L, "0.00123432" },
2535 { 1.234321234321234e-2L, "0.0123432" },
2536 { 1.234321234321234e-1L, "0.123432" },
2537 { 1.234321234321234L, "1.23432" },
2538 { 1.234321234321234e1L, "12.3432" },
2539 { 1.234321234321234e2L, "123.432" },
2540 { 1.234321234321234e3L, "1234.32" },
2541 { 1.234321234321234e4L, "12343.2" },
2542 { 1.234321234321234e5L, "123432" },
2543 { 1.234321234321234e6L, "1.23432e+06" },
2544 { 1.234321234321234e7L, "1.23432e+07" },
2545 { 1.234321234321234e8L, "1.23432e+08" },
2546 { 1.234321234321234e9L, "1.23432e+09" },
2547 { 1.234321234321234e10L, "1.23432e+10" },
2548 { 1.234321234321234e11L, "1.23432e+11" },
2549 { 1.234321234321234e12L, "1.23432e+12" },
2550 { 1.234321234321234e13L, "1.23432e+13" },
2551 { 1.234321234321234e14L, "1.23432e+14" },
2552 { 1.234321234321234e15L, "1.23432e+15" },
2553 { 1.234321234321234e16L, "1.23432e+16" },
2554 { 1.234321234321234e17L, "1.23432e+17" },
2555 { 1.234321234321234e18L, "1.23432e+18" },
2556 { 1.234321234321234e19L, "1.23432e+19" },
2557 { 1.234321234321234e20L, "1.23432e+20" },
2558 { 1.234321234321234e21L, "1.23432e+21" },
2559 { 1.234321234321234e22L, "1.23432e+22" },
2560 { 1.234321234321234e23L, "1.23432e+23" },
2561 { 1.234321234321234e24L, "1.23432e+24" },
2562 { 1.234321234321234e25L, "1.23432e+25" },
2563 { 1.234321234321234e26L, "1.23432e+26" },
2564 { 1.234321234321234e27L, "1.23432e+27" },
2565 { 1.234321234321234e28L, "1.23432e+28" },
2566 { 1.234321234321234e29L, "1.23432e+29" },
2567 { 1.234321234321234e30L, "1.23432e+30" },
2568 { 1.234321234321234e31L, "1.23432e+31" },
2569 { 1.234321234321234e32L, "1.23432e+32" },
2570 { 1.234321234321234e33L, "1.23432e+33" },
2571 { 1.234321234321234e34L, "1.23432e+34" },
2572 { 1.234321234321234e35L, "1.23432e+35" },
2573 { 1.234321234321234e36L, "1.23432e+36" }
2575 size_t k;
2576 for (k = 0; k < SIZEOF (data); k++)
2578 int retval =
2579 my_snprintf (result, sizeof (result), "%Lg", data[k].value);
2580 const char *expected = data[k].string;
2581 ASSERT (strcmp (result, expected) == 0
2582 /* Some implementations produce exponents with 3 digits. */
2583 || (expected[strlen (expected) - 4] == 'e'
2584 && strlen (result) == strlen (expected) + 1
2585 && memcmp (result, expected, strlen (expected) - 2) == 0
2586 && result[strlen (expected) - 2] == '0'
2587 && strcmp (result + strlen (expected) - 1,
2588 expected + strlen (expected) - 2)
2589 == 0));
2590 ASSERT (retval == strlen (result));
2594 { /* A negative number. */
2595 int retval =
2596 my_snprintf (result, sizeof (result), "%Lg %d", -0.03125L, 33, 44, 55);
2597 ASSERT (strcmp (result, "-0.03125 33") == 0);
2598 ASSERT (retval == strlen (result));
2601 { /* Positive zero. */
2602 int retval =
2603 my_snprintf (result, sizeof (result), "%Lg %d", 0.0L, 33, 44, 55);
2604 ASSERT (strcmp (result, "0 33") == 0);
2605 ASSERT (retval == strlen (result));
2608 { /* Negative zero. */
2609 int retval =
2610 my_snprintf (result, sizeof (result), "%Lg %d", minus_zerol, 33, 44, 55);
2611 if (have_minus_zero ())
2612 ASSERT (strcmp (result, "-0 33") == 0);
2613 ASSERT (retval == strlen (result));
2616 { /* Positive infinity. */
2617 int retval =
2618 my_snprintf (result, sizeof (result), "%Lg %d", Infinityl (), 33, 44, 55);
2619 ASSERT (strcmp (result, "inf 33") == 0
2620 || strcmp (result, "infinity 33") == 0);
2621 ASSERT (retval == strlen (result));
2624 { /* Negative infinity. */
2625 int retval =
2626 my_snprintf (result, sizeof (result), "%Lg %d", - Infinityl (), 33, 44, 55);
2627 ASSERT (strcmp (result, "-inf 33") == 0
2628 || strcmp (result, "-infinity 33") == 0);
2629 ASSERT (retval == strlen (result));
2632 { /* NaN. */
2633 int retval =
2634 my_snprintf (result, sizeof (result), "%Lg %d", NaNl (), 33, 44, 55);
2635 ASSERT (strlen (result) >= 3 + 3
2636 && strisnan (result, 0, strlen (result) - 3, 0)
2637 && strcmp (result + strlen (result) - 3, " 33") == 0);
2638 ASSERT (retval == strlen (result));
2640 #if HAVE_SNANL
2641 { /* Signalling NaN. */
2642 int retval =
2643 my_snprintf (result, sizeof (result), "%Lg %d", SNaNl (), 33, 44, 55);
2644 ASSERT (strlen (result) >= 3 + 3
2645 && strisnan (result, 0, strlen (result) - 3, 0)
2646 && strcmp (result + strlen (result) - 3, " 33") == 0);
2647 ASSERT (retval == strlen (result));
2649 #endif
2650 #if CHECK_PRINTF_SAFE && ((defined __ia64 && LDBL_MANT_DIG == 64) || (defined __x86_64__ || defined __amd64__) || (defined __i386 || defined __i386__ || defined _I386 || defined _M_IX86 || defined _X86_)) && !HAVE_SAME_LONG_DOUBLE_AS_DOUBLE
2651 { /* Quiet NaN. */
2652 static union { unsigned int word[4]; long double value; } x =
2653 { .word = LDBL80_WORDS (0xFFFF, 0xC3333333, 0x00000000) };
2654 int retval =
2655 my_snprintf (result, sizeof (result), "%Lg %d", x.value, 33, 44, 55);
2656 ASSERT (strlen (result) >= 3 + 3
2657 && strisnan (result, 0, strlen (result) - 3, 0)
2658 && strcmp (result + strlen (result) - 3, " 33") == 0);
2659 ASSERT (retval == strlen (result));
2662 /* Signalling NaN. */
2663 static union { unsigned int word[4]; long double value; } x =
2664 { .word = LDBL80_WORDS (0xFFFF, 0x83333333, 0x00000000) };
2665 int retval =
2666 my_snprintf (result, sizeof (result), "%Lg %d", x.value, 33, 44, 55);
2667 ASSERT (strlen (result) >= 3 + 3
2668 && strisnan (result, 0, strlen (result) - 3, 0)
2669 && strcmp (result + strlen (result) - 3, " 33") == 0);
2670 ASSERT (retval == strlen (result));
2672 /* snprintf should print something for noncanonical values. */
2673 { /* Pseudo-NaN. */
2674 static union { unsigned int word[4]; long double value; } x =
2675 { .word = LDBL80_WORDS (0xFFFF, 0x40000001, 0x00000000) };
2676 int retval =
2677 my_snprintf (result, sizeof (result), "%Lg %d", x.value, 33, 44, 55);
2678 ASSERT (retval == strlen (result));
2679 ASSERT (3 < retval && strcmp (result + retval - 3, " 33") == 0);
2681 { /* Pseudo-Infinity. */
2682 static union { unsigned int word[4]; long double value; } x =
2683 { .word = LDBL80_WORDS (0xFFFF, 0x00000000, 0x00000000) };
2684 int retval =
2685 my_snprintf (result, sizeof (result), "%Lg %d", x.value, 33, 44, 55);
2686 ASSERT (retval == strlen (result));
2687 ASSERT (3 < retval && strcmp (result + retval - 3, " 33") == 0);
2689 { /* Pseudo-Zero. */
2690 static union { unsigned int word[4]; long double value; } x =
2691 { .word = LDBL80_WORDS (0x4004, 0x00000000, 0x00000000) };
2692 int retval =
2693 my_snprintf (result, sizeof (result), "%Lg %d", x.value, 33, 44, 55);
2694 ASSERT (retval == strlen (result));
2695 ASSERT (3 < retval && strcmp (result + retval - 3, " 33") == 0);
2697 { /* Unnormalized number. */
2698 static union { unsigned int word[4]; long double value; } x =
2699 { .word = LDBL80_WORDS (0x4000, 0x63333333, 0x00000000) };
2700 int retval =
2701 my_snprintf (result, sizeof (result), "%Lg %d", x.value, 33, 44, 55);
2702 ASSERT (retval == strlen (result));
2703 ASSERT (3 < retval && strcmp (result + retval - 3, " 33") == 0);
2705 { /* Pseudo-Denormal. */
2706 static union { unsigned int word[4]; long double value; } x =
2707 { .word = LDBL80_WORDS (0x0000, 0x83333333, 0x00000000) };
2708 int retval =
2709 my_snprintf (result, sizeof (result), "%Lg %d", x.value, 33, 44, 55);
2710 ASSERT (retval == strlen (result));
2711 ASSERT (3 < retval && strcmp (result + retval - 3, " 33") == 0);
2713 #endif
2715 { /* Width. */
2716 int retval =
2717 my_snprintf (result, sizeof (result), "%10Lg %d", 1.75L, 33, 44, 55);
2718 ASSERT (strcmp (result, " 1.75 33") == 0);
2719 ASSERT (retval == strlen (result));
2722 { /* Width given as argument. */
2723 int retval =
2724 my_snprintf (result, sizeof (result), "%*Lg %d", 10, 1.75L, 33, 44, 55);
2725 ASSERT (strcmp (result, " 1.75 33") == 0);
2726 ASSERT (retval == strlen (result));
2729 { /* Negative width given as argument (cf. FLAG_LEFT below). */
2730 int retval =
2731 my_snprintf (result, sizeof (result), "%*Lg %d", -10, 1.75L, 33, 44, 55);
2732 ASSERT (strcmp (result, "1.75 33") == 0);
2733 ASSERT (retval == strlen (result));
2736 { /* FLAG_LEFT. */
2737 int retval =
2738 my_snprintf (result, sizeof (result), "%-10Lg %d", 1.75L, 33, 44, 55);
2739 ASSERT (strcmp (result, "1.75 33") == 0);
2740 ASSERT (retval == strlen (result));
2743 { /* FLAG_SHOWSIGN. */
2744 int retval =
2745 my_snprintf (result, sizeof (result), "%+Lg %d", 1.75L, 33, 44, 55);
2746 ASSERT (strcmp (result, "+1.75 33") == 0);
2747 ASSERT (retval == strlen (result));
2750 { /* FLAG_SPACE. */
2751 int retval =
2752 my_snprintf (result, sizeof (result), "% Lg %d", 1.75L, 33, 44, 55);
2753 ASSERT (strcmp (result, " 1.75 33") == 0);
2754 ASSERT (retval == strlen (result));
2757 { /* FLAG_ALT. */
2758 int retval =
2759 my_snprintf (result, sizeof (result), "%#Lg %d", 1.75L, 33, 44, 55);
2760 ASSERT (strcmp (result, "1.75000 33") == 0);
2761 ASSERT (retval == strlen (result));
2764 { /* FLAG_ALT. */
2765 int retval =
2766 my_snprintf (result, sizeof (result), "%#.Lg %d", 1.75L, 33, 44, 55);
2767 ASSERT (strcmp (result, "2. 33") == 0);
2768 ASSERT (retval == strlen (result));
2771 { /* FLAG_ALT. */
2772 int retval =
2773 my_snprintf (result, sizeof (result), "%#.Lg %d", 9.75L, 33, 44, 55);
2774 ASSERT (strcmp (result, "1.e+01 33") == 0
2775 || strcmp (result, "1.e+001 33") == 0);
2776 ASSERT (retval == strlen (result));
2779 { /* FLAG_ZERO with finite number. */
2780 int retval =
2781 my_snprintf (result, sizeof (result), "%010Lg %d", 1234.0L, 33, 44, 55);
2782 ASSERT (strcmp (result, "0000001234 33") == 0);
2783 ASSERT (retval == strlen (result));
2786 { /* FLAG_ZERO with infinite number. */
2787 int retval =
2788 my_snprintf (result, sizeof (result), "%015Lg %d", - Infinityl (), 33, 44, 55);
2789 ASSERT (strcmp (result, " -inf 33") == 0
2790 || strcmp (result, " -infinity 33") == 0);
2791 ASSERT (retval == strlen (result));
2794 { /* FLAG_ZERO with NaN. */
2795 int retval =
2796 my_snprintf (result, sizeof (result), "%050Lg %d", NaNl (), 33, 44, 55);
2797 ASSERT (strlen (result) == 50 + 3
2798 && strisnan (result, strspn (result, " "), strlen (result) - 3, 0)
2799 && strcmp (result + strlen (result) - 3, " 33") == 0);
2800 ASSERT (retval == strlen (result));
2803 { /* Precision. */
2804 int retval =
2805 my_snprintf (result, sizeof (result), "%.Lg %d", 1234.0L, 33, 44, 55);
2806 ASSERT (strcmp (result, "1e+03 33") == 0
2807 || strcmp (result, "1e+003 33") == 0);
2808 ASSERT (retval == strlen (result));
2811 { /* Precision with no rounding. */
2812 int retval =
2813 my_snprintf (result, sizeof (result), "%.5Lg %d", 999.951L, 33, 44, 55);
2814 ASSERT (strcmp (result, "999.95 33") == 0);
2815 ASSERT (retval == strlen (result));
2818 { /* Precision with rounding. */
2819 int retval =
2820 my_snprintf (result, sizeof (result), "%.5Lg %d", 999.996L, 33, 44, 55);
2821 ASSERT (strcmp (result, "1000 33") == 0);
2822 ASSERT (retval == strlen (result));
2825 #if NEED_PRINTF_WITH_N_DIRECTIVE
2826 /* Test the support of the %n format directive. */
2829 int count = -1;
2830 int retval =
2831 my_snprintf (result, sizeof (result), "%d %n", 123, &count, 33, 44, 55);
2832 ASSERT (strcmp (result, "123 ") == 0);
2833 ASSERT (retval == strlen (result));
2834 ASSERT (count == 4);
2836 #endif
2838 /* Test the support of the POSIX/XSI format strings with positions. */
2841 int retval =
2842 my_snprintf (result, sizeof (result), "%2$d %1$d", 33, 55);
2843 ASSERT (strcmp (result, "55 33") == 0);
2844 ASSERT (retval == strlen (result));
2847 /* Test the support of the grouping flag. */
2850 int retval =
2851 my_snprintf (result, sizeof (result), "%'d %d", 1234567, 99);
2852 ASSERT (result[strlen (result) - 1] == '9');
2853 ASSERT (retval == strlen (result));
2856 /* Test the support of the left-adjust flag. */
2859 int retval =
2860 my_snprintf (result, sizeof (result), "a%*sc", -3, "b");
2861 ASSERT (strcmp (result, "ab c") == 0);
2862 ASSERT (retval == strlen (result));
2866 int retval =
2867 my_snprintf (result, sizeof (result), "a%-*sc", 3, "b");
2868 ASSERT (strcmp (result, "ab c") == 0);
2869 ASSERT (retval == strlen (result));
2873 int retval =
2874 my_snprintf (result, sizeof (result), "a%-*sc", -3, "b");
2875 ASSERT (strcmp (result, "ab c") == 0);
2876 ASSERT (retval == strlen (result));
2879 /* Test the support of large precision. */
2882 int retval =
2883 my_snprintf (result, sizeof (result), "%.4000d %d", 1234567, 99);
2884 size_t i;
2885 for (i = 0; i < 4000 - 7; i++)
2886 ASSERT (result[i] == '0');
2887 ASSERT (strcmp (result + 4000 - 7, "1234567 99") == 0);
2888 ASSERT (retval == strlen (result));
2892 int retval =
2893 my_snprintf (result, sizeof (result), "%.*d %d", 4000, 1234567, 99);
2894 size_t i;
2895 for (i = 0; i < 4000 - 7; i++)
2896 ASSERT (result[i] == '0');
2897 ASSERT (strcmp (result + 4000 - 7, "1234567 99") == 0);
2898 ASSERT (retval == strlen (result));
2902 int retval =
2903 my_snprintf (result, sizeof (result), "%.4000d %d", -1234567, 99);
2904 size_t i;
2905 ASSERT (result[0] == '-');
2906 for (i = 0; i < 4000 - 7; i++)
2907 ASSERT (result[1 + i] == '0');
2908 ASSERT (strcmp (result + 1 + 4000 - 7, "1234567 99") == 0);
2909 ASSERT (retval == strlen (result));
2913 int retval =
2914 my_snprintf (result, sizeof (result), "%.4000u %d", 1234567, 99);
2915 size_t i;
2916 for (i = 0; i < 4000 - 7; i++)
2917 ASSERT (result[i] == '0');
2918 ASSERT (strcmp (result + 4000 - 7, "1234567 99") == 0);
2919 ASSERT (retval == strlen (result));
2923 int retval =
2924 my_snprintf (result, sizeof (result), "%.4000o %d", 1234567, 99);
2925 size_t i;
2926 for (i = 0; i < 4000 - 7; i++)
2927 ASSERT (result[i] == '0');
2928 ASSERT (strcmp (result + 4000 - 7, "4553207 99") == 0);
2929 ASSERT (retval == strlen (result));
2933 int retval =
2934 my_snprintf (result, sizeof (result), "%.4000x %d", 1234567, 99);
2935 size_t i;
2936 for (i = 0; i < 4000 - 6; i++)
2937 ASSERT (result[i] == '0');
2938 ASSERT (strcmp (result + 4000 - 6, "12d687 99") == 0);
2939 ASSERT (retval == strlen (result));
2943 int retval =
2944 my_snprintf (result, sizeof (result), "%#.4000x %d", 1234567, 99);
2945 size_t i;
2946 ASSERT (result[0] == '0');
2947 ASSERT (result[1] == 'x');
2948 for (i = 0; i < 4000 - 6; i++)
2949 ASSERT (result[2 + i] == '0');
2950 ASSERT (strcmp (result + 2 + 4000 - 6, "12d687 99") == 0);
2951 ASSERT (retval == strlen (result));
2955 int retval =
2956 my_snprintf (result, sizeof (result), "%.4000f %d", 1.0, 99);
2957 size_t i;
2958 ASSERT (result[0] == '1');
2959 ASSERT (result[1] == '.');
2960 for (i = 0; i < 4000; i++)
2961 ASSERT (result[2 + i] == '0');
2962 ASSERT (strcmp (result + 2 + 4000, " 99") == 0);
2963 ASSERT (retval == strlen (result));
2967 int retval =
2968 my_snprintf (result, sizeof (result), "%.511f %d", 1.0, 99);
2969 size_t i;
2970 ASSERT (result[0] == '1');
2971 ASSERT (result[1] == '.');
2972 for (i = 0; i < 511; i++)
2973 ASSERT (result[2 + i] == '0');
2974 ASSERT (strcmp (result + 2 + 511, " 99") == 0);
2975 ASSERT (retval == strlen (result));
2979 char input[5000];
2980 int retval;
2981 size_t i;
2983 for (i = 0; i < sizeof (input) - 1; i++)
2984 input[i] = 'a' + ((1000000 / (i + 1)) % 26);
2985 input[i] = '\0';
2986 retval = my_snprintf (result, sizeof (result), "%.4000s %d", input, 99);
2987 ASSERT (memcmp (result, input, 4000) == 0);
2988 ASSERT (strcmp (result + 4000, " 99") == 0);
2989 ASSERT (retval == strlen (result));
2992 /* Test the support of the %s format directive. */
2994 { /* Width. */
2995 int retval =
2996 my_snprintf (result, sizeof (result), "%10s %d", "xyz", 33, 44, 55);
2997 ASSERT (strcmp (result, " xyz 33") == 0);
2998 ASSERT (retval == strlen (result));
3001 { /* Width given as argument. */
3002 int retval =
3003 my_snprintf (result, sizeof (result), "%*s %d", 10, "xyz", 33, 44, 55);
3004 ASSERT (strcmp (result, " xyz 33") == 0);
3005 ASSERT (retval == strlen (result));
3008 { /* Negative width given as argument (cf. FLAG_LEFT below). */
3009 int retval =
3010 my_snprintf (result, sizeof (result), "%*s %d", -10, "xyz", 33, 44, 55);
3011 ASSERT (strcmp (result, "xyz 33") == 0);
3012 ASSERT (retval == strlen (result));
3015 { /* FLAG_LEFT. */
3016 int retval =
3017 my_snprintf (result, sizeof (result), "%-10s %d", "xyz", 33, 44, 55);
3018 ASSERT (strcmp (result, "xyz 33") == 0);
3019 ASSERT (retval == strlen (result));
3022 static wchar_t L_xyz[4] = { 'x', 'y', 'z', 0 };
3024 { /* Width. */
3025 int retval =
3026 my_snprintf (result, sizeof (result), "%10ls %d", L_xyz, 33, 44, 55);
3027 ASSERT (strcmp (result, " xyz 33") == 0);
3028 ASSERT (retval == strlen (result));
3031 { /* Width given as argument. */
3032 int retval =
3033 my_snprintf (result, sizeof (result), "%*ls %d", 10, L_xyz, 33, 44, 55);
3034 ASSERT (strcmp (result, " xyz 33") == 0);
3035 ASSERT (retval == strlen (result));
3038 { /* Negative width given as argument (cf. FLAG_LEFT below). */
3039 int retval =
3040 my_snprintf (result, sizeof (result), "%*ls %d", -10, L_xyz, 33, 44, 55);
3041 ASSERT (strcmp (result, "xyz 33") == 0);
3042 ASSERT (retval == strlen (result));
3045 { /* FLAG_LEFT. */
3046 int retval =
3047 my_snprintf (result, sizeof (result), "%-10ls %d", L_xyz, 33, 44, 55);
3048 ASSERT (strcmp (result, "xyz 33") == 0);
3049 ASSERT (retval == strlen (result));
3052 /* To verify that these tests succeed, it is necessary to run them under
3053 a tool that checks against invalid memory accesses, such as ElectricFence
3054 or "valgrind --tool=memcheck". */
3056 size_t i;
3058 for (i = 1; i <= 8; i++)
3060 char *block;
3061 int retval;
3063 block = (char *) malloc (i);
3064 memcpy (block, "abcdefgh", i);
3065 retval = my_snprintf (result, sizeof (result), "%.*s", (int) i, block);
3066 ASSERT (memcmp (result, block, i) == 0);
3067 ASSERT (result[i] == '\0');
3068 ASSERT (retval == strlen (result));
3069 free (block);
3073 size_t i;
3075 for (i = 1; i <= 8; i++)
3077 wchar_t *block;
3078 size_t j;
3079 int retval;
3081 block = (wchar_t *) malloc (i * sizeof (wchar_t));
3082 for (j = 0; j < i; j++)
3083 block[j] = "abcdefgh"[j];
3084 retval = my_snprintf (result, sizeof (result), "%.*ls", (int) i, block);
3085 ASSERT (memcmp (result, "abcdefgh", i) == 0);
3086 ASSERT (result[i] == '\0');
3087 ASSERT (retval == strlen (result));
3088 free (block);
3092 /* Test the support of the %c format directive. */
3094 { /* Width. */
3095 int retval =
3096 my_snprintf (result, sizeof (result),
3097 "%10c %d", (unsigned char) 'x', 33, 44, 55);
3098 ASSERT (strcmp (result, " x 33") == 0);
3099 ASSERT (retval == strlen (result));
3102 { /* Width given as argument. */
3103 int retval =
3104 my_snprintf (result, sizeof (result),
3105 "%*c %d", 10, (unsigned char) 'x', 33, 44, 55);
3106 ASSERT (strcmp (result, " x 33") == 0);
3107 ASSERT (retval == strlen (result));
3110 { /* Negative width given as argument (cf. FLAG_LEFT below). */
3111 int retval =
3112 my_snprintf (result, sizeof (result),
3113 "%*c %d", -10, (unsigned char) 'x', 33, 44, 55);
3114 ASSERT (strcmp (result, "x 33") == 0);
3115 ASSERT (retval == strlen (result));
3118 { /* FLAG_LEFT. */
3119 int retval =
3120 my_snprintf (result, sizeof (result),
3121 "%-10c %d", (unsigned char) 'x', 33, 44, 55);
3122 ASSERT (strcmp (result, "x 33") == 0);
3123 ASSERT (retval == strlen (result));
3126 { /* Precision is ignored. */
3127 int retval =
3128 my_snprintf (result, sizeof (result),
3129 "%.0c %d", (unsigned char) 'x', 33, 44, 55);
3130 ASSERT (strcmp (result, "x 33") == 0);
3131 ASSERT (retval == strlen (result));
3134 { /* NUL character. */
3135 int retval =
3136 my_snprintf (result, sizeof (result),
3137 "a%cz %d", '\0', 33, 44, 55);
3138 ASSERT (memcmp (result, "a\0z 33\0", 6 + 1) == 0);
3139 ASSERT (retval == 6);
3142 static wint_t L_x = (wchar_t) 'x';
3144 { /* Width. */
3145 int retval =
3146 my_snprintf (result, sizeof (result), "%10lc %d", L_x, 33, 44, 55);
3147 ASSERT (strcmp (result, " x 33") == 0);
3148 ASSERT (retval == strlen (result));
3151 { /* Width given as argument. */
3152 int retval =
3153 my_snprintf (result, sizeof (result), "%*lc %d", 10, L_x, 33, 44, 55);
3154 ASSERT (strcmp (result, " x 33") == 0);
3155 ASSERT (retval == strlen (result));
3158 { /* Negative width given as argument (cf. FLAG_LEFT below). */
3159 int retval =
3160 my_snprintf (result, sizeof (result), "%*lc %d", -10, L_x, 33, 44, 55);
3161 ASSERT (strcmp (result, "x 33") == 0);
3162 ASSERT (retval == strlen (result));
3165 { /* FLAG_LEFT. */
3166 int retval =
3167 my_snprintf (result, sizeof (result), "%-10lc %d", L_x, 33, 44, 55);
3168 ASSERT (strcmp (result, "x 33") == 0);
3169 ASSERT (retval == strlen (result));
3172 { /* Precision is ignored. */
3173 int retval =
3174 my_snprintf (result, sizeof (result),
3175 "%.0lc %d", L_x, 33, 44, 55);
3176 ASSERT (strcmp (result, "x 33") == 0);
3177 ASSERT (retval == strlen (result));
3180 { /* NUL character. */
3181 int retval =
3182 my_snprintf (result, sizeof (result),
3183 "a%lcz %d", (wint_t) L'\0', 33, 44, 55);
3184 /* ISO C had this wrong for decades. ISO C 23 now corrects it, through
3185 this wording:
3186 "If an l length modifier is present, the wint_t argument is converted
3187 as if by a call to the wcrtomb function with a pointer to storage of
3188 at least MB_CUR_MAX bytes, the wint_t argument converted to wchar_t,
3189 and an initial shift state." */
3190 ASSERT (memcmp (result, "a\0z 33\0", 6 + 1) == 0);
3191 ASSERT (retval == 6);
3194 static wint_t L_invalid = (wchar_t) 0x76543210;
3196 { /* Invalid wide character.
3197 The conversion may succeed or may fail, but it should not abort. */
3198 int retval =
3199 my_snprintf (result, sizeof (result),
3200 "%lc %d", L_invalid, 33, 44, 55);
3201 (void) retval;
3204 { /* Invalid wide character and width.
3205 The conversion may succeed or may fail, but it should not abort. */
3206 int retval =
3207 my_snprintf (result, sizeof (result),
3208 "%10lc %d", L_invalid, 33, 44, 55);
3209 (void) retval;
3212 /* Test the support of the 'x' conversion specifier for hexadecimal output of
3213 integers. */
3215 { /* Zero. */
3216 int retval =
3217 my_snprintf (result, sizeof (result), "%x %d", 0, 33, 44, 55);
3218 ASSERT (strcmp (result, "0 33") == 0);
3219 ASSERT (retval == strlen (result));
3222 { /* A positive number. */
3223 int retval =
3224 my_snprintf (result, sizeof (result), "%x %d", 12348, 33, 44, 55);
3225 ASSERT (strcmp (result, "303c 33") == 0);
3226 ASSERT (retval == strlen (result));
3229 { /* A large positive number. */
3230 int retval =
3231 my_snprintf (result, sizeof (result), "%x %d", 0xFFFFFFFEU, 33, 44, 55);
3232 ASSERT (strcmp (result, "fffffffe 33") == 0);
3233 ASSERT (retval == strlen (result));
3236 { /* Width. */
3237 int retval =
3238 my_snprintf (result, sizeof (result), "%10x %d", 12348, 33, 44, 55);
3239 ASSERT (strcmp (result, " 303c 33") == 0);
3240 ASSERT (retval == strlen (result));
3243 { /* Width given as argument. */
3244 int retval =
3245 my_snprintf (result, sizeof (result), "%*x %d", 10, 12348, 33, 44, 55);
3246 ASSERT (strcmp (result, " 303c 33") == 0);
3247 ASSERT (retval == strlen (result));
3250 { /* Negative width given as argument (cf. FLAG_LEFT below). */
3251 int retval =
3252 my_snprintf (result, sizeof (result), "%*x %d", -10, 12348, 33, 44, 55);
3253 ASSERT (strcmp (result, "303c 33") == 0);
3254 ASSERT (retval == strlen (result));
3257 { /* Precision. */
3258 int retval =
3259 my_snprintf (result, sizeof (result), "%.10x %d", 12348, 33, 44, 55);
3260 ASSERT (strcmp (result, "000000303c 33") == 0);
3261 ASSERT (retval == strlen (result));
3264 { /* Zero precision and a positive number. */
3265 int retval =
3266 my_snprintf (result, sizeof (result), "%.0x %d", 12348, 33, 44, 55);
3267 ASSERT (strcmp (result, "303c 33") == 0);
3268 ASSERT (retval == strlen (result));
3271 { /* Zero precision and a zero number. */
3272 int retval =
3273 my_snprintf (result, sizeof (result), "%.0x %d", 0, 33, 44, 55);
3274 /* ISO C and POSIX specify that "The result of converting a zero value
3275 with a precision of zero is no characters." */
3276 ASSERT (strcmp (result, " 33") == 0);
3277 ASSERT (retval == strlen (result));
3280 { /* Width and precision. */
3281 int retval =
3282 my_snprintf (result, sizeof (result), "%15.10x %d", 12348, 33, 44, 55);
3283 ASSERT (strcmp (result, " 000000303c 33") == 0);
3284 ASSERT (retval == strlen (result));
3287 { /* Padding and precision. */
3288 int retval =
3289 my_snprintf (result, sizeof (result), "%015.10x %d", 12348, 33, 44, 55);
3290 /* ISO C 99 § 7.19.6.1.(6) says: "For d, i, o, u, x, and X conversions, if a
3291 precision is specified, the 0 flag is ignored." */
3292 ASSERT (strcmp (result, " 000000303c 33") == 0);
3293 ASSERT (retval == strlen (result));
3296 { /* FLAG_LEFT. */
3297 int retval =
3298 my_snprintf (result, sizeof (result), "%-10x %d", 12348, 33, 44, 55);
3299 ASSERT (strcmp (result, "303c 33") == 0);
3300 ASSERT (retval == strlen (result));
3303 { /* FLAG_ALT with zero. */
3304 int retval =
3305 my_snprintf (result, sizeof (result), "%#x %d", 0, 33, 44, 55);
3306 ASSERT (strcmp (result, "0 33") == 0);
3307 ASSERT (retval == strlen (result));
3310 { /* FLAG_ALT with a positive number. */
3311 int retval =
3312 my_snprintf (result, sizeof (result), "%#x %d", 12348, 33, 44, 55);
3313 ASSERT (strcmp (result, "0x303c 33") == 0);
3314 ASSERT (retval == strlen (result));
3317 { /* FLAG_ALT with a positive number and width. */
3318 int retval =
3319 my_snprintf (result, sizeof (result), "%#10x %d", 12348, 33, 44, 55);
3320 ASSERT (strcmp (result, " 0x303c 33") == 0);
3321 ASSERT (retval == strlen (result));
3324 { /* FLAG_ALT with a positive number and padding. */
3325 int retval =
3326 my_snprintf (result, sizeof (result), "%0#10x %d", 12348, 33, 44, 55);
3327 ASSERT (strcmp (result, "0x0000303c 33") == 0);
3328 ASSERT (retval == strlen (result));
3331 { /* FLAG_ALT with a positive number and precision. */
3332 int retval =
3333 my_snprintf (result, sizeof (result), "%0#.10x %d", 12348, 33, 44, 55);
3334 ASSERT (strcmp (result, "0x000000303c 33") == 0);
3335 ASSERT (retval == strlen (result));
3338 { /* FLAG_ALT with a positive number and width and precision. */
3339 int retval =
3340 my_snprintf (result, sizeof (result), "%#15.10x %d", 12348, 33, 44, 55);
3341 ASSERT (strcmp (result, " 0x000000303c 33") == 0);
3342 ASSERT (retval == strlen (result));
3345 { /* FLAG_ALT with a positive number and padding and precision. */
3346 int retval =
3347 my_snprintf (result, sizeof (result), "%0#15.10x %d", 12348, 33, 44, 55);
3348 /* ISO C 99 § 7.19.6.1.(6) says: "For d, i, o, u, x, and X conversions, if a
3349 precision is specified, the 0 flag is ignored." */
3350 ASSERT (strcmp (result, " 0x000000303c 33") == 0);
3351 ASSERT (retval == strlen (result));
3354 { /* FLAG_ALT with a zero precision and a zero number. */
3355 int retval =
3356 my_snprintf (result, sizeof (result), "%#.0x %d", 0, 33, 44, 55);
3357 /* ISO C and POSIX specify that "The result of converting a zero value
3358 with a precision of zero is no characters.", and the prefix is added
3359 only for non-zero values. */
3360 ASSERT (strcmp (result, " 33") == 0);
3361 ASSERT (retval == strlen (result));
3364 { /* Uppercase 'X'. */
3365 int retval =
3366 my_snprintf (result, sizeof (result), "%X %d", 12348, 33, 44, 55);
3367 ASSERT (strcmp (result, "303C 33") == 0);
3368 ASSERT (retval == strlen (result));
3371 { /* Uppercase 'X' with FLAG_ALT. */
3372 int retval =
3373 my_snprintf (result, sizeof (result), "%#X %d", 12348, 33, 44, 55);
3374 ASSERT (strcmp (result, "0X303C 33") == 0);
3375 ASSERT (retval == strlen (result));
3378 { /* Uppercase 'X' with FLAG_ALT and zero precision and a zero number. */
3379 int retval =
3380 my_snprintf (result, sizeof (result), "%#.0X %d", 0, 33, 44, 55);
3381 /* ISO C and POSIX specify that "The result of converting a zero value
3382 with a precision of zero is no characters.", and the prefix is added
3383 only for non-zero values. */
3384 ASSERT (strcmp (result, " 33") == 0);
3385 ASSERT (retval == strlen (result));
3388 /* Test the support of the 'b' conversion specifier for binary output of
3389 integers. */
3391 { /* Zero. */
3392 int retval =
3393 my_snprintf (result, sizeof (result), "%b %d", 0, 33, 44, 55);
3394 ASSERT (strcmp (result, "0 33") == 0);
3395 ASSERT (retval == strlen (result));
3398 { /* A positive number. */
3399 int retval =
3400 my_snprintf (result, sizeof (result), "%b %d", 12345, 33, 44, 55);
3401 ASSERT (strcmp (result, "11000000111001 33") == 0);
3402 ASSERT (retval == strlen (result));
3405 { /* A large positive number. */
3406 int retval =
3407 my_snprintf (result, sizeof (result), "%b %d", 0xFFFFFFFEU, 33, 44, 55);
3408 ASSERT (strcmp (result, "11111111111111111111111111111110 33") == 0);
3409 ASSERT (retval == strlen (result));
3412 { /* Width. */
3413 int retval =
3414 my_snprintf (result, sizeof (result), "%20b %d", 12345, 33, 44, 55);
3415 ASSERT (strcmp (result, " 11000000111001 33") == 0);
3416 ASSERT (retval == strlen (result));
3419 { /* Width given as argument. */
3420 int retval =
3421 my_snprintf (result, sizeof (result), "%*b %d", 20, 12345, 33, 44, 55);
3422 ASSERT (strcmp (result, " 11000000111001 33") == 0);
3423 ASSERT (retval == strlen (result));
3426 { /* Negative width given as argument (cf. FLAG_LEFT below). */
3427 int retval =
3428 my_snprintf (result, sizeof (result), "%*b %d", -20, 12345, 33, 44, 55);
3429 ASSERT (strcmp (result, "11000000111001 33") == 0);
3430 ASSERT (retval == strlen (result));
3433 { /* Precision. */
3434 int retval =
3435 my_snprintf (result, sizeof (result), "%.20b %d", 12345, 33, 44, 55);
3436 ASSERT (strcmp (result, "00000011000000111001 33") == 0);
3437 ASSERT (retval == strlen (result));
3440 { /* Zero precision and a positive number. */
3441 int retval =
3442 my_snprintf (result, sizeof (result), "%.0b %d", 12345, 33, 44, 55);
3443 ASSERT (strcmp (result, "11000000111001 33") == 0);
3444 ASSERT (retval == strlen (result));
3447 { /* Zero precision and a zero number. */
3448 int retval =
3449 my_snprintf (result, sizeof (result), "%.0b %d", 0, 33, 44, 55);
3450 /* ISO C and POSIX specify that "The result of converting a zero value
3451 with a precision of zero is no characters." */
3452 ASSERT (strcmp (result, " 33") == 0);
3453 ASSERT (retval == strlen (result));
3456 { /* Width and precision. */
3457 int retval =
3458 my_snprintf (result, sizeof (result), "%25.20b %d", 12345, 33, 44, 55);
3459 ASSERT (strcmp (result, " 00000011000000111001 33") == 0);
3460 ASSERT (retval == strlen (result));
3463 { /* Padding and precision. */
3464 int retval =
3465 my_snprintf (result, sizeof (result), "%025.20b %d", 12345, 33, 44, 55);
3466 /* Neither ISO C nor POSIX specify that the '0' flag is ignored when
3467 a width and a precision are both present. But implementations do so. */
3468 ASSERT (strcmp (result, " 00000011000000111001 33") == 0);
3469 ASSERT (retval == strlen (result));
3472 { /* FLAG_LEFT. */
3473 int retval =
3474 my_snprintf (result, sizeof (result), "%-20b %d", 12345, 33, 44, 55);
3475 ASSERT (strcmp (result, "11000000111001 33") == 0);
3476 ASSERT (retval == strlen (result));
3479 { /* FLAG_ALT with zero. */
3480 int retval =
3481 my_snprintf (result, sizeof (result), "%#b %d", 0, 33, 44, 55);
3482 ASSERT (strcmp (result, "0 33") == 0);
3483 ASSERT (retval == strlen (result));
3486 { /* FLAG_ALT with a positive number. */
3487 int retval =
3488 my_snprintf (result, sizeof (result), "%#b %d", 12345, 33, 44, 55);
3489 ASSERT (strcmp (result, "0b11000000111001 33") == 0);
3490 ASSERT (retval == strlen (result));
3493 { /* FLAG_ALT with a positive number and width. */
3494 int retval =
3495 my_snprintf (result, sizeof (result), "%#20b %d", 12345, 33, 44, 55);
3496 ASSERT (strcmp (result, " 0b11000000111001 33") == 0);
3497 ASSERT (retval == strlen (result));
3500 { /* FLAG_ALT with a positive number and padding. */
3501 int retval =
3502 my_snprintf (result, sizeof (result), "%0#20b %d", 12345, 33, 44, 55);
3503 ASSERT (strcmp (result, "0b000011000000111001 33") == 0);
3504 ASSERT (retval == strlen (result));
3507 { /* FLAG_ALT with a positive number and precision. */
3508 int retval =
3509 my_snprintf (result, sizeof (result), "%0#.20b %d", 12345, 33, 44, 55);
3510 ASSERT (strcmp (result, "0b00000011000000111001 33") == 0);
3511 ASSERT (retval == strlen (result));
3514 { /* FLAG_ALT with a positive number and width and precision. */
3515 int retval =
3516 my_snprintf (result, sizeof (result), "%#25.20b %d", 12345, 33, 44, 55);
3517 ASSERT (strcmp (result, " 0b00000011000000111001 33") == 0);
3518 ASSERT (retval == strlen (result));
3521 { /* FLAG_ALT with a positive number and padding and precision. */
3522 int retval =
3523 my_snprintf (result, sizeof (result), "%0#25.20b %d", 12345, 33, 44, 55);
3524 /* Neither ISO C nor POSIX specify that the '0' flag is ignored when
3525 a width and a precision are both present. But implementations do so. */
3526 ASSERT (strcmp (result, " 0b00000011000000111001 33") == 0);
3527 ASSERT (retval == strlen (result));
3530 { /* FLAG_ALT with a zero precision and a zero number. */
3531 int retval =
3532 my_snprintf (result, sizeof (result), "%#.0b %d", 0, 33, 44, 55);
3533 /* ISO C and POSIX specify that "The result of converting a zero value
3534 with a precision of zero is no characters.", and the prefix is added
3535 only for non-zero values. */
3536 ASSERT (strcmp (result, " 33") == 0);
3537 ASSERT (retval == strlen (result));
3540 /* Test the support of argument type/size specifiers for signed integer
3541 conversions. */
3544 int retval =
3545 my_snprintf (result, sizeof (result),
3546 "%hhd %d", (signed char) -42, 33, 44, 55);
3547 ASSERT (strcmp (result, "-42 33") == 0);
3548 ASSERT (retval == strlen (result));
3552 int retval =
3553 my_snprintf (result, sizeof (result),
3554 "%hd %d", (short) -12345, 33, 44, 55);
3555 ASSERT (strcmp (result, "-12345 33") == 0);
3556 ASSERT (retval == strlen (result));
3560 int retval =
3561 my_snprintf (result, sizeof (result),
3562 "%d %d", -12345, 33, 44, 55);
3563 ASSERT (strcmp (result, "-12345 33") == 0);
3564 ASSERT (retval == strlen (result));
3568 int retval =
3569 my_snprintf (result, sizeof (result),
3570 "%ld %d", (long int) -12345, 33, 44, 55);
3571 ASSERT (strcmp (result, "-12345 33") == 0);
3572 ASSERT (retval == strlen (result));
3576 int retval =
3577 my_snprintf (result, sizeof (result),
3578 "%lld %d", (long long int) -12345, 33, 44, 55);
3579 ASSERT (strcmp (result, "-12345 33") == 0);
3580 ASSERT (retval == strlen (result));
3584 int retval =
3585 my_snprintf (result, sizeof (result),
3586 "%w8d %d", (int8_t) -42, 33, 44, 55);
3587 ASSERT (strcmp (result, "-42 33") == 0);
3588 ASSERT (retval == strlen (result));
3592 int retval =
3593 my_snprintf (result, sizeof (result),
3594 "%w16d %d", (int16_t) -12345, 33, 44, 55);
3595 ASSERT (strcmp (result, "-12345 33") == 0);
3596 ASSERT (retval == strlen (result));
3600 int retval =
3601 my_snprintf (result, sizeof (result),
3602 "%w32d %d", (int32_t) -12345, 33, 44, 55);
3603 ASSERT (strcmp (result, "-12345 33") == 0);
3604 ASSERT (retval == strlen (result));
3608 int retval =
3609 my_snprintf (result, sizeof (result),
3610 "%w64d %d", (int64_t) -12345, 33, 44, 55);
3611 ASSERT (strcmp (result, "-12345 33") == 0);
3612 ASSERT (retval == strlen (result));
3616 int retval =
3617 my_snprintf (result, sizeof (result),
3618 "%wf8d %d", (int_fast8_t) -42, 33, 44, 55);
3619 ASSERT (strcmp (result, "-42 33") == 0);
3620 ASSERT (retval == strlen (result));
3624 int retval =
3625 my_snprintf (result, sizeof (result),
3626 "%wf16d %d", (int_fast16_t) -12345, 33, 44, 55);
3627 ASSERT (strcmp (result, "-12345 33") == 0);
3628 ASSERT (retval == strlen (result));
3632 int retval =
3633 my_snprintf (result, sizeof (result),
3634 "%wf32d %d", (int_fast32_t) -12345, 33, 44, 55);
3635 ASSERT (strcmp (result, "-12345 33") == 0);
3636 ASSERT (retval == strlen (result));
3640 int retval =
3641 my_snprintf (result, sizeof (result),
3642 "%wf64d %d", (int_fast64_t) -12345, 33, 44, 55);
3643 ASSERT (strcmp (result, "-12345 33") == 0);
3644 ASSERT (retval == strlen (result));
3647 /* Test the support of argument type/size specifiers for unsigned integer
3648 conversions: %u */
3651 int retval =
3652 my_snprintf (result, sizeof (result),
3653 "%hhu %d", (unsigned char) 42, 33, 44, 55);
3654 ASSERT (strcmp (result, "42 33") == 0);
3655 ASSERT (retval == strlen (result));
3659 int retval =
3660 my_snprintf (result, sizeof (result),
3661 "%hu %d", (unsigned short) 12345, 33, 44, 55);
3662 ASSERT (strcmp (result, "12345 33") == 0);
3663 ASSERT (retval == strlen (result));
3667 int retval =
3668 my_snprintf (result, sizeof (result),
3669 "%u %d", (unsigned int) 12345, 33, 44, 55);
3670 ASSERT (strcmp (result, "12345 33") == 0);
3671 ASSERT (retval == strlen (result));
3675 int retval =
3676 my_snprintf (result, sizeof (result),
3677 "%lu %d", (unsigned long int) 12345, 33, 44, 55);
3678 ASSERT (strcmp (result, "12345 33") == 0);
3679 ASSERT (retval == strlen (result));
3683 int retval =
3684 my_snprintf (result, sizeof (result),
3685 "%llu %d", (unsigned long long int) 12345, 33, 44, 55);
3686 ASSERT (strcmp (result, "12345 33") == 0);
3687 ASSERT (retval == strlen (result));
3691 int retval =
3692 my_snprintf (result, sizeof (result),
3693 "%w8u %d", (uint8_t) 42, 33, 44, 55);
3694 ASSERT (strcmp (result, "42 33") == 0);
3695 ASSERT (retval == strlen (result));
3699 int retval =
3700 my_snprintf (result, sizeof (result),
3701 "%w16u %d", (uint16_t) 12345, 33, 44, 55);
3702 ASSERT (strcmp (result, "12345 33") == 0);
3703 ASSERT (retval == strlen (result));
3707 int retval =
3708 my_snprintf (result, sizeof (result),
3709 "%w32u %d", (uint32_t) 12345, 33, 44, 55);
3710 ASSERT (strcmp (result, "12345 33") == 0);
3711 ASSERT (retval == strlen (result));
3715 int retval =
3716 my_snprintf (result, sizeof (result),
3717 "%w64u %d", (uint64_t) 12345, 33, 44, 55);
3718 ASSERT (strcmp (result, "12345 33") == 0);
3719 ASSERT (retval == strlen (result));
3723 int retval =
3724 my_snprintf (result, sizeof (result),
3725 "%wf8u %d", (uint_fast8_t) 42, 33, 44, 55);
3726 ASSERT (strcmp (result, "42 33") == 0);
3727 ASSERT (retval == strlen (result));
3731 int retval =
3732 my_snprintf (result, sizeof (result),
3733 "%wf16u %d", (uint_fast16_t) 12345, 33, 44, 55);
3734 ASSERT (strcmp (result, "12345 33") == 0);
3735 ASSERT (retval == strlen (result));
3739 int retval =
3740 my_snprintf (result, sizeof (result),
3741 "%wf32u %d", (uint_fast32_t) 12345, 33, 44, 55);
3742 ASSERT (strcmp (result, "12345 33") == 0);
3743 ASSERT (retval == strlen (result));
3747 int retval =
3748 my_snprintf (result, sizeof (result),
3749 "%wf64u %d", (uint_fast64_t) 12345, 33, 44, 55);
3750 ASSERT (strcmp (result, "12345 33") == 0);
3751 ASSERT (retval == strlen (result));
3754 /* Test the support of argument type/size specifiers for unsigned integer
3755 conversions: %b */
3758 int retval =
3759 my_snprintf (result, sizeof (result),
3760 "%hhb %d", (unsigned char) 42, 33, 44, 55);
3761 ASSERT (strcmp (result, "101010 33") == 0);
3762 ASSERT (retval == strlen (result));
3766 int retval =
3767 my_snprintf (result, sizeof (result),
3768 "%hb %d", (unsigned short) 12345, 33, 44, 55);
3769 ASSERT (strcmp (result, "11000000111001 33") == 0);
3770 ASSERT (retval == strlen (result));
3774 int retval =
3775 my_snprintf (result, sizeof (result),
3776 "%b %d", (unsigned int) 12345, 33, 44, 55);
3777 ASSERT (strcmp (result, "11000000111001 33") == 0);
3778 ASSERT (retval == strlen (result));
3782 int retval =
3783 my_snprintf (result, sizeof (result),
3784 "%lb %d", (unsigned long int) 12345, 33, 44, 55);
3785 ASSERT (strcmp (result, "11000000111001 33") == 0);
3786 ASSERT (retval == strlen (result));
3790 int retval =
3791 my_snprintf (result, sizeof (result),
3792 "%llb %d", (unsigned long long int) 12345, 33, 44, 55);
3793 ASSERT (strcmp (result, "11000000111001 33") == 0);
3794 ASSERT (retval == strlen (result));
3798 int retval =
3799 my_snprintf (result, sizeof (result),
3800 "%w8b %d", (uint8_t) 42, 33, 44, 55);
3801 ASSERT (strcmp (result, "101010 33") == 0);
3802 ASSERT (retval == strlen (result));
3806 int retval =
3807 my_snprintf (result, sizeof (result),
3808 "%w16b %d", (uint16_t) 12345, 33, 44, 55);
3809 ASSERT (strcmp (result, "11000000111001 33") == 0);
3810 ASSERT (retval == strlen (result));
3814 int retval =
3815 my_snprintf (result, sizeof (result),
3816 "%w32b %d", (uint32_t) 12345, 33, 44, 55);
3817 ASSERT (strcmp (result, "11000000111001 33") == 0);
3818 ASSERT (retval == strlen (result));
3822 int retval =
3823 my_snprintf (result, sizeof (result),
3824 "%w64b %d", (uint64_t) 12345, 33, 44, 55);
3825 ASSERT (strcmp (result, "11000000111001 33") == 0);
3826 ASSERT (retval == strlen (result));
3830 int retval =
3831 my_snprintf (result, sizeof (result),
3832 "%wf8b %d", (uint_fast8_t) 42, 33, 44, 55);
3833 ASSERT (strcmp (result, "101010 33") == 0);
3834 ASSERT (retval == strlen (result));
3838 int retval =
3839 my_snprintf (result, sizeof (result),
3840 "%wf16b %d", (uint_fast16_t) 12345, 33, 44, 55);
3841 ASSERT (strcmp (result, "11000000111001 33") == 0);
3842 ASSERT (retval == strlen (result));
3846 int retval =
3847 my_snprintf (result, sizeof (result),
3848 "%wf32b %d", (uint_fast32_t) 12345, 33, 44, 55);
3849 ASSERT (strcmp (result, "11000000111001 33") == 0);
3850 ASSERT (retval == strlen (result));
3854 int retval =
3855 my_snprintf (result, sizeof (result),
3856 "%wf64b %d", (uint_fast64_t) 12345, 33, 44, 55);
3857 ASSERT (strcmp (result, "11000000111001 33") == 0);
3858 ASSERT (retval == strlen (result));
3861 /* Test the support of argument type/size specifiers for unsigned integer
3862 conversions: %o */
3865 int retval =
3866 my_snprintf (result, sizeof (result),
3867 "%hho %d", (unsigned char) 42, 33, 44, 55);
3868 ASSERT (strcmp (result, "52 33") == 0);
3869 ASSERT (retval == strlen (result));
3873 int retval =
3874 my_snprintf (result, sizeof (result),
3875 "%ho %d", (unsigned short) 12345, 33, 44, 55);
3876 ASSERT (strcmp (result, "30071 33") == 0);
3877 ASSERT (retval == strlen (result));
3881 int retval =
3882 my_snprintf (result, sizeof (result),
3883 "%o %d", (unsigned int) 12345, 33, 44, 55);
3884 ASSERT (strcmp (result, "30071 33") == 0);
3885 ASSERT (retval == strlen (result));
3889 int retval =
3890 my_snprintf (result, sizeof (result),
3891 "%lo %d", (unsigned long int) 12345, 33, 44, 55);
3892 ASSERT (strcmp (result, "30071 33") == 0);
3893 ASSERT (retval == strlen (result));
3897 int retval =
3898 my_snprintf (result, sizeof (result),
3899 "%llo %d", (unsigned long long int) 12345, 33, 44, 55);
3900 ASSERT (strcmp (result, "30071 33") == 0);
3901 ASSERT (retval == strlen (result));
3905 int retval =
3906 my_snprintf (result, sizeof (result),
3907 "%w8o %d", (uint8_t) 42, 33, 44, 55);
3908 ASSERT (strcmp (result, "52 33") == 0);
3909 ASSERT (retval == strlen (result));
3913 int retval =
3914 my_snprintf (result, sizeof (result),
3915 "%w16o %d", (uint16_t) 12345, 33, 44, 55);
3916 ASSERT (strcmp (result, "30071 33") == 0);
3917 ASSERT (retval == strlen (result));
3921 int retval =
3922 my_snprintf (result, sizeof (result),
3923 "%w32o %d", (uint32_t) 12345, 33, 44, 55);
3924 ASSERT (strcmp (result, "30071 33") == 0);
3925 ASSERT (retval == strlen (result));
3929 int retval =
3930 my_snprintf (result, sizeof (result),
3931 "%w64o %d", (uint64_t) 12345, 33, 44, 55);
3932 ASSERT (strcmp (result, "30071 33") == 0);
3933 ASSERT (retval == strlen (result));
3937 int retval =
3938 my_snprintf (result, sizeof (result),
3939 "%wf8o %d", (uint_fast8_t) 42, 33, 44, 55);
3940 ASSERT (strcmp (result, "52 33") == 0);
3941 ASSERT (retval == strlen (result));
3945 int retval =
3946 my_snprintf (result, sizeof (result),
3947 "%wf16o %d", (uint_fast16_t) 12345, 33, 44, 55);
3948 ASSERT (strcmp (result, "30071 33") == 0);
3949 ASSERT (retval == strlen (result));
3953 int retval =
3954 my_snprintf (result, sizeof (result),
3955 "%wf32o %d", (uint_fast32_t) 12345, 33, 44, 55);
3956 ASSERT (strcmp (result, "30071 33") == 0);
3957 ASSERT (retval == strlen (result));
3961 int retval =
3962 my_snprintf (result, sizeof (result),
3963 "%wf64o %d", (uint_fast64_t) 12345, 33, 44, 55);
3964 ASSERT (strcmp (result, "30071 33") == 0);
3965 ASSERT (retval == strlen (result));
3968 /* Test the support of argument type/size specifiers for unsigned integer
3969 conversions: %x */
3972 int retval =
3973 my_snprintf (result, sizeof (result),
3974 "%hhX %d", (unsigned char) 42, 33, 44, 55);
3975 ASSERT (strcmp (result, "2A 33") == 0);
3976 ASSERT (retval == strlen (result));
3980 int retval =
3981 my_snprintf (result, sizeof (result),
3982 "%hX %d", (unsigned short) 12345, 33, 44, 55);
3983 ASSERT (strcmp (result, "3039 33") == 0);
3984 ASSERT (retval == strlen (result));
3988 int retval =
3989 my_snprintf (result, sizeof (result),
3990 "%X %d", (unsigned int) 12345, 33, 44, 55);
3991 ASSERT (strcmp (result, "3039 33") == 0);
3992 ASSERT (retval == strlen (result));
3996 int retval =
3997 my_snprintf (result, sizeof (result),
3998 "%lX %d", (unsigned long int) 12345, 33, 44, 55);
3999 ASSERT (strcmp (result, "3039 33") == 0);
4000 ASSERT (retval == strlen (result));
4004 int retval =
4005 my_snprintf (result, sizeof (result),
4006 "%llX %d", (unsigned long long int) 12345, 33, 44, 55);
4007 ASSERT (strcmp (result, "3039 33") == 0);
4008 ASSERT (retval == strlen (result));
4012 int retval =
4013 my_snprintf (result, sizeof (result),
4014 "%w8X %d", (uint8_t) 42, 33, 44, 55);
4015 ASSERT (strcmp (result, "2A 33") == 0);
4016 ASSERT (retval == strlen (result));
4020 int retval =
4021 my_snprintf (result, sizeof (result),
4022 "%w16X %d", (uint16_t) 12345, 33, 44, 55);
4023 ASSERT (strcmp (result, "3039 33") == 0);
4024 ASSERT (retval == strlen (result));
4028 int retval =
4029 my_snprintf (result, sizeof (result),
4030 "%w32X %d", (uint32_t) 12345, 33, 44, 55);
4031 ASSERT (strcmp (result, "3039 33") == 0);
4032 ASSERT (retval == strlen (result));
4036 int retval =
4037 my_snprintf (result, sizeof (result),
4038 "%w64X %d", (uint64_t) 12345, 33, 44, 55);
4039 ASSERT (strcmp (result, "3039 33") == 0);
4040 ASSERT (retval == strlen (result));
4044 int retval =
4045 my_snprintf (result, sizeof (result),
4046 "%wf8X %d", (uint_fast8_t) 42, 33, 44, 55);
4047 ASSERT (strcmp (result, "2A 33") == 0);
4048 ASSERT (retval == strlen (result));
4052 int retval =
4053 my_snprintf (result, sizeof (result),
4054 "%wf16X %d", (uint_fast16_t) 12345, 33, 44, 55);
4055 ASSERT (strcmp (result, "3039 33") == 0);
4056 ASSERT (retval == strlen (result));
4060 int retval =
4061 my_snprintf (result, sizeof (result),
4062 "%wf32X %d", (uint_fast32_t) 12345, 33, 44, 55);
4063 ASSERT (strcmp (result, "3039 33") == 0);
4064 ASSERT (retval == strlen (result));
4068 int retval =
4069 my_snprintf (result, sizeof (result),
4070 "%wf64X %d", (uint_fast64_t) 12345, 33, 44, 55);
4071 ASSERT (strcmp (result, "3039 33") == 0);
4072 ASSERT (retval == strlen (result));