1 /* Test of POSIX compatible vasnwprintf() and asnwprintf() 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. */
21 #include "vasnwprintf.h"
33 #include "minus-zero.h"
38 /* The SGI MIPS floating-point format does not distinguish 0.0 and -0.0. */
42 static double plus_zero
= 0.0;
43 double minus_zero
= minus_zerod
;
44 return memcmp (&plus_zero
, &minus_zero
, sizeof (double)) != 0;
47 /* Representation of an 80-bit 'long double' as an initializer for a sequence
48 of 'unsigned int' words. */
49 #ifdef WORDS_BIGENDIAN
50 # define LDBL80_WORDS(exponent,manthi,mantlo) \
51 { ((unsigned int) (exponent) << 16) | ((unsigned int) (manthi) >> 16), \
52 ((unsigned int) (manthi) << 16) | ((unsigned int) (mantlo) >> 16), \
53 (unsigned int) (mantlo) << 16 \
56 # define LDBL80_WORDS(exponent,manthi,mantlo) \
57 { mantlo, manthi, exponent }
61 wcsmatch (const wchar_t *pattern
, const wchar_t *string
)
63 if (wcslen (pattern
) != wcslen (string
))
65 for (; *pattern
!= L
'\0'; pattern
++, string
++)
66 if (*pattern
!= L
'*' && *string
!= *pattern
)
71 /* Test whether string[start_index..end_index-1] is a valid textual
72 representation of NaN. */
74 wcsisnan (const wchar_t *string
, size_t start_index
, size_t end_index
, int uppercase
)
76 if (start_index
< end_index
)
78 if (string
[start_index
] == L
'-')
80 if (start_index
+ 3 <= end_index
81 && wmemcmp (string
+ start_index
, uppercase
? L
"NAN" : L
"nan", 3) == 0)
84 if (start_index
== end_index
85 || (string
[start_index
] == L
'(' && string
[end_index
- 1] == L
')'))
93 test_function (wchar_t * (*my_asnwprintf
) (wchar_t *, size_t *, const wchar_t *, ...))
98 /* Test return value convention. */
100 for (size
= 0; size
<= 8; size
++)
102 size_t length
= size
;
103 wchar_t *result
= my_asnwprintf (NULL
, &length
, L
"%d", 12345);
104 ASSERT (result
!= NULL
);
105 ASSERT (wcscmp (result
, L
"12345") == 0);
106 ASSERT (length
== 5);
110 for (size
= 0; size
<= 8; size
++)
115 wmemcpy (buf
, L
"DEADBEEF", 8);
117 result
= my_asnwprintf (buf
, &length
, L
"%d", 12345);
118 ASSERT (result
!= NULL
);
119 ASSERT (wcscmp (result
, L
"12345") == 0);
120 ASSERT (length
== 5);
122 ASSERT (result
!= buf
);
123 ASSERT (wmemcmp (buf
+ size
, &L
"DEADBEEF"[size
], 8 - size
) == 0);
128 /* Test support of size specifiers as in C99. */
133 my_asnwprintf (NULL
, &length
, L
"%ju %d", (uintmax_t) 12345671, 33, 44, 55);
134 ASSERT (result
!= NULL
);
135 ASSERT (wcscmp (result
, L
"12345671 33") == 0);
136 ASSERT (length
== wcslen (result
));
143 my_asnwprintf (NULL
, &length
, L
"%zu %d", (size_t) 12345672, 33, 44, 55);
144 ASSERT (result
!= NULL
);
145 ASSERT (wcscmp (result
, L
"12345672 33") == 0);
146 ASSERT (length
== wcslen (result
));
153 my_asnwprintf (NULL
, &length
, L
"%tu %d", (ptrdiff_t) 12345673, 33, 44, 55);
154 ASSERT (result
!= NULL
);
155 ASSERT (wcscmp (result
, L
"12345673 33") == 0);
156 ASSERT (length
== wcslen (result
));
163 my_asnwprintf (NULL
, &length
, L
"%Lg %d", (long double) 1.5, 33, 44, 55);
164 ASSERT (result
!= NULL
);
165 ASSERT (wcscmp (result
, L
"1.5 33") == 0);
166 ASSERT (length
== wcslen (result
));
170 /* Test the support of the 'a' and 'A' conversion specifier for hexadecimal
171 output of floating-point numbers. */
173 { /* A positive number. */
176 my_asnwprintf (NULL
, &length
, L
"%a %d", 3.1416015625, 33, 44, 55);
177 ASSERT (result
!= NULL
);
178 ASSERT (wcscmp (result
, L
"0x1.922p+1 33") == 0
179 || wcscmp (result
, L
"0x3.244p+0 33") == 0
180 || wcscmp (result
, L
"0x6.488p-1 33") == 0
181 || wcscmp (result
, L
"0xc.91p-2 33") == 0);
182 ASSERT (length
== wcslen (result
));
186 { /* A negative number. */
189 my_asnwprintf (NULL
, &length
, L
"%A %d", -3.1416015625, 33, 44, 55);
190 ASSERT (result
!= NULL
);
191 ASSERT (wcscmp (result
, L
"-0X1.922P+1 33") == 0
192 || wcscmp (result
, L
"-0X3.244P+0 33") == 0
193 || wcscmp (result
, L
"-0X6.488P-1 33") == 0
194 || wcscmp (result
, L
"-0XC.91P-2 33") == 0);
195 ASSERT (length
== wcslen (result
));
199 { /* Positive zero. */
202 my_asnwprintf (NULL
, &length
, L
"%a %d", 0.0, 33, 44, 55);
203 ASSERT (result
!= NULL
);
204 ASSERT (wcscmp (result
, L
"0x0p+0 33") == 0);
205 ASSERT (length
== wcslen (result
));
209 { /* Negative zero. */
212 my_asnwprintf (NULL
, &length
, L
"%a %d", minus_zerod
, 33, 44, 55);
213 ASSERT (result
!= NULL
);
214 if (have_minus_zero ())
215 ASSERT (wcscmp (result
, L
"-0x0p+0 33") == 0);
216 ASSERT (length
== wcslen (result
));
220 { /* Positive infinity. */
223 my_asnwprintf (NULL
, &length
, L
"%a %d", Infinityd (), 33, 44, 55);
224 ASSERT (result
!= NULL
);
225 ASSERT (wcscmp (result
, L
"inf 33") == 0);
226 ASSERT (length
== wcslen (result
));
230 { /* Negative infinity. */
233 my_asnwprintf (NULL
, &length
, L
"%a %d", - Infinityd (), 33, 44, 55);
234 ASSERT (result
!= NULL
);
235 ASSERT (wcscmp (result
, L
"-inf 33") == 0);
236 ASSERT (length
== wcslen (result
));
243 my_asnwprintf (NULL
, &length
, L
"%a %d", NaNd (), 33, 44, 55);
244 ASSERT (result
!= NULL
);
245 ASSERT (wcslen (result
) >= 3 + 3
246 && wcsisnan (result
, 0, wcslen (result
) - 3, 0)
247 && wcscmp (result
+ wcslen (result
) - 3, L
" 33") == 0);
248 ASSERT (length
== wcslen (result
));
252 { /* Signalling NaN. */
255 my_asnwprintf (NULL
, &length
, L
"%a %d", SNaNd (), 33, 44, 55);
256 ASSERT (result
!= NULL
);
257 ASSERT (wcslen (result
) >= 3 + 3
258 && wcsisnan (result
, 0, wcslen (result
) - 3, 0)
259 && wcscmp (result
+ wcslen (result
) - 3, L
" 33") == 0);
260 ASSERT (length
== wcslen (result
));
265 { /* Rounding near the decimal point. */
268 my_asnwprintf (NULL
, &length
, L
"%.0a %d", 1.5, 33, 44, 55);
269 ASSERT (result
!= NULL
);
270 ASSERT (wcscmp (result
, L
"0x1p+0 33") == 0
271 || wcscmp (result
, L
"0x2p+0 33") == 0
272 || wcscmp (result
, L
"0x3p-1 33") == 0
273 || wcscmp (result
, L
"0x6p-2 33") == 0
274 || wcscmp (result
, L
"0xcp-3 33") == 0);
275 ASSERT (length
== wcslen (result
));
279 { /* Rounding with precision 0. */
282 my_asnwprintf (NULL
, &length
, L
"%.0a %d", 1.51, 33, 44, 55);
283 ASSERT (result
!= NULL
);
284 ASSERT (wcscmp (result
, L
"0x2p+0 33") == 0
285 || wcscmp (result
, L
"0x3p-1 33") == 0
286 || wcscmp (result
, L
"0x6p-2 33") == 0
287 || wcscmp (result
, L
"0xcp-3 33") == 0);
288 ASSERT (length
== wcslen (result
));
292 { /* Rounding with precision 1. */
295 my_asnwprintf (NULL
, &length
, L
"%.1a %d", 1.51, 33, 44, 55);
296 ASSERT (result
!= NULL
);
297 ASSERT (wcscmp (result
, L
"0x1.8p+0 33") == 0
298 || wcscmp (result
, L
"0x3.0p-1 33") == 0
299 || wcscmp (result
, L
"0x6.1p-2 33") == 0
300 || wcscmp (result
, L
"0xc.1p-3 33") == 0);
301 ASSERT (length
== wcslen (result
));
305 { /* Rounding with precision 2. */
308 my_asnwprintf (NULL
, &length
, L
"%.2a %d", 1.51, 33, 44, 55);
309 ASSERT (result
!= NULL
);
310 ASSERT (wcscmp (result
, L
"0x1.83p+0 33") == 0
311 || wcscmp (result
, L
"0x3.05p-1 33") == 0
312 || wcscmp (result
, L
"0x6.0ap-2 33") == 0
313 || wcscmp (result
, L
"0xc.14p-3 33") == 0);
314 ASSERT (length
== wcslen (result
));
318 { /* Rounding with precision 3. */
321 my_asnwprintf (NULL
, &length
, L
"%.3a %d", 1.51, 33, 44, 55);
322 ASSERT (result
!= NULL
);
323 ASSERT (wcscmp (result
, L
"0x1.829p+0 33") == 0
324 || wcscmp (result
, L
"0x3.052p-1 33") == 0
325 || wcscmp (result
, L
"0x6.0a4p-2 33") == 0
326 || wcscmp (result
, L
"0xc.148p-3 33") == 0);
327 ASSERT (length
== wcslen (result
));
331 { /* Rounding can turn a ...FFF into a ...000. */
334 my_asnwprintf (NULL
, &length
, L
"%.3a %d", 1.49999, 33, 44, 55);
335 ASSERT (result
!= NULL
);
336 ASSERT (wcscmp (result
, L
"0x1.800p+0 33") == 0
337 || wcscmp (result
, L
"0x3.000p-1 33") == 0
338 || wcscmp (result
, L
"0x6.000p-2 33") == 0
339 || wcscmp (result
, L
"0xc.000p-3 33") == 0);
340 ASSERT (length
== wcslen (result
));
344 { /* Rounding can turn a ...FFF into a ...000.
345 This shows a Mac OS X 10.3.9 (Darwin 7.9) bug. */
348 my_asnwprintf (NULL
, &length
, L
"%.1a %d", 1.999, 33, 44, 55);
349 ASSERT (result
!= NULL
);
350 ASSERT (wcscmp (result
, L
"0x1.0p+1 33") == 0
351 || wcscmp (result
, L
"0x2.0p+0 33") == 0
352 || wcscmp (result
, L
"0x4.0p-1 33") == 0
353 || wcscmp (result
, L
"0x8.0p-2 33") == 0);
354 ASSERT (length
== wcslen (result
));
361 my_asnwprintf (NULL
, &length
, L
"%10a %d", 1.75, 33, 44, 55);
362 ASSERT (result
!= NULL
);
363 ASSERT (wcscmp (result
, L
" 0x1.cp+0 33") == 0
364 || wcscmp (result
, L
" 0x3.8p-1 33") == 0
365 || wcscmp (result
, L
" 0x7p-2 33") == 0
366 || wcscmp (result
, L
" 0xep-3 33") == 0);
367 ASSERT (length
== wcslen (result
));
371 { /* Width given as argument. */
374 my_asnwprintf (NULL
, &length
, L
"%*a %d", 10, 1.75, 33, 44, 55);
375 ASSERT (result
!= NULL
);
376 ASSERT (wcscmp (result
, L
" 0x1.cp+0 33") == 0
377 || wcscmp (result
, L
" 0x3.8p-1 33") == 0
378 || wcscmp (result
, L
" 0x7p-2 33") == 0
379 || wcscmp (result
, L
" 0xep-3 33") == 0);
380 ASSERT (length
== wcslen (result
));
384 { /* Negative width given as argument (cf. FLAG_LEFT below). */
387 my_asnwprintf (NULL
, &length
, L
"%*a %d", -10, 1.75, 33, 44, 55);
388 ASSERT (result
!= NULL
);
389 ASSERT (wcscmp (result
, L
"0x1.cp+0 33") == 0
390 || wcscmp (result
, L
"0x3.8p-1 33") == 0
391 || wcscmp (result
, L
"0x7p-2 33") == 0
392 || wcscmp (result
, L
"0xep-3 33") == 0);
393 ASSERT (length
== wcslen (result
));
397 { /* Small precision. */
400 my_asnwprintf (NULL
, &length
, L
"%.10a %d", 1.75, 33, 44, 55);
401 ASSERT (result
!= NULL
);
402 ASSERT (wcscmp (result
, L
"0x1.c000000000p+0 33") == 0
403 || wcscmp (result
, L
"0x3.8000000000p-1 33") == 0
404 || wcscmp (result
, L
"0x7.0000000000p-2 33") == 0
405 || wcscmp (result
, L
"0xe.0000000000p-3 33") == 0);
406 ASSERT (length
== wcslen (result
));
410 { /* Large precision. */
413 my_asnwprintf (NULL
, &length
, L
"%.50a %d", 1.75, 33, 44, 55);
414 ASSERT (result
!= NULL
);
415 ASSERT (wcscmp (result
, L
"0x1.c0000000000000000000000000000000000000000000000000p+0 33") == 0
416 || wcscmp (result
, L
"0x3.80000000000000000000000000000000000000000000000000p-1 33") == 0
417 || wcscmp (result
, L
"0x7.00000000000000000000000000000000000000000000000000p-2 33") == 0
418 || wcscmp (result
, L
"0xe.00000000000000000000000000000000000000000000000000p-3 33") == 0);
419 ASSERT (length
== wcslen (result
));
426 my_asnwprintf (NULL
, &length
, L
"%-10a %d", 1.75, 33, 44, 55);
427 ASSERT (result
!= NULL
);
428 ASSERT (wcscmp (result
, L
"0x1.cp+0 33") == 0
429 || wcscmp (result
, L
"0x3.8p-1 33") == 0
430 || wcscmp (result
, L
"0x7p-2 33") == 0
431 || wcscmp (result
, L
"0xep-3 33") == 0);
432 ASSERT (length
== wcslen (result
));
436 { /* FLAG_SHOWSIGN. */
439 my_asnwprintf (NULL
, &length
, L
"%+a %d", 1.75, 33, 44, 55);
440 ASSERT (result
!= NULL
);
441 ASSERT (wcscmp (result
, L
"+0x1.cp+0 33") == 0
442 || wcscmp (result
, L
"+0x3.8p-1 33") == 0
443 || wcscmp (result
, L
"+0x7p-2 33") == 0
444 || wcscmp (result
, L
"+0xep-3 33") == 0);
445 ASSERT (length
== wcslen (result
));
452 my_asnwprintf (NULL
, &length
, L
"% a %d", 1.75, 33, 44, 55);
453 ASSERT (result
!= NULL
);
454 ASSERT (wcscmp (result
, L
" 0x1.cp+0 33") == 0
455 || wcscmp (result
, L
" 0x3.8p-1 33") == 0
456 || wcscmp (result
, L
" 0x7p-2 33") == 0
457 || wcscmp (result
, L
" 0xep-3 33") == 0);
458 ASSERT (length
== wcslen (result
));
465 my_asnwprintf (NULL
, &length
, L
"%#a %d", 1.75, 33, 44, 55);
466 ASSERT (result
!= NULL
);
467 ASSERT (wcscmp (result
, L
"0x1.cp+0 33") == 0
468 || wcscmp (result
, L
"0x3.8p-1 33") == 0
469 || wcscmp (result
, L
"0x7.p-2 33") == 0
470 || wcscmp (result
, L
"0xe.p-3 33") == 0);
471 ASSERT (length
== wcslen (result
));
478 my_asnwprintf (NULL
, &length
, L
"%#a %d", 1.0, 33, 44, 55);
479 ASSERT (result
!= NULL
);
480 ASSERT (wcscmp (result
, L
"0x1.p+0 33") == 0
481 || wcscmp (result
, L
"0x2.p-1 33") == 0
482 || wcscmp (result
, L
"0x4.p-2 33") == 0
483 || wcscmp (result
, L
"0x8.p-3 33") == 0);
484 ASSERT (length
== wcslen (result
));
488 { /* FLAG_ZERO with finite number. */
491 my_asnwprintf (NULL
, &length
, L
"%010a %d", 1.75, 33, 44, 55);
492 ASSERT (result
!= NULL
);
493 ASSERT (wcscmp (result
, L
"0x001.cp+0 33") == 0
494 || wcscmp (result
, L
"0x003.8p-1 33") == 0
495 || wcscmp (result
, L
"0x00007p-2 33") == 0
496 || wcscmp (result
, L
"0x0000ep-3 33") == 0);
497 ASSERT (length
== wcslen (result
));
501 { /* FLAG_ZERO with infinite number. */
504 my_asnwprintf (NULL
, &length
, L
"%010a %d", Infinityd (), 33, 44, 55);
505 ASSERT (result
!= NULL
);
506 /* "0000000inf 33" is not a valid result; see
507 <https://lists.gnu.org/r/bug-gnulib/2007-04/msg00107.html> */
508 ASSERT (wcscmp (result
, L
" inf 33") == 0);
509 ASSERT (length
== wcslen (result
));
513 { /* FLAG_ZERO with NaN. */
516 my_asnwprintf (NULL
, &length
, L
"%050a %d", NaNd (), 33, 44, 55);
517 ASSERT (result
!= NULL
);
518 /* "0000000nan 33" is not a valid result; see
519 <https://lists.gnu.org/r/bug-gnulib/2007-04/msg00107.html> */
520 ASSERT (wcslen (result
) == 50 + 3
521 && wcsisnan (result
, wcsspn (result
, L
" "), wcslen (result
) - 3, 0)
522 && wcscmp (result
+ wcslen (result
) - 3, L
" 33") == 0);
523 ASSERT (length
== wcslen (result
));
527 { /* A positive number. */
530 my_asnwprintf (NULL
, &length
, L
"%La %d", 3.1416015625L, 33, 44, 55);
531 ASSERT (result
!= NULL
);
532 ASSERT (wcscmp (result
, L
"0x1.922p+1 33") == 0
533 || wcscmp (result
, L
"0x3.244p+0 33") == 0
534 || wcscmp (result
, L
"0x6.488p-1 33") == 0
535 || wcscmp (result
, L
"0xc.91p-2 33") == 0);
536 ASSERT (length
== wcslen (result
));
540 { /* A negative number. */
543 my_asnwprintf (NULL
, &length
, L
"%LA %d", -3.1416015625L, 33, 44, 55);
544 ASSERT (result
!= NULL
);
545 ASSERT (wcscmp (result
, L
"-0X1.922P+1 33") == 0
546 || wcscmp (result
, L
"-0X3.244P+0 33") == 0
547 || wcscmp (result
, L
"-0X6.488P-1 33") == 0
548 || wcscmp (result
, L
"-0XC.91P-2 33") == 0);
549 ASSERT (length
== wcslen (result
));
553 { /* Positive zero. */
556 my_asnwprintf (NULL
, &length
, L
"%La %d", 0.0L, 33, 44, 55);
557 ASSERT (result
!= NULL
);
558 ASSERT (wcscmp (result
, L
"0x0p+0 33") == 0);
559 ASSERT (length
== wcslen (result
));
563 { /* Negative zero. */
566 my_asnwprintf (NULL
, &length
, L
"%La %d", minus_zerol
, 33, 44, 55);
567 ASSERT (result
!= NULL
);
568 if (have_minus_zero ())
569 ASSERT (wcscmp (result
, L
"-0x0p+0 33") == 0);
570 ASSERT (length
== wcslen (result
));
574 { /* Positive infinity. */
577 my_asnwprintf (NULL
, &length
, L
"%La %d", Infinityl (), 33, 44, 55);
578 ASSERT (result
!= NULL
);
579 /* Note: This assertion fails under valgrind.
580 Reported at <https://bugs.kde.org/show_bug.cgi?id=424044>. */
581 ASSERT (wcscmp (result
, L
"inf 33") == 0);
582 ASSERT (length
== wcslen (result
));
586 { /* Negative infinity. */
589 my_asnwprintf (NULL
, &length
, L
"%La %d", - Infinityl (), 33, 44, 55);
590 ASSERT (result
!= NULL
);
591 ASSERT (wcscmp (result
, L
"-inf 33") == 0);
592 ASSERT (length
== wcslen (result
));
599 my_asnwprintf (NULL
, &length
, L
"%La %d", NaNl (), 33, 44, 55);
600 ASSERT (result
!= NULL
);
601 ASSERT (wcslen (result
) >= 3 + 3
602 && wcsisnan (result
, 0, wcslen (result
) - 3, 0)
603 && wcscmp (result
+ wcslen (result
) - 3, L
" 33") == 0);
604 ASSERT (length
== wcslen (result
));
608 { /* Signalling NaN. */
611 my_asnwprintf (NULL
, &length
, L
"%La %d", SNaNl (), 33, 44, 55);
612 ASSERT (result
!= NULL
);
613 ASSERT (wcslen (result
) >= 3 + 3
614 && wcsisnan (result
, 0, wcslen (result
) - 3, 0)
615 && wcscmp (result
+ wcslen (result
) - 3, L
" 33") == 0);
616 ASSERT (length
== wcslen (result
));
620 #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
622 static union { unsigned int word
[4]; long double value
; } x
=
623 { .word
= LDBL80_WORDS (0xFFFF, 0xC3333333, 0x00000000) };
626 my_asnwprintf (NULL
, &length
, L
"%La %d", x
.value
, 33, 44, 55);
627 ASSERT (result
!= NULL
);
628 ASSERT (wcslen (result
) >= 3 + 3
629 && wcsisnan (result
, 0, wcslen (result
) - 3, 0)
630 && wcscmp (result
+ wcslen (result
) - 3, L
" 33") == 0);
631 ASSERT (length
== wcslen (result
));
635 /* Signalling NaN. */
636 static union { unsigned int word
[4]; long double value
; } x
=
637 { .word
= LDBL80_WORDS (0xFFFF, 0x83333333, 0x00000000) };
640 my_asnwprintf (NULL
, &length
, L
"%La %d", x
.value
, 33, 44, 55);
641 ASSERT (result
!= NULL
);
642 ASSERT (wcslen (result
) >= 3 + 3
643 && wcsisnan (result
, 0, wcslen (result
) - 3, 0)
644 && wcscmp (result
+ wcslen (result
) - 3, L
" 33") == 0);
645 ASSERT (length
== wcslen (result
));
648 /* asnwprintf should print something for noncanonical values. */
650 static union { unsigned int word
[4]; long double value
; } x
=
651 { .word
= LDBL80_WORDS (0xFFFF, 0x40000001, 0x00000000) };
654 my_asnwprintf (NULL
, &length
, L
"%La %d", x
.value
, 33, 44, 55);
655 ASSERT (result
!= NULL
);
656 ASSERT (length
== wcslen (result
));
657 ASSERT (3 < length
&& wcscmp (result
+ length
- 3, L
" 33") == 0);
660 { /* Pseudo-Infinity. */
661 static union { unsigned int word
[4]; long double value
; } x
=
662 { .word
= LDBL80_WORDS (0xFFFF, 0x00000000, 0x00000000) };
665 my_asnwprintf (NULL
, &length
, L
"%La %d", x
.value
, 33, 44, 55);
666 ASSERT (result
!= NULL
);
667 ASSERT (length
== wcslen (result
));
668 ASSERT (3 < length
&& wcscmp (result
+ length
- 3, L
" 33") == 0);
672 static union { unsigned int word
[4]; long double value
; } x
=
673 { .word
= LDBL80_WORDS (0x4004, 0x00000000, 0x00000000) };
676 my_asnwprintf (NULL
, &length
, L
"%La %d", x
.value
, 33, 44, 55);
677 ASSERT (result
!= NULL
);
678 ASSERT (length
== wcslen (result
));
679 ASSERT (3 < length
&& wcscmp (result
+ length
- 3, L
" 33") == 0);
682 { /* Unnormalized number. */
683 static union { unsigned int word
[4]; long double value
; } x
=
684 { .word
= LDBL80_WORDS (0x4000, 0x63333333, 0x00000000) };
687 my_asnwprintf (NULL
, &length
, L
"%La %d", x
.value
, 33, 44, 55);
688 ASSERT (result
!= NULL
);
689 ASSERT (length
== wcslen (result
));
690 ASSERT (3 < length
&& wcscmp (result
+ length
- 3, L
" 33") == 0);
693 { /* Pseudo-Denormal. */
694 static union { unsigned int word
[4]; long double value
; } x
=
695 { .word
= LDBL80_WORDS (0x0000, 0x83333333, 0x00000000) };
698 my_asnwprintf (NULL
, &length
, L
"%La %d", x
.value
, 33, 44, 55);
699 ASSERT (result
!= NULL
);
700 ASSERT (length
== wcslen (result
));
701 ASSERT (3 < length
&& wcscmp (result
+ length
- 3, L
" 33") == 0);
706 { /* Rounding near the decimal point. */
709 my_asnwprintf (NULL
, &length
, L
"%.0La %d", 1.5L, 33, 44, 55);
710 ASSERT (result
!= NULL
);
711 ASSERT (wcscmp (result
, L
"0x2p+0 33") == 0
712 || wcscmp (result
, L
"0x3p-1 33") == 0
713 || wcscmp (result
, L
"0x6p-2 33") == 0
714 || wcscmp (result
, L
"0xcp-3 33") == 0);
715 ASSERT (length
== wcslen (result
));
719 { /* Rounding with precision 0. */
722 my_asnwprintf (NULL
, &length
, L
"%.0La %d", 1.51L, 33, 44, 55);
723 ASSERT (result
!= NULL
);
724 ASSERT (wcscmp (result
, L
"0x2p+0 33") == 0
725 || wcscmp (result
, L
"0x3p-1 33") == 0
726 || wcscmp (result
, L
"0x6p-2 33") == 0
727 || wcscmp (result
, L
"0xcp-3 33") == 0);
728 ASSERT (length
== wcslen (result
));
732 { /* Rounding with precision 1. */
735 my_asnwprintf (NULL
, &length
, L
"%.1La %d", 1.51L, 33, 44, 55);
736 ASSERT (result
!= NULL
);
737 ASSERT (wcscmp (result
, L
"0x1.8p+0 33") == 0
738 || wcscmp (result
, L
"0x3.0p-1 33") == 0
739 || wcscmp (result
, L
"0x6.1p-2 33") == 0
740 || wcscmp (result
, L
"0xc.1p-3 33") == 0);
741 ASSERT (length
== wcslen (result
));
745 { /* Rounding with precision 2. */
748 my_asnwprintf (NULL
, &length
, L
"%.2La %d", 1.51L, 33, 44, 55);
749 ASSERT (result
!= NULL
);
750 ASSERT (wcscmp (result
, L
"0x1.83p+0 33") == 0
751 || wcscmp (result
, L
"0x3.05p-1 33") == 0
752 || wcscmp (result
, L
"0x6.0ap-2 33") == 0
753 || wcscmp (result
, L
"0xc.14p-3 33") == 0);
754 ASSERT (length
== wcslen (result
));
758 { /* Rounding with precision 3. */
761 my_asnwprintf (NULL
, &length
, L
"%.3La %d", 1.51L, 33, 44, 55);
762 ASSERT (result
!= NULL
);
763 ASSERT (wcscmp (result
, L
"0x1.829p+0 33") == 0
764 || wcscmp (result
, L
"0x3.052p-1 33") == 0
765 || wcscmp (result
, L
"0x6.0a4p-2 33") == 0
766 || wcscmp (result
, L
"0xc.148p-3 33") == 0);
767 ASSERT (length
== wcslen (result
));
771 { /* Rounding can turn a ...FFF into a ...000. */
774 my_asnwprintf (NULL
, &length
, L
"%.3La %d", 1.49999L, 33, 44, 55);
775 ASSERT (result
!= NULL
);
776 ASSERT (wcscmp (result
, L
"0x1.800p+0 33") == 0
777 || wcscmp (result
, L
"0x3.000p-1 33") == 0
778 || wcscmp (result
, L
"0x6.000p-2 33") == 0
779 || wcscmp (result
, L
"0xc.000p-3 33") == 0);
780 ASSERT (length
== wcslen (result
));
784 { /* Rounding can turn a ...FFF into a ...000.
785 This shows a Mac OS X 10.3.9 (Darwin 7.9) bug and a
786 glibc 2.4 bug <https://sourceware.org/bugzilla/show_bug.cgi?id=2908>. */
789 my_asnwprintf (NULL
, &length
, L
"%.1La %d", 1.999L, 33, 44, 55);
790 ASSERT (result
!= NULL
);
791 ASSERT (wcscmp (result
, L
"0x1.0p+1 33") == 0
792 || wcscmp (result
, L
"0x2.0p+0 33") == 0
793 || wcscmp (result
, L
"0x4.0p-1 33") == 0
794 || wcscmp (result
, L
"0x8.0p-2 33") == 0);
795 ASSERT (length
== wcslen (result
));
802 my_asnwprintf (NULL
, &length
, L
"%10La %d", 1.75L, 33, 44, 55);
803 ASSERT (result
!= NULL
);
804 ASSERT (wcscmp (result
, L
" 0x1.cp+0 33") == 0
805 || wcscmp (result
, L
" 0x3.8p-1 33") == 0
806 || wcscmp (result
, L
" 0x7p-2 33") == 0
807 || wcscmp (result
, L
" 0xep-3 33") == 0);
808 ASSERT (length
== wcslen (result
));
812 { /* Width given as argument. */
815 my_asnwprintf (NULL
, &length
, L
"%*La %d", 10, 1.75L, 33, 44, 55);
816 ASSERT (result
!= NULL
);
817 ASSERT (wcscmp (result
, L
" 0x1.cp+0 33") == 0
818 || wcscmp (result
, L
" 0x3.8p-1 33") == 0
819 || wcscmp (result
, L
" 0x7p-2 33") == 0
820 || wcscmp (result
, L
" 0xep-3 33") == 0);
821 ASSERT (length
== wcslen (result
));
825 { /* Negative width given as argument (cf. FLAG_LEFT below). */
828 my_asnwprintf (NULL
, &length
, L
"%*La %d", -10, 1.75L, 33, 44, 55);
829 ASSERT (result
!= NULL
);
830 ASSERT (wcscmp (result
, L
"0x1.cp+0 33") == 0
831 || wcscmp (result
, L
"0x3.8p-1 33") == 0
832 || wcscmp (result
, L
"0x7p-2 33") == 0
833 || wcscmp (result
, L
"0xep-3 33") == 0);
834 ASSERT (length
== wcslen (result
));
838 { /* Small precision. */
841 my_asnwprintf (NULL
, &length
, L
"%.10La %d", 1.75L, 33, 44, 55);
842 ASSERT (result
!= NULL
);
843 ASSERT (wcscmp (result
, L
"0x1.c000000000p+0 33") == 0
844 || wcscmp (result
, L
"0x3.8000000000p-1 33") == 0
845 || wcscmp (result
, L
"0x7.0000000000p-2 33") == 0
846 || wcscmp (result
, L
"0xe.0000000000p-3 33") == 0);
847 ASSERT (length
== wcslen (result
));
851 { /* Large precision. */
854 my_asnwprintf (NULL
, &length
, L
"%.50La %d", 1.75L, 33, 44, 55);
855 ASSERT (result
!= NULL
);
856 ASSERT (wcscmp (result
, L
"0x1.c0000000000000000000000000000000000000000000000000p+0 33") == 0
857 || wcscmp (result
, L
"0x3.80000000000000000000000000000000000000000000000000p-1 33") == 0
858 || wcscmp (result
, L
"0x7.00000000000000000000000000000000000000000000000000p-2 33") == 0
859 || wcscmp (result
, L
"0xe.00000000000000000000000000000000000000000000000000p-3 33") == 0);
860 ASSERT (length
== wcslen (result
));
867 my_asnwprintf (NULL
, &length
, L
"%-10La %d", 1.75L, 33, 44, 55);
868 ASSERT (result
!= NULL
);
869 ASSERT (wcscmp (result
, L
"0x1.cp+0 33") == 0
870 || wcscmp (result
, L
"0x3.8p-1 33") == 0
871 || wcscmp (result
, L
"0x7p-2 33") == 0
872 || wcscmp (result
, L
"0xep-3 33") == 0);
873 ASSERT (length
== wcslen (result
));
877 { /* FLAG_SHOWSIGN. */
880 my_asnwprintf (NULL
, &length
, L
"%+La %d", 1.75L, 33, 44, 55);
881 ASSERT (result
!= NULL
);
882 ASSERT (wcscmp (result
, L
"+0x1.cp+0 33") == 0
883 || wcscmp (result
, L
"+0x3.8p-1 33") == 0
884 || wcscmp (result
, L
"+0x7p-2 33") == 0
885 || wcscmp (result
, L
"+0xep-3 33") == 0);
886 ASSERT (length
== wcslen (result
));
893 my_asnwprintf (NULL
, &length
, L
"% La %d", 1.75L, 33, 44, 55);
894 ASSERT (result
!= NULL
);
895 ASSERT (wcscmp (result
, L
" 0x1.cp+0 33") == 0
896 || wcscmp (result
, L
" 0x3.8p-1 33") == 0
897 || wcscmp (result
, L
" 0x7p-2 33") == 0
898 || wcscmp (result
, L
" 0xep-3 33") == 0);
899 ASSERT (length
== wcslen (result
));
906 my_asnwprintf (NULL
, &length
, L
"%#La %d", 1.75L, 33, 44, 55);
907 ASSERT (result
!= NULL
);
908 ASSERT (wcscmp (result
, L
"0x1.cp+0 33") == 0
909 || wcscmp (result
, L
"0x3.8p-1 33") == 0
910 || wcscmp (result
, L
"0x7.p-2 33") == 0
911 || wcscmp (result
, L
"0xe.p-3 33") == 0);
912 ASSERT (length
== wcslen (result
));
919 my_asnwprintf (NULL
, &length
, L
"%#La %d", 1.0L, 33, 44, 55);
920 ASSERT (result
!= NULL
);
921 ASSERT (wcscmp (result
, L
"0x1.p+0 33") == 0
922 || wcscmp (result
, L
"0x2.p-1 33") == 0
923 || wcscmp (result
, L
"0x4.p-2 33") == 0
924 || wcscmp (result
, L
"0x8.p-3 33") == 0);
925 ASSERT (length
== wcslen (result
));
929 { /* FLAG_ZERO with finite number. */
932 my_asnwprintf (NULL
, &length
, L
"%010La %d", 1.75L, 33, 44, 55);
933 ASSERT (result
!= NULL
);
934 ASSERT (wcscmp (result
, L
"0x001.cp+0 33") == 0
935 || wcscmp (result
, L
"0x003.8p-1 33") == 0
936 || wcscmp (result
, L
"0x00007p-2 33") == 0
937 || wcscmp (result
, L
"0x0000ep-3 33") == 0);
938 ASSERT (length
== wcslen (result
));
942 { /* FLAG_ZERO with infinite number. */
945 my_asnwprintf (NULL
, &length
, L
"%010La %d", Infinityl (), 33, 44, 55);
946 ASSERT (result
!= NULL
);
947 /* "0000000inf 33" is not a valid result; see
948 <https://lists.gnu.org/r/bug-gnulib/2007-04/msg00107.html> */
949 ASSERT (wcscmp (result
, L
" inf 33") == 0);
950 ASSERT (length
== wcslen (result
));
954 { /* FLAG_ZERO with NaN. */
957 my_asnwprintf (NULL
, &length
, L
"%050La %d", NaNl (), 33, 44, 55);
958 ASSERT (result
!= NULL
);
959 /* "0000000nan 33" is not a valid result; see
960 <https://lists.gnu.org/r/bug-gnulib/2007-04/msg00107.html> */
961 ASSERT (wcslen (result
) == 50 + 3
962 && wcsisnan (result
, wcsspn (result
, L
" "), wcslen (result
) - 3, 0)
963 && wcscmp (result
+ wcslen (result
) - 3, L
" 33") == 0);
964 ASSERT (length
== wcslen (result
));
968 /* Test the support of the %f format directive. */
970 { /* A positive number. */
973 my_asnwprintf (NULL
, &length
, L
"%f %d", 12.75, 33, 44, 55);
974 ASSERT (result
!= NULL
);
975 ASSERT (wcscmp (result
, L
"12.750000 33") == 0);
976 ASSERT (length
== wcslen (result
));
980 { /* A larger positive number. */
983 my_asnwprintf (NULL
, &length
, L
"%f %d", 1234567.0, 33, 44, 55);
984 ASSERT (result
!= NULL
);
985 ASSERT (wcscmp (result
, L
"1234567.000000 33") == 0);
986 ASSERT (length
== wcslen (result
));
990 { /* Small and large positive numbers. */
991 static struct { double value
; const wchar_t *string
; } data
[] =
993 { 1.234321234321234e-37, L
"0.000000" },
994 { 1.234321234321234e-36, L
"0.000000" },
995 { 1.234321234321234e-35, L
"0.000000" },
996 { 1.234321234321234e-34, L
"0.000000" },
997 { 1.234321234321234e-33, L
"0.000000" },
998 { 1.234321234321234e-32, L
"0.000000" },
999 { 1.234321234321234e-31, L
"0.000000" },
1000 { 1.234321234321234e-30, L
"0.000000" },
1001 { 1.234321234321234e-29, L
"0.000000" },
1002 { 1.234321234321234e-28, L
"0.000000" },
1003 { 1.234321234321234e-27, L
"0.000000" },
1004 { 1.234321234321234e-26, L
"0.000000" },
1005 { 1.234321234321234e-25, L
"0.000000" },
1006 { 1.234321234321234e-24, L
"0.000000" },
1007 { 1.234321234321234e-23, L
"0.000000" },
1008 { 1.234321234321234e-22, L
"0.000000" },
1009 { 1.234321234321234e-21, L
"0.000000" },
1010 { 1.234321234321234e-20, L
"0.000000" },
1011 { 1.234321234321234e-19, L
"0.000000" },
1012 { 1.234321234321234e-18, L
"0.000000" },
1013 { 1.234321234321234e-17, L
"0.000000" },
1014 { 1.234321234321234e-16, L
"0.000000" },
1015 { 1.234321234321234e-15, L
"0.000000" },
1016 { 1.234321234321234e-14, L
"0.000000" },
1017 { 1.234321234321234e-13, L
"0.000000" },
1018 { 1.234321234321234e-12, L
"0.000000" },
1019 { 1.234321234321234e-11, L
"0.000000" },
1020 { 1.234321234321234e-10, L
"0.000000" },
1021 { 1.234321234321234e-9, L
"0.000000" },
1022 { 1.234321234321234e-8, L
"0.000000" },
1023 { 1.234321234321234e-7, L
"0.000000" },
1024 { 1.234321234321234e-6, L
"0.000001" },
1025 { 1.234321234321234e-5, L
"0.000012" },
1026 { 1.234321234321234e-4, L
"0.000123" },
1027 { 1.234321234321234e-3, L
"0.001234" },
1028 { 1.234321234321234e-2, L
"0.012343" },
1029 { 1.234321234321234e-1, L
"0.123432" },
1030 { 1.234321234321234, L
"1.234321" },
1031 { 1.234321234321234e1
, L
"12.343212" },
1032 { 1.234321234321234e2
, L
"123.432123" },
1033 { 1.234321234321234e3
, L
"1234.321234" },
1034 { 1.234321234321234e4
, L
"12343.212343" },
1035 { 1.234321234321234e5
, L
"123432.123432" },
1036 { 1.234321234321234e6
, L
"1234321.234321" },
1037 { 1.234321234321234e7
, L
"12343212.343212" },
1038 { 1.234321234321234e8
, L
"123432123.432123" },
1039 { 1.234321234321234e9
, L
"1234321234.321234" },
1040 { 1.234321234321234e10
, L
"12343212343.2123**" },
1041 { 1.234321234321234e11
, L
"123432123432.123***" },
1042 { 1.234321234321234e12
, L
"1234321234321.23****" },
1043 { 1.234321234321234e13
, L
"12343212343212.3*****" },
1044 { 1.234321234321234e14
, L
"123432123432123.******" },
1045 { 1.234321234321234e15
, L
"1234321234321234.000000" },
1046 { 1.234321234321234e16
, L
"123432123432123**.000000" },
1047 { 1.234321234321234e17
, L
"123432123432123***.000000" },
1048 { 1.234321234321234e18
, L
"123432123432123****.000000" },
1049 { 1.234321234321234e19
, L
"123432123432123*****.000000" },
1050 { 1.234321234321234e20
, L
"123432123432123******.000000" },
1051 { 1.234321234321234e21
, L
"123432123432123*******.000000" },
1052 { 1.234321234321234e22
, L
"123432123432123********.000000" },
1053 { 1.234321234321234e23
, L
"123432123432123*********.000000" },
1054 { 1.234321234321234e24
, L
"123432123432123**********.000000" },
1055 { 1.234321234321234e25
, L
"123432123432123***********.000000" },
1056 { 1.234321234321234e26
, L
"123432123432123************.000000" },
1057 { 1.234321234321234e27
, L
"123432123432123*************.000000" },
1058 { 1.234321234321234e28
, L
"123432123432123**************.000000" },
1059 { 1.234321234321234e29
, L
"123432123432123***************.000000" },
1060 { 1.234321234321234e30
, L
"123432123432123****************.000000" },
1061 { 1.234321234321234e31
, L
"123432123432123*****************.000000" },
1062 { 1.234321234321234e32
, L
"123432123432123******************.000000" },
1063 { 1.234321234321234e33
, L
"123432123432123*******************.000000" },
1064 { 1.234321234321234e34
, L
"123432123432123********************.000000" },
1065 { 1.234321234321234e35
, L
"123432123432123*********************.000000" },
1066 { 1.234321234321234e36
, L
"123432123432123**********************.000000" }
1069 for (k
= 0; k
< SIZEOF (data
); k
++)
1073 my_asnwprintf (NULL
, &length
, L
"%f", data
[k
].value
);
1074 ASSERT (result
!= NULL
);
1075 ASSERT (wcsmatch (data
[k
].string
, result
));
1076 ASSERT (length
== wcslen (result
));
1081 { /* A negative number. */
1084 my_asnwprintf (NULL
, &length
, L
"%f %d", -0.03125, 33, 44, 55);
1085 ASSERT (result
!= NULL
);
1086 ASSERT (wcscmp (result
, L
"-0.031250 33") == 0);
1087 ASSERT (length
== wcslen (result
));
1091 { /* Positive zero. */
1094 my_asnwprintf (NULL
, &length
, L
"%f %d", 0.0, 33, 44, 55);
1095 ASSERT (result
!= NULL
);
1096 ASSERT (wcscmp (result
, L
"0.000000 33") == 0);
1097 ASSERT (length
== wcslen (result
));
1101 { /* Negative zero. */
1104 my_asnwprintf (NULL
, &length
, L
"%f %d", minus_zerod
, 33, 44, 55);
1105 ASSERT (result
!= NULL
);
1106 if (have_minus_zero ())
1107 ASSERT (wcscmp (result
, L
"-0.000000 33") == 0);
1108 ASSERT (length
== wcslen (result
));
1112 { /* Positive infinity. */
1115 my_asnwprintf (NULL
, &length
, L
"%f %d", Infinityd (), 33, 44, 55);
1116 ASSERT (result
!= NULL
);
1117 ASSERT (wcscmp (result
, L
"inf 33") == 0
1118 || wcscmp (result
, L
"infinity 33") == 0);
1119 ASSERT (length
== wcslen (result
));
1123 { /* Negative infinity. */
1126 my_asnwprintf (NULL
, &length
, L
"%f %d", - Infinityd (), 33, 44, 55);
1127 ASSERT (result
!= NULL
);
1128 ASSERT (wcscmp (result
, L
"-inf 33") == 0
1129 || wcscmp (result
, L
"-infinity 33") == 0);
1130 ASSERT (length
== wcslen (result
));
1137 my_asnwprintf (NULL
, &length
, L
"%f %d", NaNd (), 33, 44, 55);
1138 ASSERT (result
!= NULL
);
1139 ASSERT (wcslen (result
) >= 3 + 3
1140 && wcsisnan (result
, 0, wcslen (result
) - 3, 0)
1141 && wcscmp (result
+ wcslen (result
) - 3, L
" 33") == 0);
1142 ASSERT (length
== wcslen (result
));
1146 { /* Signalling NaN. */
1149 my_asnwprintf (NULL
, &length
, L
"%f %d", SNaNd (), 33, 44, 55);
1150 ASSERT (result
!= NULL
);
1151 ASSERT (wcslen (result
) >= 3 + 3
1152 && wcsisnan (result
, 0, wcslen (result
) - 3, 0)
1153 && wcscmp (result
+ wcslen (result
) - 3, L
" 33") == 0);
1154 ASSERT (length
== wcslen (result
));
1162 my_asnwprintf (NULL
, &length
, L
"%10f %d", 1.75, 33, 44, 55);
1163 ASSERT (result
!= NULL
);
1164 ASSERT (wcscmp (result
, L
" 1.750000 33") == 0);
1165 ASSERT (length
== wcslen (result
));
1169 { /* Width given as argument. */
1172 my_asnwprintf (NULL
, &length
, L
"%*f %d", 10, 1.75, 33, 44, 55);
1173 ASSERT (result
!= NULL
);
1174 ASSERT (wcscmp (result
, L
" 1.750000 33") == 0);
1175 ASSERT (length
== wcslen (result
));
1179 { /* Negative width given as argument (cf. FLAG_LEFT below). */
1182 my_asnwprintf (NULL
, &length
, L
"%*f %d", -10, 1.75, 33, 44, 55);
1183 ASSERT (result
!= NULL
);
1184 ASSERT (wcscmp (result
, L
"1.750000 33") == 0);
1185 ASSERT (length
== wcslen (result
));
1192 my_asnwprintf (NULL
, &length
, L
"%-10f %d", 1.75, 33, 44, 55);
1193 ASSERT (result
!= NULL
);
1194 ASSERT (wcscmp (result
, L
"1.750000 33") == 0);
1195 ASSERT (length
== wcslen (result
));
1199 { /* FLAG_SHOWSIGN. */
1202 my_asnwprintf (NULL
, &length
, L
"%+f %d", 1.75, 33, 44, 55);
1203 ASSERT (result
!= NULL
);
1204 ASSERT (wcscmp (result
, L
"+1.750000 33") == 0);
1205 ASSERT (length
== wcslen (result
));
1212 my_asnwprintf (NULL
, &length
, L
"% f %d", 1.75, 33, 44, 55);
1213 ASSERT (result
!= NULL
);
1214 ASSERT (wcscmp (result
, L
" 1.750000 33") == 0);
1215 ASSERT (length
== wcslen (result
));
1222 my_asnwprintf (NULL
, &length
, L
"%#f %d", 1.75, 33, 44, 55);
1223 ASSERT (result
!= NULL
);
1224 ASSERT (wcscmp (result
, L
"1.750000 33") == 0);
1225 ASSERT (length
== wcslen (result
));
1232 my_asnwprintf (NULL
, &length
, L
"%#.f %d", 1.75, 33, 44, 55);
1233 ASSERT (result
!= NULL
);
1234 ASSERT (wcscmp (result
, L
"2. 33") == 0);
1235 ASSERT (length
== wcslen (result
));
1239 { /* FLAG_ZERO with finite number. */
1242 my_asnwprintf (NULL
, &length
, L
"%015f %d", 1234.0, 33, 44, 55);
1243 ASSERT (result
!= NULL
);
1244 ASSERT (wcscmp (result
, L
"00001234.000000 33") == 0);
1245 ASSERT (length
== wcslen (result
));
1249 { /* FLAG_ZERO with infinite number. */
1252 my_asnwprintf (NULL
, &length
, L
"%015f %d", - Infinityd (), 33, 44, 55);
1253 ASSERT (result
!= NULL
);
1254 ASSERT (wcscmp (result
, L
" -inf 33") == 0
1255 || wcscmp (result
, L
" -infinity 33") == 0);
1256 ASSERT (length
== wcslen (result
));
1260 { /* FLAG_ZERO with NaN. */
1263 my_asnwprintf (NULL
, &length
, L
"%050f %d", NaNd (), 33, 44, 55);
1264 ASSERT (result
!= NULL
);
1265 ASSERT (wcslen (result
) == 50 + 3
1266 && wcsisnan (result
, wcsspn (result
, L
" "), wcslen (result
) - 3, 0)
1267 && wcscmp (result
+ wcslen (result
) - 3, L
" 33") == 0);
1268 ASSERT (length
== wcslen (result
));
1275 my_asnwprintf (NULL
, &length
, L
"%.f %d", 1234.0, 33, 44, 55);
1276 ASSERT (result
!= NULL
);
1277 ASSERT (wcscmp (result
, L
"1234 33") == 0);
1278 ASSERT (length
== wcslen (result
));
1282 { /* Precision with no rounding. */
1285 my_asnwprintf (NULL
, &length
, L
"%.2f %d", 999.951, 33, 44, 55);
1286 ASSERT (result
!= NULL
);
1287 ASSERT (wcscmp (result
, L
"999.95 33") == 0);
1288 ASSERT (length
== wcslen (result
));
1292 { /* Precision with rounding. */
1295 my_asnwprintf (NULL
, &length
, L
"%.2f %d", 999.996, 33, 44, 55);
1296 ASSERT (result
!= NULL
);
1297 ASSERT (wcscmp (result
, L
"1000.00 33") == 0);
1298 ASSERT (length
== wcslen (result
));
1302 { /* A positive number. */
1305 my_asnwprintf (NULL
, &length
, L
"%Lf %d", 12.75L, 33, 44, 55);
1306 ASSERT (result
!= NULL
);
1307 ASSERT (wcscmp (result
, L
"12.750000 33") == 0);
1308 ASSERT (length
== wcslen (result
));
1312 { /* A larger positive number. */
1315 my_asnwprintf (NULL
, &length
, L
"%Lf %d", 1234567.0L, 33, 44, 55);
1316 ASSERT (result
!= NULL
);
1317 ASSERT (wcscmp (result
, L
"1234567.000000 33") == 0);
1318 ASSERT (length
== wcslen (result
));
1322 { /* Small and large positive numbers. */
1323 static struct { long double value
; const wchar_t *string
; } data
[] =
1325 { 1.234321234321234e-37L, L
"0.000000" },
1326 { 1.234321234321234e-36L, L
"0.000000" },
1327 { 1.234321234321234e-35L, L
"0.000000" },
1328 { 1.234321234321234e-34L, L
"0.000000" },
1329 { 1.234321234321234e-33L, L
"0.000000" },
1330 { 1.234321234321234e-32L, L
"0.000000" },
1331 { 1.234321234321234e-31L, L
"0.000000" },
1332 { 1.234321234321234e-30L, L
"0.000000" },
1333 { 1.234321234321234e-29L, L
"0.000000" },
1334 { 1.234321234321234e-28L, L
"0.000000" },
1335 { 1.234321234321234e-27L, L
"0.000000" },
1336 { 1.234321234321234e-26L, L
"0.000000" },
1337 { 1.234321234321234e-25L, L
"0.000000" },
1338 { 1.234321234321234e-24L, L
"0.000000" },
1339 { 1.234321234321234e-23L, L
"0.000000" },
1340 { 1.234321234321234e-22L, L
"0.000000" },
1341 { 1.234321234321234e-21L, L
"0.000000" },
1342 { 1.234321234321234e-20L, L
"0.000000" },
1343 { 1.234321234321234e-19L, L
"0.000000" },
1344 { 1.234321234321234e-18L, L
"0.000000" },
1345 { 1.234321234321234e-17L, L
"0.000000" },
1346 { 1.234321234321234e-16L, L
"0.000000" },
1347 { 1.234321234321234e-15L, L
"0.000000" },
1348 { 1.234321234321234e-14L, L
"0.000000" },
1349 { 1.234321234321234e-13L, L
"0.000000" },
1350 { 1.234321234321234e-12L, L
"0.000000" },
1351 { 1.234321234321234e-11L, L
"0.000000" },
1352 { 1.234321234321234e-10L, L
"0.000000" },
1353 { 1.234321234321234e-9L, L
"0.000000" },
1354 { 1.234321234321234e-8L, L
"0.000000" },
1355 { 1.234321234321234e-7L, L
"0.000000" },
1356 { 1.234321234321234e-6L, L
"0.000001" },
1357 { 1.234321234321234e-5L, L
"0.000012" },
1358 { 1.234321234321234e-4L, L
"0.000123" },
1359 { 1.234321234321234e-3L, L
"0.001234" },
1360 { 1.234321234321234e-2L, L
"0.012343" },
1361 { 1.234321234321234e-1L, L
"0.123432" },
1362 { 1.234321234321234L, L
"1.234321" },
1363 { 1.234321234321234e1L
, L
"12.343212" },
1364 { 1.234321234321234e2L
, L
"123.432123" },
1365 { 1.234321234321234e3L
, L
"1234.321234" },
1366 { 1.234321234321234e4L
, L
"12343.212343" },
1367 { 1.234321234321234e5L
, L
"123432.123432" },
1368 { 1.234321234321234e6L
, L
"1234321.234321" },
1369 { 1.234321234321234e7L
, L
"12343212.343212" },
1370 { 1.234321234321234e8L
, L
"123432123.432123" },
1371 { 1.234321234321234e9L
, L
"1234321234.321234" },
1372 { 1.234321234321234e10L
, L
"12343212343.2123**" },
1373 { 1.234321234321234e11L
, L
"123432123432.123***" },
1374 { 1.234321234321234e12L
, L
"1234321234321.23****" },
1375 { 1.234321234321234e13L
, L
"12343212343212.3*****" },
1376 { 1.234321234321234e14L
, L
"123432123432123.******" },
1377 { 1.234321234321234e15L
, L
"1234321234321234.000000" },
1378 { 1.234321234321234e16L
, L
"123432123432123**.000000" },
1379 { 1.234321234321234e17L
, L
"123432123432123***.000000" },
1380 { 1.234321234321234e18L
, L
"123432123432123****.000000" },
1381 { 1.234321234321234e19L
, L
"123432123432123*****.000000" },
1382 { 1.234321234321234e20L
, L
"123432123432123******.000000" },
1383 { 1.234321234321234e21L
, L
"123432123432123*******.000000" },
1384 { 1.234321234321234e22L
, L
"123432123432123********.000000" },
1385 { 1.234321234321234e23L
, L
"123432123432123*********.000000" },
1386 { 1.234321234321234e24L
, L
"123432123432123**********.000000" },
1387 { 1.234321234321234e25L
, L
"123432123432123***********.000000" },
1388 { 1.234321234321234e26L
, L
"123432123432123************.000000" },
1389 { 1.234321234321234e27L
, L
"123432123432123*************.000000" },
1390 { 1.234321234321234e28L
, L
"123432123432123**************.000000" },
1391 { 1.234321234321234e29L
, L
"123432123432123***************.000000" },
1392 { 1.234321234321234e30L
, L
"123432123432123****************.000000" },
1393 { 1.234321234321234e31L
, L
"123432123432123*****************.000000" },
1394 { 1.234321234321234e32L
, L
"123432123432123******************.000000" },
1395 { 1.234321234321234e33L
, L
"123432123432123*******************.000000" },
1396 { 1.234321234321234e34L
, L
"123432123432123********************.000000" },
1397 { 1.234321234321234e35L
, L
"123432123432123*********************.000000" },
1398 { 1.234321234321234e36L
, L
"123432123432123**********************.000000" }
1401 for (k
= 0; k
< SIZEOF (data
); k
++)
1405 my_asnwprintf (NULL
, &length
, L
"%Lf", data
[k
].value
);
1406 ASSERT (result
!= NULL
);
1407 ASSERT (wcsmatch (data
[k
].string
, result
));
1408 ASSERT (length
== wcslen (result
));
1413 { /* A negative number. */
1416 my_asnwprintf (NULL
, &length
, L
"%Lf %d", -0.03125L, 33, 44, 55);
1417 ASSERT (result
!= NULL
);
1418 ASSERT (wcscmp (result
, L
"-0.031250 33") == 0);
1419 ASSERT (length
== wcslen (result
));
1423 { /* Positive zero. */
1426 my_asnwprintf (NULL
, &length
, L
"%Lf %d", 0.0L, 33, 44, 55);
1427 ASSERT (result
!= NULL
);
1428 ASSERT (wcscmp (result
, L
"0.000000 33") == 0);
1429 ASSERT (length
== wcslen (result
));
1433 { /* Negative zero. */
1436 my_asnwprintf (NULL
, &length
, L
"%Lf %d", minus_zerol
, 33, 44, 55);
1437 ASSERT (result
!= NULL
);
1438 if (have_minus_zero ())
1439 ASSERT (wcscmp (result
, L
"-0.000000 33") == 0);
1440 ASSERT (length
== wcslen (result
));
1444 { /* Positive infinity. */
1447 my_asnwprintf (NULL
, &length
, L
"%Lf %d", Infinityl (), 33, 44, 55);
1448 ASSERT (result
!= NULL
);
1449 ASSERT (wcscmp (result
, L
"inf 33") == 0
1450 || wcscmp (result
, L
"infinity 33") == 0);
1451 ASSERT (length
== wcslen (result
));
1455 { /* Negative infinity. */
1458 my_asnwprintf (NULL
, &length
, L
"%Lf %d", - Infinityl (), 33, 44, 55);
1459 ASSERT (result
!= NULL
);
1460 ASSERT (wcscmp (result
, L
"-inf 33") == 0
1461 || wcscmp (result
, L
"-infinity 33") == 0);
1462 ASSERT (length
== wcslen (result
));
1469 my_asnwprintf (NULL
, &length
, L
"%Lf %d", NaNl (), 33, 44, 55);
1470 ASSERT (result
!= NULL
);
1471 ASSERT (wcslen (result
) >= 3 + 3
1472 && wcsisnan (result
, 0, wcslen (result
) - 3, 0)
1473 && wcscmp (result
+ wcslen (result
) - 3, L
" 33") == 0);
1474 ASSERT (length
== wcslen (result
));
1478 { /* Signalling NaN. */
1481 my_asnwprintf (NULL
, &length
, L
"%Lf %d", SNaNl (), 33, 44, 55);
1482 ASSERT (result
!= NULL
);
1483 ASSERT (wcslen (result
) >= 3 + 3
1484 && wcsisnan (result
, 0, wcslen (result
) - 3, 0)
1485 && wcscmp (result
+ wcslen (result
) - 3, L
" 33") == 0);
1486 ASSERT (length
== wcslen (result
));
1490 #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
1492 static union { unsigned int word
[4]; long double value
; } x
=
1493 { .word
= LDBL80_WORDS (0xFFFF, 0xC3333333, 0x00000000) };
1496 my_asnwprintf (NULL
, &length
, L
"%Lf %d", x
.value
, 33, 44, 55);
1497 ASSERT (result
!= NULL
);
1498 ASSERT (wcslen (result
) >= 3 + 3
1499 && wcsisnan (result
, 0, wcslen (result
) - 3, 0)
1500 && wcscmp (result
+ wcslen (result
) - 3, L
" 33") == 0);
1501 ASSERT (length
== wcslen (result
));
1505 /* Signalling NaN. */
1506 static union { unsigned int word
[4]; long double value
; } x
=
1507 { .word
= LDBL80_WORDS (0xFFFF, 0x83333333, 0x00000000) };
1510 my_asnwprintf (NULL
, &length
, L
"%Lf %d", x
.value
, 33, 44, 55);
1511 ASSERT (result
!= NULL
);
1512 ASSERT (wcslen (result
) >= 3 + 3
1513 && wcsisnan (result
, 0, wcslen (result
) - 3, 0)
1514 && wcscmp (result
+ wcslen (result
) - 3, L
" 33") == 0);
1515 ASSERT (length
== wcslen (result
));
1518 /* asnwprintf should print something for noncanonical values. */
1520 static union { unsigned int word
[4]; long double value
; } x
=
1521 { .word
= LDBL80_WORDS (0xFFFF, 0x40000001, 0x00000000) };
1524 my_asnwprintf (NULL
, &length
, L
"%Lf %d", x
.value
, 33, 44, 55);
1525 ASSERT (result
!= NULL
);
1526 ASSERT (length
== wcslen (result
));
1527 ASSERT (3 < length
&& wcscmp (result
+ length
- 3, L
" 33") == 0);
1530 { /* Pseudo-Infinity. */
1531 static union { unsigned int word
[4]; long double value
; } x
=
1532 { .word
= LDBL80_WORDS (0xFFFF, 0x00000000, 0x00000000) };
1535 my_asnwprintf (NULL
, &length
, L
"%Lf %d", x
.value
, 33, 44, 55);
1536 ASSERT (result
!= NULL
);
1537 ASSERT (length
== wcslen (result
));
1538 ASSERT (3 < length
&& wcscmp (result
+ length
- 3, L
" 33") == 0);
1541 { /* Pseudo-Zero. */
1542 static union { unsigned int word
[4]; long double value
; } x
=
1543 { .word
= LDBL80_WORDS (0x4004, 0x00000000, 0x00000000) };
1546 my_asnwprintf (NULL
, &length
, L
"%Lf %d", x
.value
, 33, 44, 55);
1547 ASSERT (result
!= NULL
);
1548 ASSERT (length
== wcslen (result
));
1549 ASSERT (3 < length
&& wcscmp (result
+ length
- 3, L
" 33") == 0);
1552 { /* Unnormalized number. */
1553 static union { unsigned int word
[4]; long double value
; } x
=
1554 { .word
= LDBL80_WORDS (0x4000, 0x63333333, 0x00000000) };
1557 my_asnwprintf (NULL
, &length
, L
"%Lf %d", x
.value
, 33, 44, 55);
1558 ASSERT (result
!= NULL
);
1559 ASSERT (length
== wcslen (result
));
1560 ASSERT (3 < length
&& wcscmp (result
+ length
- 3, L
" 33") == 0);
1563 { /* Pseudo-Denormal. */
1564 static union { unsigned int word
[4]; long double value
; } x
=
1565 { .word
= LDBL80_WORDS (0x0000, 0x83333333, 0x00000000) };
1568 my_asnwprintf (NULL
, &length
, L
"%Lf %d", x
.value
, 33, 44, 55);
1569 ASSERT (result
!= NULL
);
1570 ASSERT (length
== wcslen (result
));
1571 ASSERT (3 < length
&& wcscmp (result
+ length
- 3, L
" 33") == 0);
1579 my_asnwprintf (NULL
, &length
, L
"%10Lf %d", 1.75L, 33, 44, 55);
1580 ASSERT (result
!= NULL
);
1581 ASSERT (wcscmp (result
, L
" 1.750000 33") == 0);
1582 ASSERT (length
== wcslen (result
));
1586 { /* Width given as argument. */
1589 my_asnwprintf (NULL
, &length
, L
"%*Lf %d", 10, 1.75L, 33, 44, 55);
1590 ASSERT (result
!= NULL
);
1591 ASSERT (wcscmp (result
, L
" 1.750000 33") == 0);
1592 ASSERT (length
== wcslen (result
));
1596 { /* Negative width given as argument (cf. FLAG_LEFT below). */
1599 my_asnwprintf (NULL
, &length
, L
"%*Lf %d", -10, 1.75L, 33, 44, 55);
1600 ASSERT (result
!= NULL
);
1601 ASSERT (wcscmp (result
, L
"1.750000 33") == 0);
1602 ASSERT (length
== wcslen (result
));
1609 my_asnwprintf (NULL
, &length
, L
"%-10Lf %d", 1.75L, 33, 44, 55);
1610 ASSERT (result
!= NULL
);
1611 ASSERT (wcscmp (result
, L
"1.750000 33") == 0);
1612 ASSERT (length
== wcslen (result
));
1616 { /* FLAG_SHOWSIGN. */
1619 my_asnwprintf (NULL
, &length
, L
"%+Lf %d", 1.75L, 33, 44, 55);
1620 ASSERT (result
!= NULL
);
1621 ASSERT (wcscmp (result
, L
"+1.750000 33") == 0);
1622 ASSERT (length
== wcslen (result
));
1629 my_asnwprintf (NULL
, &length
, L
"% Lf %d", 1.75L, 33, 44, 55);
1630 ASSERT (result
!= NULL
);
1631 ASSERT (wcscmp (result
, L
" 1.750000 33") == 0);
1632 ASSERT (length
== wcslen (result
));
1639 my_asnwprintf (NULL
, &length
, L
"%#Lf %d", 1.75L, 33, 44, 55);
1640 ASSERT (result
!= NULL
);
1641 ASSERT (wcscmp (result
, L
"1.750000 33") == 0);
1642 ASSERT (length
== wcslen (result
));
1649 my_asnwprintf (NULL
, &length
, L
"%#.Lf %d", 1.75L, 33, 44, 55);
1650 ASSERT (result
!= NULL
);
1651 ASSERT (wcscmp (result
, L
"2. 33") == 0);
1652 ASSERT (length
== wcslen (result
));
1656 { /* FLAG_ZERO with finite number. */
1659 my_asnwprintf (NULL
, &length
, L
"%015Lf %d", 1234.0L, 33, 44, 55);
1660 ASSERT (result
!= NULL
);
1661 ASSERT (wcscmp (result
, L
"00001234.000000 33") == 0);
1662 ASSERT (length
== wcslen (result
));
1666 { /* FLAG_ZERO with infinite number. */
1669 my_asnwprintf (NULL
, &length
, L
"%015Lf %d", - Infinityl (), 33, 44, 55);
1670 ASSERT (result
!= NULL
);
1671 ASSERT (wcscmp (result
, L
" -inf 33") == 0
1672 || wcscmp (result
, L
" -infinity 33") == 0);
1673 ASSERT (length
== wcslen (result
));
1677 { /* FLAG_ZERO with NaN. */
1680 my_asnwprintf (NULL
, &length
, L
"%050Lf %d", NaNl (), 33, 44, 55);
1681 ASSERT (result
!= NULL
);
1682 ASSERT (wcslen (result
) == 50 + 3
1683 && wcsisnan (result
, wcsspn (result
, L
" "), wcslen (result
) - 3, 0)
1684 && wcscmp (result
+ wcslen (result
) - 3, L
" 33") == 0);
1685 ASSERT (length
== wcslen (result
));
1692 my_asnwprintf (NULL
, &length
, L
"%.Lf %d", 1234.0L, 33, 44, 55);
1693 ASSERT (result
!= NULL
);
1694 ASSERT (wcscmp (result
, L
"1234 33") == 0);
1695 ASSERT (length
== wcslen (result
));
1699 { /* Precision with no rounding. */
1702 my_asnwprintf (NULL
, &length
, L
"%.2Lf %d", 999.951L, 33, 44, 55);
1703 ASSERT (result
!= NULL
);
1704 ASSERT (wcscmp (result
, L
"999.95 33") == 0);
1705 ASSERT (length
== wcslen (result
));
1709 { /* Precision with rounding. */
1712 my_asnwprintf (NULL
, &length
, L
"%.2Lf %d", 999.996L, 33, 44, 55);
1713 ASSERT (result
!= NULL
);
1714 ASSERT (wcscmp (result
, L
"1000.00 33") == 0);
1715 ASSERT (length
== wcslen (result
));
1719 /* Test the support of the %F format directive. */
1721 { /* A positive number. */
1724 my_asnwprintf (NULL
, &length
, L
"%F %d", 12.75, 33, 44, 55);
1725 ASSERT (result
!= NULL
);
1726 ASSERT (wcscmp (result
, L
"12.750000 33") == 0);
1727 ASSERT (length
== wcslen (result
));
1731 { /* A larger positive number. */
1734 my_asnwprintf (NULL
, &length
, L
"%F %d", 1234567.0, 33, 44, 55);
1735 ASSERT (result
!= NULL
);
1736 ASSERT (wcscmp (result
, L
"1234567.000000 33") == 0);
1737 ASSERT (length
== wcslen (result
));
1741 { /* A negative number. */
1744 my_asnwprintf (NULL
, &length
, L
"%F %d", -0.03125, 33, 44, 55);
1745 ASSERT (result
!= NULL
);
1746 ASSERT (wcscmp (result
, L
"-0.031250 33") == 0);
1747 ASSERT (length
== wcslen (result
));
1751 { /* Positive zero. */
1754 my_asnwprintf (NULL
, &length
, L
"%F %d", 0.0, 33, 44, 55);
1755 ASSERT (result
!= NULL
);
1756 ASSERT (wcscmp (result
, L
"0.000000 33") == 0);
1757 ASSERT (length
== wcslen (result
));
1761 { /* Negative zero. */
1764 my_asnwprintf (NULL
, &length
, L
"%F %d", minus_zerod
, 33, 44, 55);
1765 ASSERT (result
!= NULL
);
1766 if (have_minus_zero ())
1767 ASSERT (wcscmp (result
, L
"-0.000000 33") == 0);
1768 ASSERT (length
== wcslen (result
));
1772 { /* Positive infinity. */
1775 my_asnwprintf (NULL
, &length
, L
"%F %d", Infinityd (), 33, 44, 55);
1776 ASSERT (result
!= NULL
);
1777 ASSERT (wcscmp (result
, L
"INF 33") == 0
1778 || wcscmp (result
, L
"INFINITY 33") == 0);
1779 ASSERT (length
== wcslen (result
));
1783 { /* Negative infinity. */
1786 my_asnwprintf (NULL
, &length
, L
"%F %d", - Infinityd (), 33, 44, 55);
1787 ASSERT (result
!= NULL
);
1788 ASSERT (wcscmp (result
, L
"-INF 33") == 0
1789 || wcscmp (result
, L
"-INFINITY 33") == 0);
1790 ASSERT (length
== wcslen (result
));
1797 my_asnwprintf (NULL
, &length
, L
"%F %d", NaNd (), 33, 44, 55);
1798 ASSERT (result
!= NULL
);
1799 ASSERT (wcslen (result
) >= 3 + 3
1800 && wcsisnan (result
, 0, wcslen (result
) - 3, 1)
1801 && wcscmp (result
+ wcslen (result
) - 3, L
" 33") == 0);
1802 ASSERT (length
== wcslen (result
));
1806 { /* Signalling NaN. */
1809 my_asnwprintf (NULL
, &length
, L
"%F %d", SNaNd (), 33, 44, 55);
1810 ASSERT (result
!= NULL
);
1811 ASSERT (wcslen (result
) >= 3 + 3
1812 && wcsisnan (result
, 0, wcslen (result
) - 3, 1)
1813 && wcscmp (result
+ wcslen (result
) - 3, L
" 33") == 0);
1814 ASSERT (length
== wcslen (result
));
1822 my_asnwprintf (NULL
, &length
, L
"%015F %d", 1234.0, 33, 44, 55);
1823 ASSERT (result
!= NULL
);
1824 ASSERT (wcscmp (result
, L
"00001234.000000 33") == 0);
1825 ASSERT (length
== wcslen (result
));
1829 { /* FLAG_ZERO with infinite number. */
1832 my_asnwprintf (NULL
, &length
, L
"%015F %d", - Infinityd (), 33, 44, 55);
1833 ASSERT (result
!= NULL
);
1834 ASSERT (wcscmp (result
, L
" -INF 33") == 0
1835 || wcscmp (result
, L
" -INFINITY 33") == 0);
1836 ASSERT (length
== wcslen (result
));
1843 my_asnwprintf (NULL
, &length
, L
"%.F %d", 1234.0, 33, 44, 55);
1844 ASSERT (result
!= NULL
);
1845 ASSERT (wcscmp (result
, L
"1234 33") == 0);
1846 ASSERT (length
== wcslen (result
));
1850 { /* Precision with no rounding. */
1853 my_asnwprintf (NULL
, &length
, L
"%.2F %d", 999.951, 33, 44, 55);
1854 ASSERT (result
!= NULL
);
1855 ASSERT (wcscmp (result
, L
"999.95 33") == 0);
1856 ASSERT (length
== wcslen (result
));
1860 { /* Precision with rounding. */
1863 my_asnwprintf (NULL
, &length
, L
"%.2F %d", 999.996, 33, 44, 55);
1864 ASSERT (result
!= NULL
);
1865 ASSERT (wcscmp (result
, L
"1000.00 33") == 0);
1866 ASSERT (length
== wcslen (result
));
1870 { /* A positive number. */
1873 my_asnwprintf (NULL
, &length
, L
"%LF %d", 12.75L, 33, 44, 55);
1874 ASSERT (result
!= NULL
);
1875 ASSERT (wcscmp (result
, L
"12.750000 33") == 0);
1876 ASSERT (length
== wcslen (result
));
1880 { /* A larger positive number. */
1883 my_asnwprintf (NULL
, &length
, L
"%LF %d", 1234567.0L, 33, 44, 55);
1884 ASSERT (result
!= NULL
);
1885 ASSERT (wcscmp (result
, L
"1234567.000000 33") == 0);
1886 ASSERT (length
== wcslen (result
));
1890 { /* A negative number. */
1893 my_asnwprintf (NULL
, &length
, L
"%LF %d", -0.03125L, 33, 44, 55);
1894 ASSERT (result
!= NULL
);
1895 ASSERT (wcscmp (result
, L
"-0.031250 33") == 0);
1896 ASSERT (length
== wcslen (result
));
1900 { /* Positive zero. */
1903 my_asnwprintf (NULL
, &length
, L
"%LF %d", 0.0L, 33, 44, 55);
1904 ASSERT (result
!= NULL
);
1905 ASSERT (wcscmp (result
, L
"0.000000 33") == 0);
1906 ASSERT (length
== wcslen (result
));
1910 { /* Negative zero. */
1913 my_asnwprintf (NULL
, &length
, L
"%LF %d", minus_zerol
, 33, 44, 55);
1914 ASSERT (result
!= NULL
);
1915 if (have_minus_zero ())
1916 ASSERT (wcscmp (result
, L
"-0.000000 33") == 0);
1917 ASSERT (length
== wcslen (result
));
1921 { /* Positive infinity. */
1924 my_asnwprintf (NULL
, &length
, L
"%LF %d", Infinityl (), 33, 44, 55);
1925 ASSERT (result
!= NULL
);
1926 ASSERT (wcscmp (result
, L
"INF 33") == 0
1927 || wcscmp (result
, L
"INFINITY 33") == 0);
1928 ASSERT (length
== wcslen (result
));
1932 { /* Negative infinity. */
1935 my_asnwprintf (NULL
, &length
, L
"%LF %d", - Infinityl (), 33, 44, 55);
1936 ASSERT (result
!= NULL
);
1937 ASSERT (wcscmp (result
, L
"-INF 33") == 0
1938 || wcscmp (result
, L
"-INFINITY 33") == 0);
1939 ASSERT (length
== wcslen (result
));
1946 my_asnwprintf (NULL
, &length
, L
"%LF %d", NaNl (), 33, 44, 55);
1947 ASSERT (result
!= NULL
);
1948 ASSERT (wcslen (result
) >= 3 + 3
1949 && wcsisnan (result
, 0, wcslen (result
) - 3, 1)
1950 && wcscmp (result
+ wcslen (result
) - 3, L
" 33") == 0);
1951 ASSERT (length
== wcslen (result
));
1955 { /* Signalling NaN. */
1958 my_asnwprintf (NULL
, &length
, L
"%LF %d", SNaNl (), 33, 44, 55);
1959 ASSERT (result
!= NULL
);
1960 ASSERT (wcslen (result
) >= 3 + 3
1961 && wcsisnan (result
, 0, wcslen (result
) - 3, 1)
1962 && wcscmp (result
+ wcslen (result
) - 3, L
" 33") == 0);
1963 ASSERT (length
== wcslen (result
));
1971 my_asnwprintf (NULL
, &length
, L
"%015LF %d", 1234.0L, 33, 44, 55);
1972 ASSERT (result
!= NULL
);
1973 ASSERT (wcscmp (result
, L
"00001234.000000 33") == 0);
1974 ASSERT (length
== wcslen (result
));
1978 { /* FLAG_ZERO with infinite number. */
1981 my_asnwprintf (NULL
, &length
, L
"%015LF %d", - Infinityl (), 33, 44, 55);
1982 ASSERT (result
!= NULL
);
1983 ASSERT (wcscmp (result
, L
" -INF 33") == 0
1984 || wcscmp (result
, L
" -INFINITY 33") == 0);
1985 ASSERT (length
== wcslen (result
));
1992 my_asnwprintf (NULL
, &length
, L
"%.LF %d", 1234.0L, 33, 44, 55);
1993 ASSERT (result
!= NULL
);
1994 ASSERT (wcscmp (result
, L
"1234 33") == 0);
1995 ASSERT (length
== wcslen (result
));
1999 { /* Precision with no rounding. */
2002 my_asnwprintf (NULL
, &length
, L
"%.2LF %d", 999.951L, 33, 44, 55);
2003 ASSERT (result
!= NULL
);
2004 ASSERT (wcscmp (result
, L
"999.95 33") == 0);
2005 ASSERT (length
== wcslen (result
));
2009 { /* Precision with rounding. */
2012 my_asnwprintf (NULL
, &length
, L
"%.2LF %d", 999.996L, 33, 44, 55);
2013 ASSERT (result
!= NULL
);
2014 ASSERT (wcscmp (result
, L
"1000.00 33") == 0);
2015 ASSERT (length
== wcslen (result
));
2019 /* Test the support of the %e format directive. */
2021 { /* A positive number. */
2024 my_asnwprintf (NULL
, &length
, L
"%e %d", 12.75, 33, 44, 55);
2025 ASSERT (result
!= NULL
);
2026 ASSERT (wcscmp (result
, L
"1.275000e+01 33") == 0
2027 || wcscmp (result
, L
"1.275000e+001 33") == 0);
2028 ASSERT (length
== wcslen (result
));
2032 { /* A larger positive number. */
2035 my_asnwprintf (NULL
, &length
, L
"%e %d", 1234567.0, 33, 44, 55);
2036 ASSERT (result
!= NULL
);
2037 ASSERT (wcscmp (result
, L
"1.234567e+06 33") == 0
2038 || wcscmp (result
, L
"1.234567e+006 33") == 0);
2039 ASSERT (length
== wcslen (result
));
2043 { /* Small and large positive numbers. */
2044 static struct { double value
; const wchar_t *string
; } data
[] =
2046 { 1.234321234321234e-37, L
"1.234321e-37" },
2047 { 1.234321234321234e-36, L
"1.234321e-36" },
2048 { 1.234321234321234e-35, L
"1.234321e-35" },
2049 { 1.234321234321234e-34, L
"1.234321e-34" },
2050 { 1.234321234321234e-33, L
"1.234321e-33" },
2051 { 1.234321234321234e-32, L
"1.234321e-32" },
2052 { 1.234321234321234e-31, L
"1.234321e-31" },
2053 { 1.234321234321234e-30, L
"1.234321e-30" },
2054 { 1.234321234321234e-29, L
"1.234321e-29" },
2055 { 1.234321234321234e-28, L
"1.234321e-28" },
2056 { 1.234321234321234e-27, L
"1.234321e-27" },
2057 { 1.234321234321234e-26, L
"1.234321e-26" },
2058 { 1.234321234321234e-25, L
"1.234321e-25" },
2059 { 1.234321234321234e-24, L
"1.234321e-24" },
2060 { 1.234321234321234e-23, L
"1.234321e-23" },
2061 { 1.234321234321234e-22, L
"1.234321e-22" },
2062 { 1.234321234321234e-21, L
"1.234321e-21" },
2063 { 1.234321234321234e-20, L
"1.234321e-20" },
2064 { 1.234321234321234e-19, L
"1.234321e-19" },
2065 { 1.234321234321234e-18, L
"1.234321e-18" },
2066 { 1.234321234321234e-17, L
"1.234321e-17" },
2067 { 1.234321234321234e-16, L
"1.234321e-16" },
2068 { 1.234321234321234e-15, L
"1.234321e-15" },
2069 { 1.234321234321234e-14, L
"1.234321e-14" },
2070 { 1.234321234321234e-13, L
"1.234321e-13" },
2071 { 1.234321234321234e-12, L
"1.234321e-12" },
2072 { 1.234321234321234e-11, L
"1.234321e-11" },
2073 { 1.234321234321234e-10, L
"1.234321e-10" },
2074 { 1.234321234321234e-9, L
"1.234321e-09" },
2075 { 1.234321234321234e-8, L
"1.234321e-08" },
2076 { 1.234321234321234e-7, L
"1.234321e-07" },
2077 { 1.234321234321234e-6, L
"1.234321e-06" },
2078 { 1.234321234321234e-5, L
"1.234321e-05" },
2079 { 1.234321234321234e-4, L
"1.234321e-04" },
2080 { 1.234321234321234e-3, L
"1.234321e-03" },
2081 { 1.234321234321234e-2, L
"1.234321e-02" },
2082 { 1.234321234321234e-1, L
"1.234321e-01" },
2083 { 1.234321234321234, L
"1.234321e+00" },
2084 { 1.234321234321234e1
, L
"1.234321e+01" },
2085 { 1.234321234321234e2
, L
"1.234321e+02" },
2086 { 1.234321234321234e3
, L
"1.234321e+03" },
2087 { 1.234321234321234e4
, L
"1.234321e+04" },
2088 { 1.234321234321234e5
, L
"1.234321e+05" },
2089 { 1.234321234321234e6
, L
"1.234321e+06" },
2090 { 1.234321234321234e7
, L
"1.234321e+07" },
2091 { 1.234321234321234e8
, L
"1.234321e+08" },
2092 { 1.234321234321234e9
, L
"1.234321e+09" },
2093 { 1.234321234321234e10
, L
"1.234321e+10" },
2094 { 1.234321234321234e11
, L
"1.234321e+11" },
2095 { 1.234321234321234e12
, L
"1.234321e+12" },
2096 { 1.234321234321234e13
, L
"1.234321e+13" },
2097 { 1.234321234321234e14
, L
"1.234321e+14" },
2098 { 1.234321234321234e15
, L
"1.234321e+15" },
2099 { 1.234321234321234e16
, L
"1.234321e+16" },
2100 { 1.234321234321234e17
, L
"1.234321e+17" },
2101 { 1.234321234321234e18
, L
"1.234321e+18" },
2102 { 1.234321234321234e19
, L
"1.234321e+19" },
2103 { 1.234321234321234e20
, L
"1.234321e+20" },
2104 { 1.234321234321234e21
, L
"1.234321e+21" },
2105 { 1.234321234321234e22
, L
"1.234321e+22" },
2106 { 1.234321234321234e23
, L
"1.234321e+23" },
2107 { 1.234321234321234e24
, L
"1.234321e+24" },
2108 { 1.234321234321234e25
, L
"1.234321e+25" },
2109 { 1.234321234321234e26
, L
"1.234321e+26" },
2110 { 1.234321234321234e27
, L
"1.234321e+27" },
2111 { 1.234321234321234e28
, L
"1.234321e+28" },
2112 { 1.234321234321234e29
, L
"1.234321e+29" },
2113 { 1.234321234321234e30
, L
"1.234321e+30" },
2114 { 1.234321234321234e31
, L
"1.234321e+31" },
2115 { 1.234321234321234e32
, L
"1.234321e+32" },
2116 { 1.234321234321234e33
, L
"1.234321e+33" },
2117 { 1.234321234321234e34
, L
"1.234321e+34" },
2118 { 1.234321234321234e35
, L
"1.234321e+35" },
2119 { 1.234321234321234e36
, L
"1.234321e+36" }
2122 for (k
= 0; k
< SIZEOF (data
); k
++)
2126 my_asnwprintf (NULL
, &length
, L
"%e", data
[k
].value
);
2127 const wchar_t *expected
= data
[k
].string
;
2128 ASSERT (result
!= NULL
);
2129 ASSERT (wcscmp (result
, expected
) == 0
2130 /* Some implementations produce exponents with 3 digits. */
2131 || (wcslen (result
) == wcslen (expected
) + 1
2132 && wmemcmp (result
, expected
, wcslen (expected
) - 2) == 0
2133 && result
[wcslen (expected
) - 2] == '0'
2134 && wcscmp (result
+ wcslen (expected
) - 1,
2135 expected
+ wcslen (expected
) - 2)
2137 ASSERT (length
== wcslen (result
));
2142 { /* A negative number. */
2145 my_asnwprintf (NULL
, &length
, L
"%e %d", -0.03125, 33, 44, 55);
2146 ASSERT (result
!= NULL
);
2147 ASSERT (wcscmp (result
, L
"-3.125000e-02 33") == 0
2148 || wcscmp (result
, L
"-3.125000e-002 33") == 0);
2149 ASSERT (length
== wcslen (result
));
2153 { /* Positive zero. */
2156 my_asnwprintf (NULL
, &length
, L
"%e %d", 0.0, 33, 44, 55);
2157 ASSERT (result
!= NULL
);
2158 ASSERT (wcscmp (result
, L
"0.000000e+00 33") == 0
2159 || wcscmp (result
, L
"0.000000e+000 33") == 0);
2160 ASSERT (length
== wcslen (result
));
2164 { /* Negative zero. */
2167 my_asnwprintf (NULL
, &length
, L
"%e %d", minus_zerod
, 33, 44, 55);
2168 ASSERT (result
!= NULL
);
2169 if (have_minus_zero ())
2170 ASSERT (wcscmp (result
, L
"-0.000000e+00 33") == 0
2171 || wcscmp (result
, L
"-0.000000e+000 33") == 0);
2172 ASSERT (length
== wcslen (result
));
2176 { /* Positive infinity. */
2179 my_asnwprintf (NULL
, &length
, L
"%e %d", Infinityd (), 33, 44, 55);
2180 ASSERT (result
!= NULL
);
2181 ASSERT (wcscmp (result
, L
"inf 33") == 0
2182 || wcscmp (result
, L
"infinity 33") == 0);
2183 ASSERT (length
== wcslen (result
));
2187 { /* Negative infinity. */
2190 my_asnwprintf (NULL
, &length
, L
"%e %d", - Infinityd (), 33, 44, 55);
2191 ASSERT (result
!= NULL
);
2192 ASSERT (wcscmp (result
, L
"-inf 33") == 0
2193 || wcscmp (result
, L
"-infinity 33") == 0);
2194 ASSERT (length
== wcslen (result
));
2201 my_asnwprintf (NULL
, &length
, L
"%e %d", NaNd (), 33, 44, 55);
2202 ASSERT (result
!= NULL
);
2203 ASSERT (wcslen (result
) >= 3 + 3
2204 && wcsisnan (result
, 0, wcslen (result
) - 3, 0)
2205 && wcscmp (result
+ wcslen (result
) - 3, L
" 33") == 0);
2206 ASSERT (length
== wcslen (result
));
2210 { /* Signalling NaN. */
2213 my_asnwprintf (NULL
, &length
, L
"%e %d", SNaNd (), 33, 44, 55);
2214 ASSERT (result
!= NULL
);
2215 ASSERT (wcslen (result
) >= 3 + 3
2216 && wcsisnan (result
, 0, wcslen (result
) - 3, 0)
2217 && wcscmp (result
+ wcslen (result
) - 3, L
" 33") == 0);
2218 ASSERT (length
== wcslen (result
));
2226 my_asnwprintf (NULL
, &length
, L
"%15e %d", 1.75, 33, 44, 55);
2227 ASSERT (result
!= NULL
);
2228 ASSERT (wcscmp (result
, L
" 1.750000e+00 33") == 0
2229 || wcscmp (result
, L
" 1.750000e+000 33") == 0);
2230 ASSERT (length
== wcslen (result
));
2234 { /* Width given as argument. */
2237 my_asnwprintf (NULL
, &length
, L
"%*e %d", 15, 1.75, 33, 44, 55);
2238 ASSERT (result
!= NULL
);
2239 ASSERT (wcscmp (result
, L
" 1.750000e+00 33") == 0
2240 || wcscmp (result
, L
" 1.750000e+000 33") == 0);
2241 ASSERT (length
== wcslen (result
));
2245 { /* Negative width given as argument (cf. FLAG_LEFT below). */
2248 my_asnwprintf (NULL
, &length
, L
"%*e %d", -15, 1.75, 33, 44, 55);
2249 ASSERT (result
!= NULL
);
2250 ASSERT (wcscmp (result
, L
"1.750000e+00 33") == 0
2251 || wcscmp (result
, L
"1.750000e+000 33") == 0);
2252 ASSERT (length
== wcslen (result
));
2259 my_asnwprintf (NULL
, &length
, L
"%-15e %d", 1.75, 33, 44, 55);
2260 ASSERT (result
!= NULL
);
2261 ASSERT (wcscmp (result
, L
"1.750000e+00 33") == 0
2262 || wcscmp (result
, L
"1.750000e+000 33") == 0);
2263 ASSERT (length
== wcslen (result
));
2267 { /* FLAG_SHOWSIGN. */
2270 my_asnwprintf (NULL
, &length
, L
"%+e %d", 1.75, 33, 44, 55);
2271 ASSERT (result
!= NULL
);
2272 ASSERT (wcscmp (result
, L
"+1.750000e+00 33") == 0
2273 || wcscmp (result
, L
"+1.750000e+000 33") == 0);
2274 ASSERT (length
== wcslen (result
));
2281 my_asnwprintf (NULL
, &length
, L
"% e %d", 1.75, 33, 44, 55);
2282 ASSERT (result
!= NULL
);
2283 ASSERT (wcscmp (result
, L
" 1.750000e+00 33") == 0
2284 || wcscmp (result
, L
" 1.750000e+000 33") == 0);
2285 ASSERT (length
== wcslen (result
));
2292 my_asnwprintf (NULL
, &length
, L
"%#e %d", 1.75, 33, 44, 55);
2293 ASSERT (result
!= NULL
);
2294 ASSERT (wcscmp (result
, L
"1.750000e+00 33") == 0
2295 || wcscmp (result
, L
"1.750000e+000 33") == 0);
2296 ASSERT (length
== wcslen (result
));
2303 my_asnwprintf (NULL
, &length
, L
"%#.e %d", 1.75, 33, 44, 55);
2304 ASSERT (result
!= NULL
);
2305 ASSERT (wcscmp (result
, L
"2.e+00 33") == 0
2306 || wcscmp (result
, L
"2.e+000 33") == 0);
2307 ASSERT (length
== wcslen (result
));
2314 my_asnwprintf (NULL
, &length
, L
"%#.e %d", 9.75, 33, 44, 55);
2315 ASSERT (result
!= NULL
);
2316 ASSERT (wcscmp (result
, L
"1.e+01 33") == 0
2317 || wcscmp (result
, L
"1.e+001 33") == 0);
2318 ASSERT (length
== wcslen (result
));
2322 { /* FLAG_ZERO with finite number. */
2325 my_asnwprintf (NULL
, &length
, L
"%015e %d", 1234.0, 33, 44, 55);
2326 ASSERT (result
!= NULL
);
2327 ASSERT (wcscmp (result
, L
"0001.234000e+03 33") == 0
2328 || wcscmp (result
, L
"001.234000e+003 33") == 0);
2329 ASSERT (length
== wcslen (result
));
2333 { /* FLAG_ZERO with infinite number. */
2336 my_asnwprintf (NULL
, &length
, L
"%015e %d", - Infinityd (), 33, 44, 55);
2337 ASSERT (result
!= NULL
);
2338 ASSERT (wcscmp (result
, L
" -inf 33") == 0
2339 || wcscmp (result
, L
" -infinity 33") == 0);
2340 ASSERT (length
== wcslen (result
));
2344 { /* FLAG_ZERO with NaN. */
2347 my_asnwprintf (NULL
, &length
, L
"%050e %d", NaNd (), 33, 44, 55);
2348 ASSERT (result
!= NULL
);
2349 ASSERT (wcslen (result
) == 50 + 3
2350 && wcsisnan (result
, wcsspn (result
, L
" "), wcslen (result
) - 3, 0)
2351 && wcscmp (result
+ wcslen (result
) - 3, L
" 33") == 0);
2352 ASSERT (length
== wcslen (result
));
2359 my_asnwprintf (NULL
, &length
, L
"%.e %d", 1234.0, 33, 44, 55);
2360 ASSERT (result
!= NULL
);
2361 ASSERT (wcscmp (result
, L
"1e+03 33") == 0
2362 || wcscmp (result
, L
"1e+003 33") == 0);
2363 ASSERT (length
== wcslen (result
));
2367 { /* Precision with no rounding. */
2370 my_asnwprintf (NULL
, &length
, L
"%.4e %d", 999.951, 33, 44, 55);
2371 ASSERT (result
!= NULL
);
2372 ASSERT (wcscmp (result
, L
"9.9995e+02 33") == 0
2373 || wcscmp (result
, L
"9.9995e+002 33") == 0);
2374 ASSERT (length
== wcslen (result
));
2378 { /* Precision with rounding. */
2381 my_asnwprintf (NULL
, &length
, L
"%.4e %d", 999.996, 33, 44, 55);
2382 ASSERT (result
!= NULL
);
2383 ASSERT (wcscmp (result
, L
"1.0000e+03 33") == 0
2384 || wcscmp (result
, L
"1.0000e+003 33") == 0);
2385 ASSERT (length
== wcslen (result
));
2389 { /* A positive number. */
2392 my_asnwprintf (NULL
, &length
, L
"%Le %d", 12.75L, 33, 44, 55);
2393 ASSERT (result
!= NULL
);
2394 ASSERT (wcscmp (result
, L
"1.275000e+01 33") == 0
2395 || wcscmp (result
, L
"1.275000e+001 33") == 0);
2396 ASSERT (length
== wcslen (result
));
2400 { /* A larger positive number. */
2403 my_asnwprintf (NULL
, &length
, L
"%Le %d", 1234567.0L, 33, 44, 55);
2404 ASSERT (result
!= NULL
);
2405 ASSERT (wcscmp (result
, L
"1.234567e+06 33") == 0
2406 || wcscmp (result
, L
"1.234567e+006 33") == 0);
2407 ASSERT (length
== wcslen (result
));
2411 { /* Small and large positive numbers. */
2412 static struct { long double value
; const wchar_t *string
; } data
[] =
2414 { 1.234321234321234e-37L, L
"1.234321e-37" },
2415 { 1.234321234321234e-36L, L
"1.234321e-36" },
2416 { 1.234321234321234e-35L, L
"1.234321e-35" },
2417 { 1.234321234321234e-34L, L
"1.234321e-34" },
2418 { 1.234321234321234e-33L, L
"1.234321e-33" },
2419 { 1.234321234321234e-32L, L
"1.234321e-32" },
2420 { 1.234321234321234e-31L, L
"1.234321e-31" },
2421 { 1.234321234321234e-30L, L
"1.234321e-30" },
2422 { 1.234321234321234e-29L, L
"1.234321e-29" },
2423 { 1.234321234321234e-28L, L
"1.234321e-28" },
2424 { 1.234321234321234e-27L, L
"1.234321e-27" },
2425 { 1.234321234321234e-26L, L
"1.234321e-26" },
2426 { 1.234321234321234e-25L, L
"1.234321e-25" },
2427 { 1.234321234321234e-24L, L
"1.234321e-24" },
2428 { 1.234321234321234e-23L, L
"1.234321e-23" },
2429 { 1.234321234321234e-22L, L
"1.234321e-22" },
2430 { 1.234321234321234e-21L, L
"1.234321e-21" },
2431 { 1.234321234321234e-20L, L
"1.234321e-20" },
2432 { 1.234321234321234e-19L, L
"1.234321e-19" },
2433 { 1.234321234321234e-18L, L
"1.234321e-18" },
2434 { 1.234321234321234e-17L, L
"1.234321e-17" },
2435 { 1.234321234321234e-16L, L
"1.234321e-16" },
2436 { 1.234321234321234e-15L, L
"1.234321e-15" },
2437 { 1.234321234321234e-14L, L
"1.234321e-14" },
2438 { 1.234321234321234e-13L, L
"1.234321e-13" },
2439 { 1.234321234321234e-12L, L
"1.234321e-12" },
2440 { 1.234321234321234e-11L, L
"1.234321e-11" },
2441 { 1.234321234321234e-10L, L
"1.234321e-10" },
2442 { 1.234321234321234e-9L, L
"1.234321e-09" },
2443 { 1.234321234321234e-8L, L
"1.234321e-08" },
2444 { 1.234321234321234e-7L, L
"1.234321e-07" },
2445 { 1.234321234321234e-6L, L
"1.234321e-06" },
2446 { 1.234321234321234e-5L, L
"1.234321e-05" },
2447 { 1.234321234321234e-4L, L
"1.234321e-04" },
2448 { 1.234321234321234e-3L, L
"1.234321e-03" },
2449 { 1.234321234321234e-2L, L
"1.234321e-02" },
2450 { 1.234321234321234e-1L, L
"1.234321e-01" },
2451 { 1.234321234321234L, L
"1.234321e+00" },
2452 { 1.234321234321234e1L
, L
"1.234321e+01" },
2453 { 1.234321234321234e2L
, L
"1.234321e+02" },
2454 { 1.234321234321234e3L
, L
"1.234321e+03" },
2455 { 1.234321234321234e4L
, L
"1.234321e+04" },
2456 { 1.234321234321234e5L
, L
"1.234321e+05" },
2457 { 1.234321234321234e6L
, L
"1.234321e+06" },
2458 { 1.234321234321234e7L
, L
"1.234321e+07" },
2459 { 1.234321234321234e8L
, L
"1.234321e+08" },
2460 { 1.234321234321234e9L
, L
"1.234321e+09" },
2461 { 1.234321234321234e10L
, L
"1.234321e+10" },
2462 { 1.234321234321234e11L
, L
"1.234321e+11" },
2463 { 1.234321234321234e12L
, L
"1.234321e+12" },
2464 { 1.234321234321234e13L
, L
"1.234321e+13" },
2465 { 1.234321234321234e14L
, L
"1.234321e+14" },
2466 { 1.234321234321234e15L
, L
"1.234321e+15" },
2467 { 1.234321234321234e16L
, L
"1.234321e+16" },
2468 { 1.234321234321234e17L
, L
"1.234321e+17" },
2469 { 1.234321234321234e18L
, L
"1.234321e+18" },
2470 { 1.234321234321234e19L
, L
"1.234321e+19" },
2471 { 1.234321234321234e20L
, L
"1.234321e+20" },
2472 { 1.234321234321234e21L
, L
"1.234321e+21" },
2473 { 1.234321234321234e22L
, L
"1.234321e+22" },
2474 { 1.234321234321234e23L
, L
"1.234321e+23" },
2475 { 1.234321234321234e24L
, L
"1.234321e+24" },
2476 { 1.234321234321234e25L
, L
"1.234321e+25" },
2477 { 1.234321234321234e26L
, L
"1.234321e+26" },
2478 { 1.234321234321234e27L
, L
"1.234321e+27" },
2479 { 1.234321234321234e28L
, L
"1.234321e+28" },
2480 { 1.234321234321234e29L
, L
"1.234321e+29" },
2481 { 1.234321234321234e30L
, L
"1.234321e+30" },
2482 { 1.234321234321234e31L
, L
"1.234321e+31" },
2483 { 1.234321234321234e32L
, L
"1.234321e+32" },
2484 { 1.234321234321234e33L
, L
"1.234321e+33" },
2485 { 1.234321234321234e34L
, L
"1.234321e+34" },
2486 { 1.234321234321234e35L
, L
"1.234321e+35" },
2487 { 1.234321234321234e36L
, L
"1.234321e+36" }
2490 for (k
= 0; k
< SIZEOF (data
); k
++)
2494 my_asnwprintf (NULL
, &length
, L
"%Le", data
[k
].value
);
2495 const wchar_t *expected
= data
[k
].string
;
2496 ASSERT (result
!= NULL
);
2497 ASSERT (wcscmp (result
, expected
) == 0
2498 /* Some implementations produce exponents with 3 digits. */
2499 || (wcslen (result
) == wcslen (expected
) + 1
2500 && wmemcmp (result
, expected
, wcslen (expected
) - 2) == 0
2501 && result
[wcslen (expected
) - 2] == '0'
2502 && wcscmp (result
+ wcslen (expected
) - 1,
2503 expected
+ wcslen (expected
) - 2)
2505 ASSERT (length
== wcslen (result
));
2510 { /* A negative number. */
2513 my_asnwprintf (NULL
, &length
, L
"%Le %d", -0.03125L, 33, 44, 55);
2514 ASSERT (result
!= NULL
);
2515 ASSERT (wcscmp (result
, L
"-3.125000e-02 33") == 0
2516 || wcscmp (result
, L
"-3.125000e-002 33") == 0);
2517 ASSERT (length
== wcslen (result
));
2521 { /* Positive zero. */
2524 my_asnwprintf (NULL
, &length
, L
"%Le %d", 0.0L, 33, 44, 55);
2525 ASSERT (result
!= NULL
);
2526 ASSERT (wcscmp (result
, L
"0.000000e+00 33") == 0
2527 || wcscmp (result
, L
"0.000000e+000 33") == 0);
2528 ASSERT (length
== wcslen (result
));
2532 { /* Negative zero. */
2535 my_asnwprintf (NULL
, &length
, L
"%Le %d", minus_zerol
, 33, 44, 55);
2536 ASSERT (result
!= NULL
);
2537 if (have_minus_zero ())
2538 ASSERT (wcscmp (result
, L
"-0.000000e+00 33") == 0
2539 || wcscmp (result
, L
"-0.000000e+000 33") == 0);
2540 ASSERT (length
== wcslen (result
));
2544 { /* Positive infinity. */
2547 my_asnwprintf (NULL
, &length
, L
"%Le %d", Infinityl (), 33, 44, 55);
2548 ASSERT (result
!= NULL
);
2549 ASSERT (wcscmp (result
, L
"inf 33") == 0
2550 || wcscmp (result
, L
"infinity 33") == 0);
2551 ASSERT (length
== wcslen (result
));
2555 { /* Negative infinity. */
2558 my_asnwprintf (NULL
, &length
, L
"%Le %d", - Infinityl (), 33, 44, 55);
2559 ASSERT (result
!= NULL
);
2560 ASSERT (wcscmp (result
, L
"-inf 33") == 0
2561 || wcscmp (result
, L
"-infinity 33") == 0);
2562 ASSERT (length
== wcslen (result
));
2569 my_asnwprintf (NULL
, &length
, L
"%Le %d", NaNl (), 33, 44, 55);
2570 ASSERT (result
!= NULL
);
2571 ASSERT (wcslen (result
) >= 3 + 3
2572 && wcsisnan (result
, 0, wcslen (result
) - 3, 0)
2573 && wcscmp (result
+ wcslen (result
) - 3, L
" 33") == 0);
2574 ASSERT (length
== wcslen (result
));
2578 { /* Signalling NaN. */
2581 my_asnwprintf (NULL
, &length
, L
"%Le %d", SNaNl (), 33, 44, 55);
2582 ASSERT (result
!= NULL
);
2583 ASSERT (wcslen (result
) >= 3 + 3
2584 && wcsisnan (result
, 0, wcslen (result
) - 3, 0)
2585 && wcscmp (result
+ wcslen (result
) - 3, L
" 33") == 0);
2586 ASSERT (length
== wcslen (result
));
2590 #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
2592 static union { unsigned int word
[4]; long double value
; } x
=
2593 { .word
= LDBL80_WORDS (0xFFFF, 0xC3333333, 0x00000000) };
2596 my_asnwprintf (NULL
, &length
, L
"%Le %d", x
.value
, 33, 44, 55);
2597 ASSERT (result
!= NULL
);
2598 ASSERT (length
== wcslen (result
));
2599 ASSERT (3 < length
&& wcscmp (result
+ length
- 3, L
" 33") == 0);
2603 /* Signalling NaN. */
2604 static union { unsigned int word
[4]; long double value
; } x
=
2605 { .word
= LDBL80_WORDS (0xFFFF, 0x83333333, 0x00000000) };
2608 my_asnwprintf (NULL
, &length
, L
"%Le %d", x
.value
, 33, 44, 55);
2609 ASSERT (result
!= NULL
);
2610 ASSERT (length
== wcslen (result
));
2611 ASSERT (3 < length
&& wcscmp (result
+ length
- 3, L
" 33") == 0);
2614 /* asnwprintf should print something even for noncanonical values. */
2616 static union { unsigned int word
[4]; long double value
; } x
=
2617 { .word
= LDBL80_WORDS (0xFFFF, 0x40000001, 0x00000000) };
2620 my_asnwprintf (NULL
, &length
, L
"%Le %d", x
.value
, 33, 44, 55);
2621 ASSERT (result
!= NULL
);
2622 ASSERT (length
== wcslen (result
));
2623 ASSERT (3 < length
&& wcscmp (result
+ length
- 3, L
" 33") == 0);
2626 { /* Pseudo-Infinity. */
2627 static union { unsigned int word
[4]; long double value
; } x
=
2628 { .word
= LDBL80_WORDS (0xFFFF, 0x00000000, 0x00000000) };
2631 my_asnwprintf (NULL
, &length
, L
"%Le %d", x
.value
, 33, 44, 55);
2632 ASSERT (result
!= NULL
);
2633 ASSERT (length
== wcslen (result
));
2634 ASSERT (3 < length
&& wcscmp (result
+ length
- 3, L
" 33") == 0);
2637 { /* Pseudo-Zero. */
2638 static union { unsigned int word
[4]; long double value
; } x
=
2639 { .word
= LDBL80_WORDS (0x4004, 0x00000000, 0x00000000) };
2642 my_asnwprintf (NULL
, &length
, L
"%Le %d", x
.value
, 33, 44, 55);
2643 ASSERT (result
!= NULL
);
2644 ASSERT (length
== wcslen (result
));
2645 ASSERT (3 < length
&& wcscmp (result
+ length
- 3, L
" 33") == 0);
2648 { /* Unnormalized number. */
2649 static union { unsigned int word
[4]; long double value
; } x
=
2650 { .word
= LDBL80_WORDS (0x4000, 0x63333333, 0x00000000) };
2653 my_asnwprintf (NULL
, &length
, L
"%Le %d", x
.value
, 33, 44, 55);
2654 ASSERT (result
!= NULL
);
2655 ASSERT (length
== wcslen (result
));
2656 ASSERT (3 < length
&& wcscmp (result
+ length
- 3, L
" 33") == 0);
2659 { /* Pseudo-Denormal. */
2660 static union { unsigned int word
[4]; long double value
; } x
=
2661 { .word
= LDBL80_WORDS (0x0000, 0x83333333, 0x00000000) };
2664 my_asnwprintf (NULL
, &length
, L
"%Le %d", x
.value
, 33, 44, 55);
2665 ASSERT (result
!= NULL
);
2666 ASSERT (length
== wcslen (result
));
2667 ASSERT (3 < length
&& wcscmp (result
+ length
- 3, L
" 33") == 0);
2675 my_asnwprintf (NULL
, &length
, L
"%15Le %d", 1.75L, 33, 44, 55);
2676 ASSERT (result
!= NULL
);
2677 ASSERT (wcscmp (result
, L
" 1.750000e+00 33") == 0
2678 || wcscmp (result
, L
" 1.750000e+000 33") == 0);
2679 ASSERT (length
== wcslen (result
));
2683 { /* Width given as argument. */
2686 my_asnwprintf (NULL
, &length
, L
"%*Le %d", 15, 1.75L, 33, 44, 55);
2687 ASSERT (result
!= NULL
);
2688 ASSERT (wcscmp (result
, L
" 1.750000e+00 33") == 0
2689 || wcscmp (result
, L
" 1.750000e+000 33") == 0);
2690 ASSERT (length
== wcslen (result
));
2694 { /* Negative width given as argument (cf. FLAG_LEFT below). */
2697 my_asnwprintf (NULL
, &length
, L
"%*Le %d", -15, 1.75L, 33, 44, 55);
2698 ASSERT (result
!= NULL
);
2699 ASSERT (wcscmp (result
, L
"1.750000e+00 33") == 0
2700 || wcscmp (result
, L
"1.750000e+000 33") == 0);
2701 ASSERT (length
== wcslen (result
));
2708 my_asnwprintf (NULL
, &length
, L
"%-15Le %d", 1.75L, 33, 44, 55);
2709 ASSERT (result
!= NULL
);
2710 ASSERT (wcscmp (result
, L
"1.750000e+00 33") == 0
2711 || wcscmp (result
, L
"1.750000e+000 33") == 0);
2712 ASSERT (length
== wcslen (result
));
2716 { /* FLAG_SHOWSIGN. */
2719 my_asnwprintf (NULL
, &length
, L
"%+Le %d", 1.75L, 33, 44, 55);
2720 ASSERT (result
!= NULL
);
2721 ASSERT (wcscmp (result
, L
"+1.750000e+00 33") == 0
2722 || wcscmp (result
, L
"+1.750000e+000 33") == 0);
2723 ASSERT (length
== wcslen (result
));
2730 my_asnwprintf (NULL
, &length
, L
"% Le %d", 1.75L, 33, 44, 55);
2731 ASSERT (result
!= NULL
);
2732 ASSERT (wcscmp (result
, L
" 1.750000e+00 33") == 0
2733 || wcscmp (result
, L
" 1.750000e+000 33") == 0);
2734 ASSERT (length
== wcslen (result
));
2741 my_asnwprintf (NULL
, &length
, L
"%#Le %d", 1.75L, 33, 44, 55);
2742 ASSERT (result
!= NULL
);
2743 ASSERT (wcscmp (result
, L
"1.750000e+00 33") == 0
2744 || wcscmp (result
, L
"1.750000e+000 33") == 0);
2745 ASSERT (length
== wcslen (result
));
2752 my_asnwprintf (NULL
, &length
, L
"%#.Le %d", 1.75L, 33, 44, 55);
2753 ASSERT (result
!= NULL
);
2754 ASSERT (wcscmp (result
, L
"2.e+00 33") == 0
2755 || wcscmp (result
, L
"2.e+000 33") == 0);
2756 ASSERT (length
== wcslen (result
));
2763 my_asnwprintf (NULL
, &length
, L
"%#.Le %d", 9.75L, 33, 44, 55);
2764 ASSERT (result
!= NULL
);
2765 ASSERT (wcscmp (result
, L
"1.e+01 33") == 0
2766 || wcscmp (result
, L
"1.e+001 33") == 0);
2767 ASSERT (length
== wcslen (result
));
2771 { /* FLAG_ZERO with finite number. */
2774 my_asnwprintf (NULL
, &length
, L
"%015Le %d", 1234.0L, 33, 44, 55);
2775 ASSERT (result
!= NULL
);
2776 ASSERT (wcscmp (result
, L
"0001.234000e+03 33") == 0
2777 || wcscmp (result
, L
"001.234000e+003 33") == 0);
2778 ASSERT (length
== wcslen (result
));
2782 { /* FLAG_ZERO with infinite number. */
2785 my_asnwprintf (NULL
, &length
, L
"%015Le %d", - Infinityl (), 33, 44, 55);
2786 ASSERT (result
!= NULL
);
2787 ASSERT (wcscmp (result
, L
" -inf 33") == 0
2788 || wcscmp (result
, L
" -infinity 33") == 0);
2789 ASSERT (length
== wcslen (result
));
2793 { /* FLAG_ZERO with NaN. */
2796 my_asnwprintf (NULL
, &length
, L
"%050Le %d", NaNl (), 33, 44, 55);
2797 ASSERT (result
!= NULL
);
2798 ASSERT (wcslen (result
) == 50 + 3
2799 && wcsisnan (result
, wcsspn (result
, L
" "), wcslen (result
) - 3, 0)
2800 && wcscmp (result
+ wcslen (result
) - 3, L
" 33") == 0);
2801 ASSERT (length
== wcslen (result
));
2808 my_asnwprintf (NULL
, &length
, L
"%.Le %d", 1234.0L, 33, 44, 55);
2809 ASSERT (result
!= NULL
);
2810 ASSERT (wcscmp (result
, L
"1e+03 33") == 0
2811 || wcscmp (result
, L
"1e+003 33") == 0);
2812 ASSERT (length
== wcslen (result
));
2816 { /* Precision with no rounding. */
2819 my_asnwprintf (NULL
, &length
, L
"%.4Le %d", 999.951L, 33, 44, 55);
2820 ASSERT (result
!= NULL
);
2821 ASSERT (wcscmp (result
, L
"9.9995e+02 33") == 0
2822 || wcscmp (result
, L
"9.9995e+002 33") == 0);
2823 ASSERT (length
== wcslen (result
));
2827 { /* Precision with rounding. */
2830 my_asnwprintf (NULL
, &length
, L
"%.4Le %d", 999.996L, 33, 44, 55);
2831 ASSERT (result
!= NULL
);
2832 ASSERT (wcscmp (result
, L
"1.0000e+03 33") == 0
2833 || wcscmp (result
, L
"1.0000e+003 33") == 0);
2834 ASSERT (length
== wcslen (result
));
2838 /* Test the support of the %g format directive. */
2840 { /* A positive number. */
2843 my_asnwprintf (NULL
, &length
, L
"%g %d", 12.75, 33, 44, 55);
2844 ASSERT (result
!= NULL
);
2845 ASSERT (wcscmp (result
, L
"12.75 33") == 0);
2846 ASSERT (length
== wcslen (result
));
2850 { /* A larger positive number. */
2853 my_asnwprintf (NULL
, &length
, L
"%g %d", 1234567.0, 33, 44, 55);
2854 ASSERT (result
!= NULL
);
2855 ASSERT (wcscmp (result
, L
"1.23457e+06 33") == 0
2856 || wcscmp (result
, L
"1.23457e+006 33") == 0);
2857 ASSERT (length
== wcslen (result
));
2861 { /* Small and large positive numbers. */
2862 static struct { double value
; const wchar_t *string
; } data
[] =
2864 { 1.234321234321234e-37, L
"1.23432e-37" },
2865 { 1.234321234321234e-36, L
"1.23432e-36" },
2866 { 1.234321234321234e-35, L
"1.23432e-35" },
2867 { 1.234321234321234e-34, L
"1.23432e-34" },
2868 { 1.234321234321234e-33, L
"1.23432e-33" },
2869 { 1.234321234321234e-32, L
"1.23432e-32" },
2870 { 1.234321234321234e-31, L
"1.23432e-31" },
2871 { 1.234321234321234e-30, L
"1.23432e-30" },
2872 { 1.234321234321234e-29, L
"1.23432e-29" },
2873 { 1.234321234321234e-28, L
"1.23432e-28" },
2874 { 1.234321234321234e-27, L
"1.23432e-27" },
2875 { 1.234321234321234e-26, L
"1.23432e-26" },
2876 { 1.234321234321234e-25, L
"1.23432e-25" },
2877 { 1.234321234321234e-24, L
"1.23432e-24" },
2878 { 1.234321234321234e-23, L
"1.23432e-23" },
2879 { 1.234321234321234e-22, L
"1.23432e-22" },
2880 { 1.234321234321234e-21, L
"1.23432e-21" },
2881 { 1.234321234321234e-20, L
"1.23432e-20" },
2882 { 1.234321234321234e-19, L
"1.23432e-19" },
2883 { 1.234321234321234e-18, L
"1.23432e-18" },
2884 { 1.234321234321234e-17, L
"1.23432e-17" },
2885 { 1.234321234321234e-16, L
"1.23432e-16" },
2886 { 1.234321234321234e-15, L
"1.23432e-15" },
2887 { 1.234321234321234e-14, L
"1.23432e-14" },
2888 { 1.234321234321234e-13, L
"1.23432e-13" },
2889 { 1.234321234321234e-12, L
"1.23432e-12" },
2890 { 1.234321234321234e-11, L
"1.23432e-11" },
2891 { 1.234321234321234e-10, L
"1.23432e-10" },
2892 { 1.234321234321234e-9, L
"1.23432e-09" },
2893 { 1.234321234321234e-8, L
"1.23432e-08" },
2894 { 1.234321234321234e-7, L
"1.23432e-07" },
2895 { 1.234321234321234e-6, L
"1.23432e-06" },
2896 { 1.234321234321234e-5, L
"1.23432e-05" },
2897 { 1.234321234321234e-4, L
"0.000123432" },
2898 { 1.234321234321234e-3, L
"0.00123432" },
2899 { 1.234321234321234e-2, L
"0.0123432" },
2900 { 1.234321234321234e-1, L
"0.123432" },
2901 { 1.234321234321234, L
"1.23432" },
2902 { 1.234321234321234e1
, L
"12.3432" },
2903 { 1.234321234321234e2
, L
"123.432" },
2904 { 1.234321234321234e3
, L
"1234.32" },
2905 { 1.234321234321234e4
, L
"12343.2" },
2906 { 1.234321234321234e5
, L
"123432" },
2907 { 1.234321234321234e6
, L
"1.23432e+06" },
2908 { 1.234321234321234e7
, L
"1.23432e+07" },
2909 { 1.234321234321234e8
, L
"1.23432e+08" },
2910 { 1.234321234321234e9
, L
"1.23432e+09" },
2911 { 1.234321234321234e10
, L
"1.23432e+10" },
2912 { 1.234321234321234e11
, L
"1.23432e+11" },
2913 { 1.234321234321234e12
, L
"1.23432e+12" },
2914 { 1.234321234321234e13
, L
"1.23432e+13" },
2915 { 1.234321234321234e14
, L
"1.23432e+14" },
2916 { 1.234321234321234e15
, L
"1.23432e+15" },
2917 { 1.234321234321234e16
, L
"1.23432e+16" },
2918 { 1.234321234321234e17
, L
"1.23432e+17" },
2919 { 1.234321234321234e18
, L
"1.23432e+18" },
2920 { 1.234321234321234e19
, L
"1.23432e+19" },
2921 { 1.234321234321234e20
, L
"1.23432e+20" },
2922 { 1.234321234321234e21
, L
"1.23432e+21" },
2923 { 1.234321234321234e22
, L
"1.23432e+22" },
2924 { 1.234321234321234e23
, L
"1.23432e+23" },
2925 { 1.234321234321234e24
, L
"1.23432e+24" },
2926 { 1.234321234321234e25
, L
"1.23432e+25" },
2927 { 1.234321234321234e26
, L
"1.23432e+26" },
2928 { 1.234321234321234e27
, L
"1.23432e+27" },
2929 { 1.234321234321234e28
, L
"1.23432e+28" },
2930 { 1.234321234321234e29
, L
"1.23432e+29" },
2931 { 1.234321234321234e30
, L
"1.23432e+30" },
2932 { 1.234321234321234e31
, L
"1.23432e+31" },
2933 { 1.234321234321234e32
, L
"1.23432e+32" },
2934 { 1.234321234321234e33
, L
"1.23432e+33" },
2935 { 1.234321234321234e34
, L
"1.23432e+34" },
2936 { 1.234321234321234e35
, L
"1.23432e+35" },
2937 { 1.234321234321234e36
, L
"1.23432e+36" }
2940 for (k
= 0; k
< SIZEOF (data
); k
++)
2944 my_asnwprintf (NULL
, &length
, L
"%g", data
[k
].value
);
2945 const wchar_t *expected
= data
[k
].string
;
2946 ASSERT (result
!= NULL
);
2947 ASSERT (wcscmp (result
, expected
) == 0
2948 /* Some implementations produce exponents with 3 digits. */
2949 || (expected
[wcslen (expected
) - 4] == 'e'
2950 && wcslen (result
) == wcslen (expected
) + 1
2951 && wmemcmp (result
, expected
, wcslen (expected
) - 2) == 0
2952 && result
[wcslen (expected
) - 2] == '0'
2953 && wcscmp (result
+ wcslen (expected
) - 1,
2954 expected
+ wcslen (expected
) - 2)
2956 ASSERT (length
== wcslen (result
));
2961 { /* A negative number. */
2964 my_asnwprintf (NULL
, &length
, L
"%g %d", -0.03125, 33, 44, 55);
2965 ASSERT (result
!= NULL
);
2966 ASSERT (wcscmp (result
, L
"-0.03125 33") == 0);
2967 ASSERT (length
== wcslen (result
));
2971 { /* Positive zero. */
2974 my_asnwprintf (NULL
, &length
, L
"%g %d", 0.0, 33, 44, 55);
2975 ASSERT (result
!= NULL
);
2976 ASSERT (wcscmp (result
, L
"0 33") == 0);
2977 ASSERT (length
== wcslen (result
));
2981 { /* Negative zero. */
2984 my_asnwprintf (NULL
, &length
, L
"%g %d", minus_zerod
, 33, 44, 55);
2985 ASSERT (result
!= NULL
);
2986 if (have_minus_zero ())
2987 ASSERT (wcscmp (result
, L
"-0 33") == 0);
2988 ASSERT (length
== wcslen (result
));
2992 { /* Positive infinity. */
2995 my_asnwprintf (NULL
, &length
, L
"%g %d", Infinityd (), 33, 44, 55);
2996 ASSERT (result
!= NULL
);
2997 ASSERT (wcscmp (result
, L
"inf 33") == 0
2998 || wcscmp (result
, L
"infinity 33") == 0);
2999 ASSERT (length
== wcslen (result
));
3003 { /* Negative infinity. */
3006 my_asnwprintf (NULL
, &length
, L
"%g %d", - Infinityd (), 33, 44, 55);
3007 ASSERT (result
!= NULL
);
3008 ASSERT (wcscmp (result
, L
"-inf 33") == 0
3009 || wcscmp (result
, L
"-infinity 33") == 0);
3010 ASSERT (length
== wcslen (result
));
3017 my_asnwprintf (NULL
, &length
, L
"%g %d", NaNd (), 33, 44, 55);
3018 ASSERT (result
!= NULL
);
3019 ASSERT (wcslen (result
) >= 3 + 3
3020 && wcsisnan (result
, 0, wcslen (result
) - 3, 0)
3021 && wcscmp (result
+ wcslen (result
) - 3, L
" 33") == 0);
3022 ASSERT (length
== wcslen (result
));
3026 { /* Signalling NaN. */
3029 my_asnwprintf (NULL
, &length
, L
"%g %d", SNaNd (), 33, 44, 55);
3030 ASSERT (result
!= NULL
);
3031 ASSERT (wcslen (result
) >= 3 + 3
3032 && wcsisnan (result
, 0, wcslen (result
) - 3, 0)
3033 && wcscmp (result
+ wcslen (result
) - 3, L
" 33") == 0);
3034 ASSERT (length
== wcslen (result
));
3042 my_asnwprintf (NULL
, &length
, L
"%10g %d", 1.75, 33, 44, 55);
3043 ASSERT (result
!= NULL
);
3044 ASSERT (wcscmp (result
, L
" 1.75 33") == 0);
3045 ASSERT (length
== wcslen (result
));
3049 { /* Width given as argument. */
3052 my_asnwprintf (NULL
, &length
, L
"%*g %d", 10, 1.75, 33, 44, 55);
3053 ASSERT (result
!= NULL
);
3054 ASSERT (wcscmp (result
, L
" 1.75 33") == 0);
3055 ASSERT (length
== wcslen (result
));
3059 { /* Negative width given as argument (cf. FLAG_LEFT below). */
3062 my_asnwprintf (NULL
, &length
, L
"%*g %d", -10, 1.75, 33, 44, 55);
3063 ASSERT (result
!= NULL
);
3064 ASSERT (wcscmp (result
, L
"1.75 33") == 0);
3065 ASSERT (length
== wcslen (result
));
3072 my_asnwprintf (NULL
, &length
, L
"%-10g %d", 1.75, 33, 44, 55);
3073 ASSERT (result
!= NULL
);
3074 ASSERT (wcscmp (result
, L
"1.75 33") == 0);
3075 ASSERT (length
== wcslen (result
));
3079 { /* FLAG_SHOWSIGN. */
3082 my_asnwprintf (NULL
, &length
, L
"%+g %d", 1.75, 33, 44, 55);
3083 ASSERT (result
!= NULL
);
3084 ASSERT (wcscmp (result
, L
"+1.75 33") == 0);
3085 ASSERT (length
== wcslen (result
));
3092 my_asnwprintf (NULL
, &length
, L
"% g %d", 1.75, 33, 44, 55);
3093 ASSERT (result
!= NULL
);
3094 ASSERT (wcscmp (result
, L
" 1.75 33") == 0);
3095 ASSERT (length
== wcslen (result
));
3102 my_asnwprintf (NULL
, &length
, L
"%#g %d", 1.75, 33, 44, 55);
3103 ASSERT (result
!= NULL
);
3104 ASSERT (wcscmp (result
, L
"1.75000 33") == 0);
3105 ASSERT (length
== wcslen (result
));
3112 my_asnwprintf (NULL
, &length
, L
"%#.g %d", 1.75, 33, 44, 55);
3113 ASSERT (result
!= NULL
);
3114 ASSERT (wcscmp (result
, L
"2. 33") == 0);
3115 ASSERT (length
== wcslen (result
));
3122 my_asnwprintf (NULL
, &length
, L
"%#.g %d", 9.75, 33, 44, 55);
3123 ASSERT (result
!= NULL
);
3124 ASSERT (wcscmp (result
, L
"1.e+01 33") == 0
3125 || wcscmp (result
, L
"1.e+001 33") == 0);
3126 ASSERT (length
== wcslen (result
));
3130 { /* FLAG_ZERO with finite number. */
3133 my_asnwprintf (NULL
, &length
, L
"%010g %d", 1234.0, 33, 44, 55);
3134 ASSERT (result
!= NULL
);
3135 ASSERT (wcscmp (result
, L
"0000001234 33") == 0);
3136 ASSERT (length
== wcslen (result
));
3140 { /* FLAG_ZERO with infinite number. */
3143 my_asnwprintf (NULL
, &length
, L
"%015g %d", - Infinityd (), 33, 44, 55);
3144 ASSERT (result
!= NULL
);
3145 ASSERT (wcscmp (result
, L
" -inf 33") == 0
3146 || wcscmp (result
, L
" -infinity 33") == 0);
3147 ASSERT (length
== wcslen (result
));
3151 { /* FLAG_ZERO with NaN. */
3154 my_asnwprintf (NULL
, &length
, L
"%050g %d", NaNd (), 33, 44, 55);
3155 ASSERT (result
!= NULL
);
3156 ASSERT (wcslen (result
) == 50 + 3
3157 && wcsisnan (result
, wcsspn (result
, L
" "), wcslen (result
) - 3, 0)
3158 && wcscmp (result
+ wcslen (result
) - 3, L
" 33") == 0);
3159 ASSERT (length
== wcslen (result
));
3166 my_asnwprintf (NULL
, &length
, L
"%.g %d", 1234.0, 33, 44, 55);
3167 ASSERT (result
!= NULL
);
3168 ASSERT (wcscmp (result
, L
"1e+03 33") == 0
3169 || wcscmp (result
, L
"1e+003 33") == 0);
3170 ASSERT (length
== wcslen (result
));
3174 { /* Precision with no rounding. */
3177 my_asnwprintf (NULL
, &length
, L
"%.5g %d", 999.951, 33, 44, 55);
3178 ASSERT (result
!= NULL
);
3179 ASSERT (wcscmp (result
, L
"999.95 33") == 0);
3180 ASSERT (length
== wcslen (result
));
3184 { /* Precision with rounding. */
3187 my_asnwprintf (NULL
, &length
, L
"%.5g %d", 999.996, 33, 44, 55);
3188 ASSERT (result
!= NULL
);
3189 ASSERT (wcscmp (result
, L
"1000 33") == 0);
3190 ASSERT (length
== wcslen (result
));
3194 { /* A positive number. */
3197 my_asnwprintf (NULL
, &length
, L
"%Lg %d", 12.75L, 33, 44, 55);
3198 ASSERT (result
!= NULL
);
3199 ASSERT (wcscmp (result
, L
"12.75 33") == 0);
3200 ASSERT (length
== wcslen (result
));
3204 { /* A larger positive number. */
3207 my_asnwprintf (NULL
, &length
, L
"%Lg %d", 1234567.0L, 33, 44, 55);
3208 ASSERT (result
!= NULL
);
3209 ASSERT (wcscmp (result
, L
"1.23457e+06 33") == 0
3210 || wcscmp (result
, L
"1.23457e+006 33") == 0);
3211 ASSERT (length
== wcslen (result
));
3215 { /* Small and large positive numbers. */
3216 static struct { long double value
; const wchar_t *string
; } data
[] =
3218 { 1.234321234321234e-37L, L
"1.23432e-37" },
3219 { 1.234321234321234e-36L, L
"1.23432e-36" },
3220 { 1.234321234321234e-35L, L
"1.23432e-35" },
3221 { 1.234321234321234e-34L, L
"1.23432e-34" },
3222 { 1.234321234321234e-33L, L
"1.23432e-33" },
3223 { 1.234321234321234e-32L, L
"1.23432e-32" },
3224 { 1.234321234321234e-31L, L
"1.23432e-31" },
3225 { 1.234321234321234e-30L, L
"1.23432e-30" },
3226 { 1.234321234321234e-29L, L
"1.23432e-29" },
3227 { 1.234321234321234e-28L, L
"1.23432e-28" },
3228 { 1.234321234321234e-27L, L
"1.23432e-27" },
3229 { 1.234321234321234e-26L, L
"1.23432e-26" },
3230 { 1.234321234321234e-25L, L
"1.23432e-25" },
3231 { 1.234321234321234e-24L, L
"1.23432e-24" },
3232 { 1.234321234321234e-23L, L
"1.23432e-23" },
3233 { 1.234321234321234e-22L, L
"1.23432e-22" },
3234 { 1.234321234321234e-21L, L
"1.23432e-21" },
3235 { 1.234321234321234e-20L, L
"1.23432e-20" },
3236 { 1.234321234321234e-19L, L
"1.23432e-19" },
3237 { 1.234321234321234e-18L, L
"1.23432e-18" },
3238 { 1.234321234321234e-17L, L
"1.23432e-17" },
3239 { 1.234321234321234e-16L, L
"1.23432e-16" },
3240 { 1.234321234321234e-15L, L
"1.23432e-15" },
3241 { 1.234321234321234e-14L, L
"1.23432e-14" },
3242 { 1.234321234321234e-13L, L
"1.23432e-13" },
3243 { 1.234321234321234e-12L, L
"1.23432e-12" },
3244 { 1.234321234321234e-11L, L
"1.23432e-11" },
3245 { 1.234321234321234e-10L, L
"1.23432e-10" },
3246 { 1.234321234321234e-9L, L
"1.23432e-09" },
3247 { 1.234321234321234e-8L, L
"1.23432e-08" },
3248 { 1.234321234321234e-7L, L
"1.23432e-07" },
3249 { 1.234321234321234e-6L, L
"1.23432e-06" },
3250 { 1.234321234321234e-5L, L
"1.23432e-05" },
3251 { 1.234321234321234e-4L, L
"0.000123432" },
3252 { 1.234321234321234e-3L, L
"0.00123432" },
3253 { 1.234321234321234e-2L, L
"0.0123432" },
3254 { 1.234321234321234e-1L, L
"0.123432" },
3255 { 1.234321234321234L, L
"1.23432" },
3256 { 1.234321234321234e1L
, L
"12.3432" },
3257 { 1.234321234321234e2L
, L
"123.432" },
3258 { 1.234321234321234e3L
, L
"1234.32" },
3259 { 1.234321234321234e4L
, L
"12343.2" },
3260 { 1.234321234321234e5L
, L
"123432" },
3261 { 1.234321234321234e6L
, L
"1.23432e+06" },
3262 { 1.234321234321234e7L
, L
"1.23432e+07" },
3263 { 1.234321234321234e8L
, L
"1.23432e+08" },
3264 { 1.234321234321234e9L
, L
"1.23432e+09" },
3265 { 1.234321234321234e10L
, L
"1.23432e+10" },
3266 { 1.234321234321234e11L
, L
"1.23432e+11" },
3267 { 1.234321234321234e12L
, L
"1.23432e+12" },
3268 { 1.234321234321234e13L
, L
"1.23432e+13" },
3269 { 1.234321234321234e14L
, L
"1.23432e+14" },
3270 { 1.234321234321234e15L
, L
"1.23432e+15" },
3271 { 1.234321234321234e16L
, L
"1.23432e+16" },
3272 { 1.234321234321234e17L
, L
"1.23432e+17" },
3273 { 1.234321234321234e18L
, L
"1.23432e+18" },
3274 { 1.234321234321234e19L
, L
"1.23432e+19" },
3275 { 1.234321234321234e20L
, L
"1.23432e+20" },
3276 { 1.234321234321234e21L
, L
"1.23432e+21" },
3277 { 1.234321234321234e22L
, L
"1.23432e+22" },
3278 { 1.234321234321234e23L
, L
"1.23432e+23" },
3279 { 1.234321234321234e24L
, L
"1.23432e+24" },
3280 { 1.234321234321234e25L
, L
"1.23432e+25" },
3281 { 1.234321234321234e26L
, L
"1.23432e+26" },
3282 { 1.234321234321234e27L
, L
"1.23432e+27" },
3283 { 1.234321234321234e28L
, L
"1.23432e+28" },
3284 { 1.234321234321234e29L
, L
"1.23432e+29" },
3285 { 1.234321234321234e30L
, L
"1.23432e+30" },
3286 { 1.234321234321234e31L
, L
"1.23432e+31" },
3287 { 1.234321234321234e32L
, L
"1.23432e+32" },
3288 { 1.234321234321234e33L
, L
"1.23432e+33" },
3289 { 1.234321234321234e34L
, L
"1.23432e+34" },
3290 { 1.234321234321234e35L
, L
"1.23432e+35" },
3291 { 1.234321234321234e36L
, L
"1.23432e+36" }
3294 for (k
= 0; k
< SIZEOF (data
); k
++)
3298 my_asnwprintf (NULL
, &length
, L
"%Lg", data
[k
].value
);
3299 const wchar_t *expected
= data
[k
].string
;
3300 ASSERT (result
!= NULL
);
3301 ASSERT (wcscmp (result
, expected
) == 0
3302 /* Some implementations produce exponents with 3 digits. */
3303 || (expected
[wcslen (expected
) - 4] == 'e'
3304 && wcslen (result
) == wcslen (expected
) + 1
3305 && wmemcmp (result
, expected
, wcslen (expected
) - 2) == 0
3306 && result
[wcslen (expected
) - 2] == '0'
3307 && wcscmp (result
+ wcslen (expected
) - 1,
3308 expected
+ wcslen (expected
) - 2)
3310 ASSERT (length
== wcslen (result
));
3315 { /* A negative number. */
3318 my_asnwprintf (NULL
, &length
, L
"%Lg %d", -0.03125L, 33, 44, 55);
3319 ASSERT (result
!= NULL
);
3320 ASSERT (wcscmp (result
, L
"-0.03125 33") == 0);
3321 ASSERT (length
== wcslen (result
));
3325 { /* Positive zero. */
3328 my_asnwprintf (NULL
, &length
, L
"%Lg %d", 0.0L, 33, 44, 55);
3329 ASSERT (result
!= NULL
);
3330 ASSERT (wcscmp (result
, L
"0 33") == 0);
3331 ASSERT (length
== wcslen (result
));
3335 { /* Negative zero. */
3338 my_asnwprintf (NULL
, &length
, L
"%Lg %d", minus_zerol
, 33, 44, 55);
3339 ASSERT (result
!= NULL
);
3340 if (have_minus_zero ())
3341 ASSERT (wcscmp (result
, L
"-0 33") == 0);
3342 ASSERT (length
== wcslen (result
));
3346 { /* Positive infinity. */
3349 my_asnwprintf (NULL
, &length
, L
"%Lg %d", Infinityl (), 33, 44, 55);
3350 ASSERT (result
!= NULL
);
3351 ASSERT (wcscmp (result
, L
"inf 33") == 0
3352 || wcscmp (result
, L
"infinity 33") == 0);
3353 ASSERT (length
== wcslen (result
));
3357 { /* Negative infinity. */
3360 my_asnwprintf (NULL
, &length
, L
"%Lg %d", - Infinityl (), 33, 44, 55);
3361 ASSERT (result
!= NULL
);
3362 ASSERT (wcscmp (result
, L
"-inf 33") == 0
3363 || wcscmp (result
, L
"-infinity 33") == 0);
3364 ASSERT (length
== wcslen (result
));
3371 my_asnwprintf (NULL
, &length
, L
"%Lg %d", NaNl (), 33, 44, 55);
3372 ASSERT (result
!= NULL
);
3373 ASSERT (wcslen (result
) >= 3 + 3
3374 && wcsisnan (result
, 0, wcslen (result
) - 3, 0)
3375 && wcscmp (result
+ wcslen (result
) - 3, L
" 33") == 0);
3376 ASSERT (length
== wcslen (result
));
3380 { /* Signalling NaN. */
3383 my_asnwprintf (NULL
, &length
, L
"%Lg %d", SNaNl (), 33, 44, 55);
3384 ASSERT (result
!= NULL
);
3385 ASSERT (wcslen (result
) >= 3 + 3
3386 && wcsisnan (result
, 0, wcslen (result
) - 3, 0)
3387 && wcscmp (result
+ wcslen (result
) - 3, L
" 33") == 0);
3388 ASSERT (length
== wcslen (result
));
3392 #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
3394 static union { unsigned int word
[4]; long double value
; } x
=
3395 { .word
= LDBL80_WORDS (0xFFFF, 0xC3333333, 0x00000000) };
3398 my_asnwprintf (NULL
, &length
, L
"%Lg %d", x
.value
, 33, 44, 55);
3399 ASSERT (result
!= NULL
);
3400 ASSERT (wcslen (result
) >= 3 + 3
3401 && wcsisnan (result
, 0, wcslen (result
) - 3, 0)
3402 && wcscmp (result
+ wcslen (result
) - 3, L
" 33") == 0);
3403 ASSERT (length
== wcslen (result
));
3407 /* Signalling NaN. */
3408 static union { unsigned int word
[4]; long double value
; } x
=
3409 { .word
= LDBL80_WORDS (0xFFFF, 0x83333333, 0x00000000) };
3412 my_asnwprintf (NULL
, &length
, L
"%Lg %d", x
.value
, 33, 44, 55);
3413 ASSERT (result
!= NULL
);
3414 ASSERT (wcslen (result
) >= 3 + 3
3415 && wcsisnan (result
, 0, wcslen (result
) - 3, 0)
3416 && wcscmp (result
+ wcslen (result
) - 3, L
" 33") == 0);
3417 ASSERT (length
== wcslen (result
));
3420 /* asnwprintf should print something for noncanonical values. */
3422 static union { unsigned int word
[4]; long double value
; } x
=
3423 { .word
= LDBL80_WORDS (0xFFFF, 0x40000001, 0x00000000) };
3426 my_asnwprintf (NULL
, &length
, L
"%Lg %d", x
.value
, 33, 44, 55);
3427 ASSERT (result
!= NULL
);
3428 ASSERT (length
== wcslen (result
));
3429 ASSERT (3 < length
&& wcscmp (result
+ length
- 3, L
" 33") == 0);
3432 { /* Pseudo-Infinity. */
3433 static union { unsigned int word
[4]; long double value
; } x
=
3434 { .word
= LDBL80_WORDS (0xFFFF, 0x00000000, 0x00000000) };
3437 my_asnwprintf (NULL
, &length
, L
"%Lg %d", x
.value
, 33, 44, 55);
3438 ASSERT (result
!= NULL
);
3439 ASSERT (length
== wcslen (result
));
3440 ASSERT (3 < length
&& wcscmp (result
+ length
- 3, L
" 33") == 0);
3443 { /* Pseudo-Zero. */
3444 static union { unsigned int word
[4]; long double value
; } x
=
3445 { .word
= LDBL80_WORDS (0x4004, 0x00000000, 0x00000000) };
3448 my_asnwprintf (NULL
, &length
, L
"%Lg %d", x
.value
, 33, 44, 55);
3449 ASSERT (result
!= NULL
);
3450 ASSERT (length
== wcslen (result
));
3451 ASSERT (3 < length
&& wcscmp (result
+ length
- 3, L
" 33") == 0);
3454 { /* Unnormalized number. */
3455 static union { unsigned int word
[4]; long double value
; } x
=
3456 { .word
= LDBL80_WORDS (0x4000, 0x63333333, 0x00000000) };
3459 my_asnwprintf (NULL
, &length
, L
"%Lg %d", x
.value
, 33, 44, 55);
3460 ASSERT (result
!= NULL
);
3461 ASSERT (length
== wcslen (result
));
3462 ASSERT (3 < length
&& wcscmp (result
+ length
- 3, L
" 33") == 0);
3465 { /* Pseudo-Denormal. */
3466 static union { unsigned int word
[4]; long double value
; } x
=
3467 { .word
= LDBL80_WORDS (0x0000, 0x83333333, 0x00000000) };
3470 my_asnwprintf (NULL
, &length
, L
"%Lg %d", x
.value
, 33, 44, 55);
3471 ASSERT (result
!= NULL
);
3472 ASSERT (length
== wcslen (result
));
3473 ASSERT (3 < length
&& wcscmp (result
+ length
- 3, L
" 33") == 0);
3481 my_asnwprintf (NULL
, &length
, L
"%10Lg %d", 1.75L, 33, 44, 55);
3482 ASSERT (result
!= NULL
);
3483 ASSERT (wcscmp (result
, L
" 1.75 33") == 0);
3484 ASSERT (length
== wcslen (result
));
3488 { /* Width given as argument. */
3491 my_asnwprintf (NULL
, &length
, L
"%*Lg %d", 10, 1.75L, 33, 44, 55);
3492 ASSERT (result
!= NULL
);
3493 ASSERT (wcscmp (result
, L
" 1.75 33") == 0);
3494 ASSERT (length
== wcslen (result
));
3498 { /* Negative width given as argument (cf. FLAG_LEFT below). */
3501 my_asnwprintf (NULL
, &length
, L
"%*Lg %d", -10, 1.75L, 33, 44, 55);
3502 ASSERT (result
!= NULL
);
3503 ASSERT (wcscmp (result
, L
"1.75 33") == 0);
3504 ASSERT (length
== wcslen (result
));
3511 my_asnwprintf (NULL
, &length
, L
"%-10Lg %d", 1.75L, 33, 44, 55);
3512 ASSERT (result
!= NULL
);
3513 ASSERT (wcscmp (result
, L
"1.75 33") == 0);
3514 ASSERT (length
== wcslen (result
));
3518 { /* FLAG_SHOWSIGN. */
3521 my_asnwprintf (NULL
, &length
, L
"%+Lg %d", 1.75L, 33, 44, 55);
3522 ASSERT (result
!= NULL
);
3523 ASSERT (wcscmp (result
, L
"+1.75 33") == 0);
3524 ASSERT (length
== wcslen (result
));
3531 my_asnwprintf (NULL
, &length
, L
"% Lg %d", 1.75L, 33, 44, 55);
3532 ASSERT (result
!= NULL
);
3533 ASSERT (wcscmp (result
, L
" 1.75 33") == 0);
3534 ASSERT (length
== wcslen (result
));
3541 my_asnwprintf (NULL
, &length
, L
"%#Lg %d", 1.75L, 33, 44, 55);
3542 ASSERT (result
!= NULL
);
3543 ASSERT (wcscmp (result
, L
"1.75000 33") == 0);
3544 ASSERT (length
== wcslen (result
));
3551 my_asnwprintf (NULL
, &length
, L
"%#.Lg %d", 1.75L, 33, 44, 55);
3552 ASSERT (result
!= NULL
);
3553 ASSERT (wcscmp (result
, L
"2. 33") == 0);
3554 ASSERT (length
== wcslen (result
));
3561 my_asnwprintf (NULL
, &length
, L
"%#.Lg %d", 9.75L, 33, 44, 55);
3562 ASSERT (result
!= NULL
);
3563 ASSERT (wcscmp (result
, L
"1.e+01 33") == 0
3564 || wcscmp (result
, L
"1.e+001 33") == 0);
3565 ASSERT (length
== wcslen (result
));
3569 { /* FLAG_ZERO with finite number. */
3572 my_asnwprintf (NULL
, &length
, L
"%010Lg %d", 1234.0L, 33, 44, 55);
3573 ASSERT (result
!= NULL
);
3574 ASSERT (wcscmp (result
, L
"0000001234 33") == 0);
3575 ASSERT (length
== wcslen (result
));
3579 { /* FLAG_ZERO with infinite number. */
3582 my_asnwprintf (NULL
, &length
, L
"%015Lg %d", - Infinityl (), 33, 44, 55);
3583 ASSERT (result
!= NULL
);
3584 ASSERT (wcscmp (result
, L
" -inf 33") == 0
3585 || wcscmp (result
, L
" -infinity 33") == 0);
3586 ASSERT (length
== wcslen (result
));
3590 { /* FLAG_ZERO with NaN. */
3593 my_asnwprintf (NULL
, &length
, L
"%050Lg %d", NaNl (), 33, 44, 55);
3594 ASSERT (result
!= NULL
);
3595 ASSERT (wcslen (result
) == 50 + 3
3596 && wcsisnan (result
, wcsspn (result
, L
" "), wcslen (result
) - 3, 0)
3597 && wcscmp (result
+ wcslen (result
) - 3, L
" 33") == 0);
3598 ASSERT (length
== wcslen (result
));
3605 my_asnwprintf (NULL
, &length
, L
"%.Lg %d", 1234.0L, 33, 44, 55);
3606 ASSERT (result
!= NULL
);
3607 ASSERT (wcscmp (result
, L
"1e+03 33") == 0
3608 || wcscmp (result
, L
"1e+003 33") == 0);
3609 ASSERT (length
== wcslen (result
));
3613 { /* Precision with no rounding. */
3616 my_asnwprintf (NULL
, &length
, L
"%.5Lg %d", 999.951L, 33, 44, 55);
3617 ASSERT (result
!= NULL
);
3618 ASSERT (wcscmp (result
, L
"999.95 33") == 0);
3619 ASSERT (length
== wcslen (result
));
3623 { /* Precision with rounding. */
3626 my_asnwprintf (NULL
, &length
, L
"%.5Lg %d", 999.996L, 33, 44, 55);
3627 ASSERT (result
!= NULL
);
3628 ASSERT (wcscmp (result
, L
"1000 33") == 0);
3629 ASSERT (length
== wcslen (result
));
3633 #if NEED_PRINTF_WITH_N_DIRECTIVE
3634 /* Test the support of the %n format directive. */
3640 my_asnwprintf (NULL
, &length
, L
"%d %n", 123, &count
, 33, 44, 55);
3641 ASSERT (result
!= NULL
);
3642 ASSERT (wcscmp (result
, L
"123 ") == 0);
3643 ASSERT (length
== wcslen (result
));
3644 ASSERT (count
== 4);
3649 /* Test the support of the POSIX/XSI format strings with positions. */
3654 my_asnwprintf (NULL
, &length
, L
"%2$d %1$d", 33, 55);
3655 ASSERT (result
!= NULL
);
3656 ASSERT (wcscmp (result
, L
"55 33") == 0);
3657 ASSERT (length
== wcslen (result
));
3661 /* Test the support of the grouping flag. */
3666 my_asnwprintf (NULL
, &length
, L
"%'d %d", 1234567, 99);
3667 ASSERT (result
!= NULL
);
3668 ASSERT (result
[wcslen (result
) - 1] == '9');
3669 ASSERT (length
== wcslen (result
));
3673 /* Test the support of the left-adjust flag. */
3678 my_asnwprintf (NULL
, &length
, L
"a%*sc", -3, "b");
3679 ASSERT (result
!= NULL
);
3680 ASSERT (wcscmp (result
, L
"ab c") == 0);
3681 ASSERT (length
== wcslen (result
));
3688 my_asnwprintf (NULL
, &length
, L
"a%-*sc", 3, "b");
3689 ASSERT (result
!= NULL
);
3690 ASSERT (wcscmp (result
, L
"ab c") == 0);
3691 ASSERT (length
== wcslen (result
));
3698 my_asnwprintf (NULL
, &length
, L
"a%-*sc", -3, "b");
3699 ASSERT (result
!= NULL
);
3700 ASSERT (wcscmp (result
, L
"ab c") == 0);
3701 ASSERT (length
== wcslen (result
));
3705 /* Test the support of large precision. */
3710 my_asnwprintf (NULL
, &length
, L
"%.4000d %d", 1234567, 99);
3712 ASSERT (result
!= NULL
);
3713 for (i
= 0; i
< 4000 - 7; i
++)
3714 ASSERT (result
[i
] == '0');
3715 ASSERT (wcscmp (result
+ 4000 - 7, L
"1234567 99") == 0);
3716 ASSERT (length
== wcslen (result
));
3723 my_asnwprintf (NULL
, &length
, L
"%.*d %d", 4000, 1234567, 99);
3725 ASSERT (result
!= NULL
);
3726 for (i
= 0; i
< 4000 - 7; i
++)
3727 ASSERT (result
[i
] == '0');
3728 ASSERT (wcscmp (result
+ 4000 - 7, L
"1234567 99") == 0);
3729 ASSERT (length
== wcslen (result
));
3736 my_asnwprintf (NULL
, &length
, L
"%.4000d %d", -1234567, 99);
3738 ASSERT (result
!= NULL
);
3739 ASSERT (result
[0] == '-');
3740 for (i
= 0; i
< 4000 - 7; i
++)
3741 ASSERT (result
[1 + i
] == '0');
3742 ASSERT (wcscmp (result
+ 1 + 4000 - 7, L
"1234567 99") == 0);
3743 ASSERT (length
== wcslen (result
));
3750 my_asnwprintf (NULL
, &length
, L
"%.4000u %d", 1234567, 99);
3752 ASSERT (result
!= NULL
);
3753 for (i
= 0; i
< 4000 - 7; i
++)
3754 ASSERT (result
[i
] == '0');
3755 ASSERT (wcscmp (result
+ 4000 - 7, L
"1234567 99") == 0);
3756 ASSERT (length
== wcslen (result
));
3763 my_asnwprintf (NULL
, &length
, L
"%.4000o %d", 1234567, 99);
3765 ASSERT (result
!= NULL
);
3766 for (i
= 0; i
< 4000 - 7; i
++)
3767 ASSERT (result
[i
] == '0');
3768 ASSERT (wcscmp (result
+ 4000 - 7, L
"4553207 99") == 0);
3769 ASSERT (length
== wcslen (result
));
3776 my_asnwprintf (NULL
, &length
, L
"%.4000x %d", 1234567, 99);
3778 ASSERT (result
!= NULL
);
3779 for (i
= 0; i
< 4000 - 6; i
++)
3780 ASSERT (result
[i
] == '0');
3781 ASSERT (wcscmp (result
+ 4000 - 6, L
"12d687 99") == 0);
3782 ASSERT (length
== wcslen (result
));
3789 my_asnwprintf (NULL
, &length
, L
"%#.4000x %d", 1234567, 99);
3791 ASSERT (result
!= NULL
);
3792 ASSERT (result
[0] == '0');
3793 ASSERT (result
[1] == 'x');
3794 for (i
= 0; i
< 4000 - 6; i
++)
3795 ASSERT (result
[2 + i
] == '0');
3796 ASSERT (wcscmp (result
+ 2 + 4000 - 6, L
"12d687 99") == 0);
3797 ASSERT (length
== wcslen (result
));
3804 my_asnwprintf (NULL
, &length
, L
"%.4000f %d", 1.0, 99);
3806 ASSERT (result
!= NULL
);
3807 ASSERT (result
[0] == '1');
3808 ASSERT (result
[1] == '.');
3809 for (i
= 0; i
< 4000; i
++)
3810 ASSERT (result
[2 + i
] == '0');
3811 ASSERT (wcscmp (result
+ 2 + 4000, L
" 99") == 0);
3812 ASSERT (length
== wcslen (result
));
3819 my_asnwprintf (NULL
, &length
, L
"%.511f %d", 1.0, 99);
3821 ASSERT (result
!= NULL
);
3822 ASSERT (result
[0] == '1');
3823 ASSERT (result
[1] == '.');
3824 for (i
= 0; i
< 511; i
++)
3825 ASSERT (result
[2 + i
] == '0');
3826 ASSERT (wcscmp (result
+ 2 + 511, L
" 99") == 0);
3827 ASSERT (length
== wcslen (result
));
3835 wchar_t winput
[5000];
3838 for (i
= 0; i
< sizeof (input
) - 1; i
++)
3839 input
[i
] = 'a' + ((1000000 / (i
+ 1)) % 26);
3841 result
= my_asnwprintf (NULL
, &length
, L
"%.4000s %d", input
, 99);
3842 ASSERT (result
!= NULL
);
3843 for (i
= 0; i
< sizeof (input
); i
++)
3844 winput
[i
] = (wchar_t) input
[i
];
3845 ASSERT (wmemcmp (result
, winput
, 4000) == 0);
3846 ASSERT (wcscmp (result
+ 4000, L
" 99") == 0);
3847 ASSERT (length
== wcslen (result
));
3851 /* Test the support of the %s format directive. */
3856 my_asnwprintf (NULL
, &length
, L
"%10s %d", "xyz", 33, 44, 55);
3857 ASSERT (result
!= NULL
);
3858 ASSERT (wcscmp (result
, L
" xyz 33") == 0);
3859 ASSERT (length
== wcslen (result
));
3863 { /* Width given as argument. */
3866 my_asnwprintf (NULL
, &length
, L
"%*s %d", 10, "xyz", 33, 44, 55);
3867 ASSERT (result
!= NULL
);
3868 ASSERT (wcscmp (result
, L
" xyz 33") == 0);
3869 ASSERT (length
== wcslen (result
));
3873 { /* Negative width given as argument (cf. FLAG_LEFT below). */
3876 my_asnwprintf (NULL
, &length
, L
"%*s %d", -10, "xyz", 33, 44, 55);
3877 ASSERT (result
!= NULL
);
3878 ASSERT (wcscmp (result
, L
"xyz 33") == 0);
3879 ASSERT (length
== wcslen (result
));
3886 my_asnwprintf (NULL
, &length
, L
"%-10s %d", "xyz", 33, 44, 55);
3887 ASSERT (result
!= NULL
);
3888 ASSERT (wcscmp (result
, L
"xyz 33") == 0);
3889 ASSERT (length
== wcslen (result
));
3893 /* On Android ≥ 5.0, the default locale is the "C.UTF-8" locale, not the
3894 "C" locale. Furthermore, when you attempt to set the "C" or "POSIX"
3895 locale via setlocale(), what you get is a "C" locale with UTF-8 encoding,
3896 that is, effectively the "C.UTF-8" locale. */
3898 { /* The conversion of %s to wide characters is done as if through repeated
3899 invocations of mbrtowc(), and in the "C" and "POSIX" locales, "an
3900 [EILSEQ] error cannot occur since all byte values are valid characters",
3904 for (c
= 0; c
< 0x100; c
++)
3906 char s
[2] = { c
, '\0' };
3908 wchar_t *result
= my_asnwprintf (NULL
, &length
, L
"%s", s
);
3909 ASSERT (result
!= NULL
);
3916 static wchar_t L_xyz
[4] = { 'x', 'y', 'z', 0 };
3921 my_asnwprintf (NULL
, &length
, L
"%10ls %d", L_xyz
, 33, 44, 55);
3922 ASSERT (result
!= NULL
);
3923 ASSERT (wcscmp (result
, L
" xyz 33") == 0);
3924 ASSERT (length
== wcslen (result
));
3928 { /* Width given as argument. */
3931 my_asnwprintf (NULL
, &length
, L
"%*ls %d", 10, L_xyz
, 33, 44, 55);
3932 ASSERT (result
!= NULL
);
3933 ASSERT (wcscmp (result
, L
" xyz 33") == 0);
3934 ASSERT (length
== wcslen (result
));
3938 { /* Negative width given as argument (cf. FLAG_LEFT below). */
3941 my_asnwprintf (NULL
, &length
, L
"%*ls %d", -10, L_xyz
, 33, 44, 55);
3942 ASSERT (result
!= NULL
);
3943 ASSERT (wcscmp (result
, L
"xyz 33") == 0);
3944 ASSERT (length
== wcslen (result
));
3951 my_asnwprintf (NULL
, &length
, L
"%-10ls %d", L_xyz
, 33, 44, 55);
3952 ASSERT (result
!= NULL
);
3953 ASSERT (wcscmp (result
, L
"xyz 33") == 0);
3954 ASSERT (length
== wcslen (result
));
3959 /* To verify that these tests succeed, it is necessary to run them under
3960 a tool that checks against invalid memory accesses, such as ElectricFence
3961 or "valgrind --tool=memcheck". */
3965 for (i
= 1; i
<= 8; i
++)
3973 block
= (char *) malloc (i
);
3974 memcpy (block
, "abcdefgh", i
);
3975 result
= my_asnwprintf (NULL
, &length
, L
"%.*s", (int) i
, block
);
3976 ASSERT (result
!= NULL
);
3977 wblock
= (wchar_t *) malloc (i
* sizeof (wchar_t));
3978 for (j
= 0; j
< i
; j
++)
3979 wblock
[j
] = (wchar_t) block
[j
];
3980 ASSERT (wmemcmp (result
, wblock
, i
) == 0);
3981 ASSERT (result
[i
] == '\0');
3982 ASSERT (length
== wcslen (result
));
3991 for (i
= 1; i
<= 8; i
++)
3998 block
= (wchar_t *) malloc (i
* sizeof (wchar_t));
3999 for (j
= 0; j
< i
; j
++)
4000 block
[j
] = "abcdefgh"[j
];
4001 result
= my_asnwprintf (NULL
, &length
, L
"%.*ls", (int) i
, block
);
4002 ASSERT (result
!= NULL
);
4003 ASSERT (wmemcmp (result
, L
"abcdefgh", i
) == 0);
4004 ASSERT (result
[i
] == '\0');
4005 ASSERT (length
== wcslen (result
));
4013 /* Test that converting an invalid wchar_t[] to char[] fails with EILSEQ. */
4015 static const wchar_t input
[] = { (wchar_t) 1702057263, 114, 0 };
4017 wchar_t *result
= my_asnwprintf (NULL
, &length
, L
"%ls %d", input
, 99);
4019 ASSERT (errno
== EILSEQ
);
4024 static const wchar_t input
[] = { (wchar_t) 1702057263, 114, 0 };
4026 wchar_t *result
= my_asnwprintf (NULL
, &length
, L
"%3ls %d", input
, 99);
4028 ASSERT (errno
== EILSEQ
);
4033 static const wchar_t input
[] = { (wchar_t) 1702057263, 114, 0 };
4035 wchar_t *result
= my_asnwprintf (NULL
, &length
, L
"%.1ls %d", input
, 99);
4037 ASSERT (errno
== EILSEQ
);
4042 static const wchar_t input
[] = { (wchar_t) 1702057263, 114, 0 };
4044 wchar_t *result
= my_asnwprintf (NULL
, &length
, L
"%3.1ls %d", input
, 99);
4046 ASSERT (errno
== EILSEQ
);
4052 /* Test the support of the %c format directive. */
4057 my_asnwprintf (NULL
, &length
,
4058 L
"%10c %d", (unsigned char) 'x', 33, 44, 55);
4059 ASSERT (result
!= NULL
);
4060 ASSERT (wcscmp (result
, L
" x 33") == 0);
4061 ASSERT (length
== wcslen (result
));
4065 { /* Width given as argument. */
4068 my_asnwprintf (NULL
, &length
,
4069 L
"%*c %d", 10, (unsigned char) 'x', 33, 44, 55);
4070 ASSERT (result
!= NULL
);
4071 ASSERT (wcscmp (result
, L
" x 33") == 0);
4072 ASSERT (length
== wcslen (result
));
4076 { /* Negative width given as argument (cf. FLAG_LEFT below). */
4079 my_asnwprintf (NULL
, &length
,
4080 L
"%*c %d", -10, (unsigned char) 'x', 33, 44, 55);
4081 ASSERT (result
!= NULL
);
4082 ASSERT (wcscmp (result
, L
"x 33") == 0);
4083 ASSERT (length
== wcslen (result
));
4090 my_asnwprintf (NULL
, &length
,
4091 L
"%-10c %d", (unsigned char) 'x', 33, 44, 55);
4092 ASSERT (result
!= NULL
);
4093 ASSERT (wcscmp (result
, L
"x 33") == 0);
4094 ASSERT (length
== wcslen (result
));
4098 { /* Precision is ignored. */
4101 my_asnwprintf (NULL
, &length
,
4102 L
"%.0c %d", (unsigned char) 'x', 33, 44, 55);
4103 ASSERT (wcscmp (result
, L
"x 33") == 0);
4104 ASSERT (length
== wcslen (result
));
4108 { /* NUL character. */
4111 my_asnwprintf (NULL
, &length
,
4112 L
"a%cz %d", '\0', 33, 44, 55);
4113 ASSERT (wmemcmp (result
, L
"a\0z 33\0", 6 + 1) == 0);
4114 ASSERT (length
== 6);
4118 /* On Android ≥ 5.0, the default locale is the "C.UTF-8" locale, not the
4119 "C" locale. Furthermore, when you attempt to set the "C" or "POSIX"
4120 locale via setlocale(), what you get is a "C" locale with UTF-8 encoding,
4121 that is, effectively the "C.UTF-8" locale. */
4123 { /* The conversion of %c to wide character is done as if through btowc(),
4124 and in the "C" and "POSIX" locales, "btowc() shall not return WEOF if
4125 c has a value in the range 0 to 255 inclusive", says POSIX:2018. */
4128 for (c
= 0; c
< 0x100; c
++)
4131 wchar_t *result
= my_asnwprintf (NULL
, &length
, L
"%c", c
);
4132 ASSERT (result
!= NULL
);
4139 static wint_t L_x
= (wchar_t) 'x';
4144 my_asnwprintf (NULL
, &length
, L
"%10lc %d", L_x
, 33, 44, 55);
4145 ASSERT (result
!= NULL
);
4146 ASSERT (wcscmp (result
, L
" x 33") == 0);
4147 ASSERT (length
== wcslen (result
));
4151 { /* Width given as argument. */
4154 my_asnwprintf (NULL
, &length
, L
"%*lc %d", 10, L_x
, 33, 44, 55);
4155 ASSERT (result
!= NULL
);
4156 ASSERT (wcscmp (result
, L
" x 33") == 0);
4157 ASSERT (length
== wcslen (result
));
4161 { /* Negative width given as argument (cf. FLAG_LEFT below). */
4164 my_asnwprintf (NULL
, &length
, L
"%*lc %d", -10, L_x
, 33, 44, 55);
4165 ASSERT (result
!= NULL
);
4166 ASSERT (wcscmp (result
, L
"x 33") == 0);
4167 ASSERT (length
== wcslen (result
));
4174 my_asnwprintf (NULL
, &length
, L
"%-10lc %d", L_x
, 33, 44, 55);
4175 ASSERT (result
!= NULL
);
4176 ASSERT (wcscmp (result
, L
"x 33") == 0);
4177 ASSERT (length
== wcslen (result
));
4181 { /* Precision is ignored. */
4184 my_asnwprintf (NULL
, &length
, L
"%.0lc %d", L_x
, 33, 44, 55);
4185 ASSERT (wcscmp (result
, L
"x 33") == 0);
4186 ASSERT (length
== wcslen (result
));
4190 { /* NUL character. */
4193 my_asnwprintf (NULL
, &length
, L
"a%lcz %d", (wint_t) L
'\0', 33, 44, 55);
4194 ASSERT (wmemcmp (result
, L
"a\0z 33\0", 6 + 1) == 0);
4195 ASSERT (length
== 6);
4199 static wint_t L_invalid
= (wchar_t) 0x76543210;
4201 { /* Invalid wide character. */
4204 my_asnwprintf (NULL
, &length
, L
"%lc %d", L_invalid
, 33, 44, 55);
4205 /* No failure is allowed: ISO C says "the wint_t argument is converted
4206 to wchar_t and written." */
4207 ASSERT (result
!= NULL
);
4208 ASSERT (result
[0] == (wchar_t) 0x76543210);
4209 ASSERT (wmemcmp (result
+ 1, L
" 33\0", 3 + 1) == 0);
4210 ASSERT (length
== 4);
4214 { /* Invalid wide character and width. */
4217 my_asnwprintf (NULL
, &length
, L
"%10lc %d", L_invalid
, 33, 44, 55);
4218 /* No failure is allowed: ISO C says "the wint_t argument is converted
4219 to wchar_t and written." */
4220 ASSERT (result
!= NULL
);
4221 ASSERT (wmemcmp (result
, L
" ", 9) == 0);
4222 ASSERT (result
[9] == (wchar_t) 0x76543210);
4223 ASSERT (wmemcmp (result
+ 10, L
" 33\0", 3 + 1) == 0);
4224 ASSERT (length
== 13);
4229 /* Test the support of the 'x' conversion specifier for hexadecimal output of
4235 my_asnwprintf (NULL
, &length
, L
"%x %d", 0, 33, 44, 55);
4236 ASSERT (result
!= NULL
);
4237 ASSERT (wcscmp (result
, L
"0 33") == 0);
4238 ASSERT (length
== wcslen (result
));
4242 { /* A positive number. */
4245 my_asnwprintf (NULL
, &length
, L
"%x %d", 12348, 33, 44, 55);
4246 ASSERT (result
!= NULL
);
4247 ASSERT (wcscmp (result
, L
"303c 33") == 0);
4248 ASSERT (length
== wcslen (result
));
4252 { /* A large positive number. */
4255 my_asnwprintf (NULL
, &length
, L
"%x %d", 0xFFFFFFFEU
, 33, 44, 55);
4256 ASSERT (result
!= NULL
);
4257 ASSERT (wcscmp (result
, L
"fffffffe 33") == 0);
4258 ASSERT (length
== wcslen (result
));
4265 my_asnwprintf (NULL
, &length
, L
"%10x %d", 12348, 33, 44, 55);
4266 ASSERT (result
!= NULL
);
4267 ASSERT (wcscmp (result
, L
" 303c 33") == 0);
4268 ASSERT (length
== wcslen (result
));
4272 { /* Width given as argument. */
4275 my_asnwprintf (NULL
, &length
, L
"%*x %d", 10, 12348, 33, 44, 55);
4276 ASSERT (result
!= NULL
);
4277 ASSERT (wcscmp (result
, L
" 303c 33") == 0);
4278 ASSERT (length
== wcslen (result
));
4282 { /* Negative width given as argument (cf. FLAG_LEFT below). */
4285 my_asnwprintf (NULL
, &length
, L
"%*x %d", -10, 12348, 33, 44, 55);
4286 ASSERT (result
!= NULL
);
4287 ASSERT (wcscmp (result
, L
"303c 33") == 0);
4288 ASSERT (length
== wcslen (result
));
4295 my_asnwprintf (NULL
, &length
, L
"%.10x %d", 12348, 33, 44, 55);
4296 ASSERT (result
!= NULL
);
4297 ASSERT (wcscmp (result
, L
"000000303c 33") == 0);
4298 ASSERT (length
== wcslen (result
));
4302 { /* Zero precision and a positive number. */
4305 my_asnwprintf (NULL
, &length
, L
"%.0x %d", 12348, 33, 44, 55);
4306 ASSERT (result
!= NULL
);
4307 ASSERT (wcscmp (result
, L
"303c 33") == 0);
4308 ASSERT (length
== wcslen (result
));
4312 { /* Zero precision and a zero number. */
4315 my_asnwprintf (NULL
, &length
, L
"%.0x %d", 0, 33, 44, 55);
4316 ASSERT (result
!= NULL
);
4317 /* ISO C and POSIX specify that "The result of converting a zero value
4318 with a precision of zero is no characters." */
4319 ASSERT (wcscmp (result
, L
" 33") == 0);
4320 ASSERT (length
== wcslen (result
));
4324 { /* Width and precision. */
4327 my_asnwprintf (NULL
, &length
, L
"%15.10x %d", 12348, 33, 44, 55);
4328 ASSERT (result
!= NULL
);
4329 ASSERT (wcscmp (result
, L
" 000000303c 33") == 0);
4330 ASSERT (length
== wcslen (result
));
4334 { /* Padding and precision. */
4337 my_asnwprintf (NULL
, &length
, L
"%015.10x %d", 12348, 33, 44, 55);
4338 ASSERT (result
!= NULL
);
4339 /* ISO C 99 § 7.24.2.1.(6) says: "For d, i, o, u, x, and X conversions, if a
4340 precision is specified, the 0 flag is ignored." */
4341 ASSERT (wcscmp (result
, L
" 000000303c 33") == 0);
4342 ASSERT (length
== wcslen (result
));
4349 my_asnwprintf (NULL
, &length
, L
"%-10x %d", 12348, 33, 44, 55);
4350 ASSERT (result
!= NULL
);
4351 ASSERT (wcscmp (result
, L
"303c 33") == 0);
4352 ASSERT (length
== wcslen (result
));
4356 { /* FLAG_ALT with zero. */
4359 my_asnwprintf (NULL
, &length
, L
"%#x %d", 0, 33, 44, 55);
4360 ASSERT (result
!= NULL
);
4361 ASSERT (wcscmp (result
, L
"0 33") == 0);
4362 ASSERT (length
== wcslen (result
));
4366 { /* FLAG_ALT with a positive number. */
4369 my_asnwprintf (NULL
, &length
, L
"%#x %d", 12348, 33, 44, 55);
4370 ASSERT (result
!= NULL
);
4371 ASSERT (wcscmp (result
, L
"0x303c 33") == 0);
4372 ASSERT (length
== wcslen (result
));
4376 { /* FLAG_ALT with a positive number and width. */
4379 my_asnwprintf (NULL
, &length
, L
"%#10x %d", 12348, 33, 44, 55);
4380 ASSERT (result
!= NULL
);
4381 ASSERT (wcscmp (result
, L
" 0x303c 33") == 0);
4382 ASSERT (length
== wcslen (result
));
4386 { /* FLAG_ALT with a positive number and padding. */
4389 my_asnwprintf (NULL
, &length
, L
"%0#10x %d", 12348, 33, 44, 55);
4390 ASSERT (result
!= NULL
);
4391 ASSERT (wcscmp (result
, L
"0x0000303c 33") == 0);
4392 ASSERT (length
== wcslen (result
));
4396 { /* FLAG_ALT with a positive number and precision. */
4399 my_asnwprintf (NULL
, &length
, L
"%0#.10x %d", 12348, 33, 44, 55);
4400 ASSERT (result
!= NULL
);
4401 ASSERT (wcscmp (result
, L
"0x000000303c 33") == 0);
4402 ASSERT (length
== wcslen (result
));
4406 { /* FLAG_ALT with a positive number and width and precision. */
4409 my_asnwprintf (NULL
, &length
, L
"%#15.10x %d", 12348, 33, 44, 55);
4410 ASSERT (result
!= NULL
);
4411 ASSERT (wcscmp (result
, L
" 0x000000303c 33") == 0);
4412 ASSERT (length
== wcslen (result
));
4416 { /* FLAG_ALT with a positive number and padding and precision. */
4419 my_asnwprintf (NULL
, &length
, L
"%0#15.10x %d", 12348, 33, 44, 55);
4420 ASSERT (result
!= NULL
);
4421 /* ISO C 99 § 7.24.2.1.(6) says: "For d, i, o, u, x, and X conversions, if a
4422 precision is specified, the 0 flag is ignored." */
4423 ASSERT (wcscmp (result
, L
" 0x000000303c 33") == 0);
4424 ASSERT (length
== wcslen (result
));
4428 { /* FLAG_ALT with a zero precision and a zero number. */
4431 my_asnwprintf (NULL
, &length
, L
"%#.0x %d", 0, 33, 44, 55);
4432 ASSERT (result
!= NULL
);
4433 /* ISO C and POSIX specify that "The result of converting a zero value
4434 with a precision of zero is no characters.", and the prefix is added
4435 only for non-zero values. */
4436 ASSERT (wcscmp (result
, L
" 33") == 0);
4437 ASSERT (length
== wcslen (result
));
4441 { /* Uppercase 'X'. */
4444 my_asnwprintf (NULL
, &length
, L
"%X %d", 12348, 33, 44, 55);
4445 ASSERT (result
!= NULL
);
4446 ASSERT (wcscmp (result
, L
"303C 33") == 0);
4447 ASSERT (length
== wcslen (result
));
4451 { /* Uppercase 'X' with FLAG_ALT. */
4454 my_asnwprintf (NULL
, &length
, L
"%#X %d", 12348, 33, 44, 55);
4455 ASSERT (result
!= NULL
);
4456 ASSERT (wcscmp (result
, L
"0X303C 33") == 0);
4457 ASSERT (length
== wcslen (result
));
4461 { /* Uppercase 'X' with FLAG_ALT and zero precision and a zero number. */
4464 my_asnwprintf (NULL
, &length
, L
"%#.0X %d", 0, 33, 44, 55);
4465 ASSERT (result
!= NULL
);
4466 /* ISO C and POSIX specify that "The result of converting a zero value
4467 with a precision of zero is no characters.", and the prefix is added
4468 only for non-zero values. */
4469 ASSERT (wcscmp (result
, L
" 33") == 0);
4470 ASSERT (length
== wcslen (result
));
4474 /* Test the support of the 'b' conversion specifier for binary output of
4480 my_asnwprintf (NULL
, &length
, L
"%b %d", 0, 33, 44, 55);
4481 ASSERT (result
!= NULL
);
4482 ASSERT (wcscmp (result
, L
"0 33") == 0);
4483 ASSERT (length
== wcslen (result
));
4487 { /* A positive number. */
4490 my_asnwprintf (NULL
, &length
, L
"%b %d", 12345, 33, 44, 55);
4491 ASSERT (result
!= NULL
);
4492 ASSERT (wcscmp (result
, L
"11000000111001 33") == 0);
4493 ASSERT (length
== wcslen (result
));
4497 { /* A large positive number. */
4500 my_asnwprintf (NULL
, &length
, L
"%b %d", 0xFFFFFFFEU
, 33, 44, 55);
4501 ASSERT (result
!= NULL
);
4502 ASSERT (wcscmp (result
, L
"11111111111111111111111111111110 33") == 0);
4503 ASSERT (length
== wcslen (result
));
4510 my_asnwprintf (NULL
, &length
, L
"%20b %d", 12345, 33, 44, 55);
4511 ASSERT (result
!= NULL
);
4512 ASSERT (wcscmp (result
, L
" 11000000111001 33") == 0);
4513 ASSERT (length
== wcslen (result
));
4517 { /* Width given as argument. */
4520 my_asnwprintf (NULL
, &length
, L
"%*b %d", 20, 12345, 33, 44, 55);
4521 ASSERT (result
!= NULL
);
4522 ASSERT (wcscmp (result
, L
" 11000000111001 33") == 0);
4523 ASSERT (length
== wcslen (result
));
4527 { /* Negative width given as argument (cf. FLAG_LEFT below). */
4530 my_asnwprintf (NULL
, &length
, L
"%*b %d", -20, 12345, 33, 44, 55);
4531 ASSERT (result
!= NULL
);
4532 ASSERT (wcscmp (result
, L
"11000000111001 33") == 0);
4533 ASSERT (length
== wcslen (result
));
4540 my_asnwprintf (NULL
, &length
, L
"%.20b %d", 12345, 33, 44, 55);
4541 ASSERT (result
!= NULL
);
4542 ASSERT (wcscmp (result
, L
"00000011000000111001 33") == 0);
4543 ASSERT (length
== wcslen (result
));
4547 { /* Zero precision and a positive number. */
4550 my_asnwprintf (NULL
, &length
, L
"%.0b %d", 12345, 33, 44, 55);
4551 ASSERT (result
!= NULL
);
4552 ASSERT (wcscmp (result
, L
"11000000111001 33") == 0);
4553 ASSERT (length
== wcslen (result
));
4557 { /* Zero precision and a zero number. */
4560 my_asnwprintf (NULL
, &length
, L
"%.0b %d", 0, 33, 44, 55);
4561 ASSERT (result
!= NULL
);
4562 /* ISO C and POSIX specify that "The result of converting a zero value
4563 with a precision of zero is no characters." */
4564 ASSERT (wcscmp (result
, L
" 33") == 0);
4565 ASSERT (length
== wcslen (result
));
4569 { /* Width and precision. */
4572 my_asnwprintf (NULL
, &length
, L
"%25.20b %d", 12345, 33, 44, 55);
4573 ASSERT (result
!= NULL
);
4574 ASSERT (wcscmp (result
, L
" 00000011000000111001 33") == 0);
4575 ASSERT (length
== wcslen (result
));
4579 { /* Padding and precision. */
4582 my_asnwprintf (NULL
, &length
, L
"%025.20b %d", 12345, 33, 44, 55);
4583 ASSERT (result
!= NULL
);
4584 /* Neither ISO C nor POSIX specify that the '0' flag is ignored when
4585 a width and a precision are both present. But implementations do so. */
4586 ASSERT (wcscmp (result
, L
" 00000011000000111001 33") == 0);
4587 ASSERT (length
== wcslen (result
));
4594 my_asnwprintf (NULL
, &length
, L
"%-20b %d", 12345, 33, 44, 55);
4595 ASSERT (result
!= NULL
);
4596 ASSERT (wcscmp (result
, L
"11000000111001 33") == 0);
4597 ASSERT (length
== wcslen (result
));
4601 { /* FLAG_ALT with zero. */
4604 my_asnwprintf (NULL
, &length
, L
"%#b %d", 0, 33, 44, 55);
4605 ASSERT (result
!= NULL
);
4606 ASSERT (wcscmp (result
, L
"0 33") == 0);
4607 ASSERT (length
== wcslen (result
));
4611 { /* FLAG_ALT with a positive number. */
4614 my_asnwprintf (NULL
, &length
, L
"%#b %d", 12345, 33, 44, 55);
4615 ASSERT (result
!= NULL
);
4616 ASSERT (wcscmp (result
, L
"0b11000000111001 33") == 0);
4617 ASSERT (length
== wcslen (result
));
4621 { /* FLAG_ALT with a positive number and width. */
4624 my_asnwprintf (NULL
, &length
, L
"%#20b %d", 12345, 33, 44, 55);
4625 ASSERT (result
!= NULL
);
4626 ASSERT (wcscmp (result
, L
" 0b11000000111001 33") == 0);
4627 ASSERT (length
== wcslen (result
));
4631 { /* FLAG_ALT with a positive number and padding. */
4634 my_asnwprintf (NULL
, &length
, L
"%0#20b %d", 12345, 33, 44, 55);
4635 ASSERT (result
!= NULL
);
4636 ASSERT (wcscmp (result
, L
"0b000011000000111001 33") == 0);
4637 ASSERT (length
== wcslen (result
));
4641 { /* FLAG_ALT with a positive number and precision. */
4644 my_asnwprintf (NULL
, &length
, L
"%0#.20b %d", 12345, 33, 44, 55);
4645 ASSERT (result
!= NULL
);
4646 ASSERT (wcscmp (result
, L
"0b00000011000000111001 33") == 0);
4647 ASSERT (length
== wcslen (result
));
4651 { /* FLAG_ALT with a positive number and width and precision. */
4654 my_asnwprintf (NULL
, &length
, L
"%#25.20b %d", 12345, 33, 44, 55);
4655 ASSERT (result
!= NULL
);
4656 ASSERT (wcscmp (result
, L
" 0b00000011000000111001 33") == 0);
4657 ASSERT (length
== wcslen (result
));
4661 { /* FLAG_ALT with a positive number and padding and precision. */
4664 my_asnwprintf (NULL
, &length
, L
"%0#25.20b %d", 12345, 33, 44, 55);
4665 ASSERT (result
!= NULL
);
4666 /* Neither ISO C nor POSIX specify that the '0' flag is ignored when
4667 a width and a precision are both present. But implementations do so. */
4668 ASSERT (wcscmp (result
, L
" 0b00000011000000111001 33") == 0);
4669 ASSERT (length
== wcslen (result
));
4673 { /* FLAG_ALT with a zero precision and a zero number. */
4676 my_asnwprintf (NULL
, &length
, L
"%#.0b %d", 0, 33, 44, 55);
4677 ASSERT (result
!= NULL
);
4678 /* ISO C and POSIX specify that "The result of converting a zero value
4679 with a precision of zero is no characters.", and the prefix is added
4680 only for non-zero values. */
4681 ASSERT (wcscmp (result
, L
" 33") == 0);
4682 ASSERT (length
== wcslen (result
));
4686 /* Test the support of argument type/size specifiers for signed integer
4692 my_asnwprintf (NULL
, &length
, L
"%hhd %d", (signed char) -42, 33, 44, 55);
4693 ASSERT (wcscmp (result
, L
"-42 33") == 0);
4694 ASSERT (length
== wcslen (result
));
4701 my_asnwprintf (NULL
, &length
, L
"%hd %d", (short) -12345, 33, 44, 55);
4702 ASSERT (wcscmp (result
, L
"-12345 33") == 0);
4703 ASSERT (length
== wcslen (result
));
4710 my_asnwprintf (NULL
, &length
, L
"%d %d", -12345, 33, 44, 55);
4711 ASSERT (wcscmp (result
, L
"-12345 33") == 0);
4712 ASSERT (length
== wcslen (result
));
4719 my_asnwprintf (NULL
, &length
, L
"%ld %d", (long int) -12345, 33, 44, 55);
4720 ASSERT (wcscmp (result
, L
"-12345 33") == 0);
4721 ASSERT (length
== wcslen (result
));
4728 my_asnwprintf (NULL
, &length
, L
"%lld %d", (long long int) -12345, 33, 44, 55);
4729 ASSERT (wcscmp (result
, L
"-12345 33") == 0);
4730 ASSERT (length
== wcslen (result
));
4737 my_asnwprintf (NULL
, &length
, L
"%w8d %d", (int8_t) -42, 33, 44, 55);
4738 ASSERT (wcscmp (result
, L
"-42 33") == 0);
4739 ASSERT (length
== wcslen (result
));
4746 my_asnwprintf (NULL
, &length
, L
"%w16d %d", (int16_t) -12345, 33, 44, 55);
4747 ASSERT (wcscmp (result
, L
"-12345 33") == 0);
4748 ASSERT (length
== wcslen (result
));
4755 my_asnwprintf (NULL
, &length
, L
"%w32d %d", (int32_t) -12345, 33, 44, 55);
4756 ASSERT (wcscmp (result
, L
"-12345 33") == 0);
4757 ASSERT (length
== wcslen (result
));
4764 my_asnwprintf (NULL
, &length
, L
"%w64d %d", (int64_t) -12345, 33, 44, 55);
4765 ASSERT (wcscmp (result
, L
"-12345 33") == 0);
4766 ASSERT (length
== wcslen (result
));
4773 my_asnwprintf (NULL
, &length
, L
"%wf8d %d", (int_fast8_t) -42, 33, 44, 55);
4774 ASSERT (wcscmp (result
, L
"-42 33") == 0);
4775 ASSERT (length
== wcslen (result
));
4782 my_asnwprintf (NULL
, &length
, L
"%wf16d %d", (int_fast16_t) -12345, 33, 44, 55);
4783 ASSERT (wcscmp (result
, L
"-12345 33") == 0);
4784 ASSERT (length
== wcslen (result
));
4791 my_asnwprintf (NULL
, &length
, L
"%wf32d %d", (int_fast32_t) -12345, 33, 44, 55);
4792 ASSERT (wcscmp (result
, L
"-12345 33") == 0);
4793 ASSERT (length
== wcslen (result
));
4800 my_asnwprintf (NULL
, &length
, L
"%wf64d %d", (int_fast64_t) -12345, 33, 44, 55);
4801 ASSERT (wcscmp (result
, L
"-12345 33") == 0);
4802 ASSERT (length
== wcslen (result
));
4806 /* Test the support of argument type/size specifiers for unsigned integer
4812 my_asnwprintf (NULL
, &length
, L
"%hhu %d", (unsigned char) 42, 33, 44, 55);
4813 ASSERT (wcscmp (result
, L
"42 33") == 0);
4814 ASSERT (length
== wcslen (result
));
4821 my_asnwprintf (NULL
, &length
, L
"%hu %d", (unsigned short) 12345, 33, 44, 55);
4822 ASSERT (wcscmp (result
, L
"12345 33") == 0);
4823 ASSERT (length
== wcslen (result
));
4830 my_asnwprintf (NULL
, &length
, L
"%u %d", (unsigned int) 12345, 33, 44, 55);
4831 ASSERT (wcscmp (result
, L
"12345 33") == 0);
4832 ASSERT (length
== wcslen (result
));
4839 my_asnwprintf (NULL
, &length
, L
"%lu %d", (unsigned long int) 12345, 33, 44, 55);
4840 ASSERT (wcscmp (result
, L
"12345 33") == 0);
4841 ASSERT (length
== wcslen (result
));
4848 my_asnwprintf (NULL
, &length
, L
"%llu %d", (unsigned long long int) 12345, 33, 44, 55);
4849 ASSERT (wcscmp (result
, L
"12345 33") == 0);
4850 ASSERT (length
== wcslen (result
));
4857 my_asnwprintf (NULL
, &length
, L
"%w8u %d", (uint8_t) 42, 33, 44, 55);
4858 ASSERT (wcscmp (result
, L
"42 33") == 0);
4859 ASSERT (length
== wcslen (result
));
4866 my_asnwprintf (NULL
, &length
, L
"%w16u %d", (uint16_t) 12345, 33, 44, 55);
4867 ASSERT (wcscmp (result
, L
"12345 33") == 0);
4868 ASSERT (length
== wcslen (result
));
4875 my_asnwprintf (NULL
, &length
, L
"%w32u %d", (uint32_t) 12345, 33, 44, 55);
4876 ASSERT (wcscmp (result
, L
"12345 33") == 0);
4877 ASSERT (length
== wcslen (result
));
4884 my_asnwprintf (NULL
, &length
, L
"%w64u %d", (uint64_t) 12345, 33, 44, 55);
4885 ASSERT (wcscmp (result
, L
"12345 33") == 0);
4886 ASSERT (length
== wcslen (result
));
4893 my_asnwprintf (NULL
, &length
, L
"%wf8u %d", (uint_fast8_t) 42, 33, 44, 55);
4894 ASSERT (wcscmp (result
, L
"42 33") == 0);
4895 ASSERT (length
== wcslen (result
));
4902 my_asnwprintf (NULL
, &length
, L
"%wf16u %d", (uint_fast16_t) 12345, 33, 44, 55);
4903 ASSERT (wcscmp (result
, L
"12345 33") == 0);
4904 ASSERT (length
== wcslen (result
));
4911 my_asnwprintf (NULL
, &length
, L
"%wf32u %d", (uint_fast32_t) 12345, 33, 44, 55);
4912 ASSERT (wcscmp (result
, L
"12345 33") == 0);
4913 ASSERT (length
== wcslen (result
));
4920 my_asnwprintf (NULL
, &length
, L
"%wf64u %d", (uint_fast64_t) 12345, 33, 44, 55);
4921 ASSERT (wcscmp (result
, L
"12345 33") == 0);
4922 ASSERT (length
== wcslen (result
));
4926 /* Test the support of argument type/size specifiers for unsigned integer
4932 my_asnwprintf (NULL
, &length
, L
"%hhb %d", (unsigned char) 42, 33, 44, 55);
4933 ASSERT (wcscmp (result
, L
"101010 33") == 0);
4934 ASSERT (length
== wcslen (result
));
4941 my_asnwprintf (NULL
, &length
, L
"%hb %d", (unsigned short) 12345, 33, 44, 55);
4942 ASSERT (wcscmp (result
, L
"11000000111001 33") == 0);
4943 ASSERT (length
== wcslen (result
));
4950 my_asnwprintf (NULL
, &length
, L
"%b %d", (unsigned int) 12345, 33, 44, 55);
4951 ASSERT (wcscmp (result
, L
"11000000111001 33") == 0);
4952 ASSERT (length
== wcslen (result
));
4959 my_asnwprintf (NULL
, &length
, L
"%lb %d", (unsigned long int) 12345, 33, 44, 55);
4960 ASSERT (wcscmp (result
, L
"11000000111001 33") == 0);
4961 ASSERT (length
== wcslen (result
));
4968 my_asnwprintf (NULL
, &length
, L
"%llb %d", (unsigned long long int) 12345, 33, 44, 55);
4969 ASSERT (wcscmp (result
, L
"11000000111001 33") == 0);
4970 ASSERT (length
== wcslen (result
));
4977 my_asnwprintf (NULL
, &length
, L
"%w8b %d", (uint8_t) 42, 33, 44, 55);
4978 ASSERT (wcscmp (result
, L
"101010 33") == 0);
4979 ASSERT (length
== wcslen (result
));
4986 my_asnwprintf (NULL
, &length
, L
"%w16b %d", (uint16_t) 12345, 33, 44, 55);
4987 ASSERT (wcscmp (result
, L
"11000000111001 33") == 0);
4988 ASSERT (length
== wcslen (result
));
4995 my_asnwprintf (NULL
, &length
, L
"%w32b %d", (uint32_t) 12345, 33, 44, 55);
4996 ASSERT (wcscmp (result
, L
"11000000111001 33") == 0);
4997 ASSERT (length
== wcslen (result
));
5004 my_asnwprintf (NULL
, &length
, L
"%w64b %d", (uint64_t) 12345, 33, 44, 55);
5005 ASSERT (wcscmp (result
, L
"11000000111001 33") == 0);
5006 ASSERT (length
== wcslen (result
));
5013 my_asnwprintf (NULL
, &length
, L
"%wf8b %d", (uint_fast8_t) 42, 33, 44, 55);
5014 ASSERT (wcscmp (result
, L
"101010 33") == 0);
5015 ASSERT (length
== wcslen (result
));
5022 my_asnwprintf (NULL
, &length
, L
"%wf16b %d", (uint_fast16_t) 12345, 33, 44, 55);
5023 ASSERT (wcscmp (result
, L
"11000000111001 33") == 0);
5024 ASSERT (length
== wcslen (result
));
5031 my_asnwprintf (NULL
, &length
, L
"%wf32b %d", (uint_fast32_t) 12345, 33, 44, 55);
5032 ASSERT (wcscmp (result
, L
"11000000111001 33") == 0);
5033 ASSERT (length
== wcslen (result
));
5040 my_asnwprintf (NULL
, &length
, L
"%wf64b %d", (uint_fast64_t) 12345, 33, 44, 55);
5041 ASSERT (wcscmp (result
, L
"11000000111001 33") == 0);
5042 ASSERT (length
== wcslen (result
));
5046 /* Test the support of argument type/size specifiers for unsigned integer
5052 my_asnwprintf (NULL
, &length
, L
"%hho %d", (unsigned char) 42, 33, 44, 55);
5053 ASSERT (wcscmp (result
, L
"52 33") == 0);
5054 ASSERT (length
== wcslen (result
));
5061 my_asnwprintf (NULL
, &length
, L
"%ho %d", (unsigned short) 12345, 33, 44, 55);
5062 ASSERT (wcscmp (result
, L
"30071 33") == 0);
5063 ASSERT (length
== wcslen (result
));
5070 my_asnwprintf (NULL
, &length
, L
"%o %d", (unsigned int) 12345, 33, 44, 55);
5071 ASSERT (wcscmp (result
, L
"30071 33") == 0);
5072 ASSERT (length
== wcslen (result
));
5079 my_asnwprintf (NULL
, &length
, L
"%lo %d", (unsigned long int) 12345, 33, 44, 55);
5080 ASSERT (wcscmp (result
, L
"30071 33") == 0);
5081 ASSERT (length
== wcslen (result
));
5088 my_asnwprintf (NULL
, &length
, L
"%llo %d", (unsigned long long int) 12345, 33, 44, 55);
5089 ASSERT (wcscmp (result
, L
"30071 33") == 0);
5090 ASSERT (length
== wcslen (result
));
5097 my_asnwprintf (NULL
, &length
, L
"%w8o %d", (uint8_t) 42, 33, 44, 55);
5098 ASSERT (wcscmp (result
, L
"52 33") == 0);
5099 ASSERT (length
== wcslen (result
));
5106 my_asnwprintf (NULL
, &length
, L
"%w16o %d", (uint16_t) 12345, 33, 44, 55);
5107 ASSERT (wcscmp (result
, L
"30071 33") == 0);
5108 ASSERT (length
== wcslen (result
));
5115 my_asnwprintf (NULL
, &length
, L
"%w32o %d", (uint32_t) 12345, 33, 44, 55);
5116 ASSERT (wcscmp (result
, L
"30071 33") == 0);
5117 ASSERT (length
== wcslen (result
));
5124 my_asnwprintf (NULL
, &length
, L
"%w64o %d", (uint64_t) 12345, 33, 44, 55);
5125 ASSERT (wcscmp (result
, L
"30071 33") == 0);
5126 ASSERT (length
== wcslen (result
));
5133 my_asnwprintf (NULL
, &length
, L
"%wf8o %d", (uint_fast8_t) 42, 33, 44, 55);
5134 ASSERT (wcscmp (result
, L
"52 33") == 0);
5135 ASSERT (length
== wcslen (result
));
5142 my_asnwprintf (NULL
, &length
, L
"%wf16o %d", (uint_fast16_t) 12345, 33, 44, 55);
5143 ASSERT (wcscmp (result
, L
"30071 33") == 0);
5144 ASSERT (length
== wcslen (result
));
5151 my_asnwprintf (NULL
, &length
, L
"%wf32o %d", (uint_fast32_t) 12345, 33, 44, 55);
5152 ASSERT (wcscmp (result
, L
"30071 33") == 0);
5153 ASSERT (length
== wcslen (result
));
5160 my_asnwprintf (NULL
, &length
, L
"%wf64o %d", (uint_fast64_t) 12345, 33, 44, 55);
5161 ASSERT (wcscmp (result
, L
"30071 33") == 0);
5162 ASSERT (length
== wcslen (result
));
5166 /* Test the support of argument type/size specifiers for unsigned integer
5172 my_asnwprintf (NULL
, &length
, L
"%hhX %d", (unsigned char) 42, 33, 44, 55);
5173 ASSERT (wcscmp (result
, L
"2A 33") == 0);
5174 ASSERT (length
== wcslen (result
));
5181 my_asnwprintf (NULL
, &length
, L
"%hX %d", (unsigned short) 12345, 33, 44, 55);
5182 ASSERT (wcscmp (result
, L
"3039 33") == 0);
5183 ASSERT (length
== wcslen (result
));
5190 my_asnwprintf (NULL
, &length
, L
"%X %d", (unsigned int) 12345, 33, 44, 55);
5191 ASSERT (wcscmp (result
, L
"3039 33") == 0);
5192 ASSERT (length
== wcslen (result
));
5199 my_asnwprintf (NULL
, &length
, L
"%lX %d", (unsigned long int) 12345, 33, 44, 55);
5200 ASSERT (wcscmp (result
, L
"3039 33") == 0);
5201 ASSERT (length
== wcslen (result
));
5208 my_asnwprintf (NULL
, &length
, L
"%llX %d", (unsigned long long int) 12345, 33, 44, 55);
5209 ASSERT (wcscmp (result
, L
"3039 33") == 0);
5210 ASSERT (length
== wcslen (result
));
5217 my_asnwprintf (NULL
, &length
, L
"%w8X %d", (uint8_t) 42, 33, 44, 55);
5218 ASSERT (wcscmp (result
, L
"2A 33") == 0);
5219 ASSERT (length
== wcslen (result
));
5226 my_asnwprintf (NULL
, &length
, L
"%w16X %d", (uint16_t) 12345, 33, 44, 55);
5227 ASSERT (wcscmp (result
, L
"3039 33") == 0);
5228 ASSERT (length
== wcslen (result
));
5235 my_asnwprintf (NULL
, &length
, L
"%w32X %d", (uint32_t) 12345, 33, 44, 55);
5236 ASSERT (wcscmp (result
, L
"3039 33") == 0);
5237 ASSERT (length
== wcslen (result
));
5244 my_asnwprintf (NULL
, &length
, L
"%w64X %d", (uint64_t) 12345, 33, 44, 55);
5245 ASSERT (wcscmp (result
, L
"3039 33") == 0);
5246 ASSERT (length
== wcslen (result
));
5253 my_asnwprintf (NULL
, &length
, L
"%wf8X %d", (uint_fast8_t) 42, 33, 44, 55);
5254 ASSERT (wcscmp (result
, L
"2A 33") == 0);
5255 ASSERT (length
== wcslen (result
));
5262 my_asnwprintf (NULL
, &length
, L
"%wf16X %d", (uint_fast16_t) 12345, 33, 44, 55);
5263 ASSERT (wcscmp (result
, L
"3039 33") == 0);
5264 ASSERT (length
== wcslen (result
));
5271 my_asnwprintf (NULL
, &length
, L
"%wf32X %d", (uint_fast32_t) 12345, 33, 44, 55);
5272 ASSERT (wcscmp (result
, L
"3039 33") == 0);
5273 ASSERT (length
== wcslen (result
));
5280 my_asnwprintf (NULL
, &length
, L
"%wf64X %d", (uint_fast64_t) 12345, 33, 44, 55);
5281 ASSERT (wcscmp (result
, L
"3039 33") == 0);
5282 ASSERT (length
== wcslen (result
));
5286 #if (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 2)) && !defined __UCLIBC__
5287 /* Test that the 'I' flag is supported. */
5291 my_asnwprintf (NULL
, &length
, L
"%Id %d", 1234567, 99);
5292 ASSERT (result
!= NULL
);
5293 ASSERT (wcscmp (result
, L
"1234567 99") == 0);
5294 ASSERT (length
== wcslen (result
));
5301 my_asnwprintf (wchar_t *resultbuf
, size_t *lengthp
, const wchar_t *format
, ...)
5306 va_start (args
, format
);
5307 ret
= vasnwprintf (resultbuf
, lengthp
, format
, args
);
5315 test_function (my_asnwprintf
);
5321 test_function (asnwprintf
);
5325 main (int argc
, char *argv
[])
5327 test_vasnwprintf ();
5329 return test_exit_status
;