root/maint/gnulib/tests/test-snprintf-posix.h

/* [previous][next][first][last][top][bottom][index][help] */

INCLUDED FROM


DEFINITIONS

This source file includes following definitions.
  1. have_minus_zero
  2. strmatch
  3. strisnan
  4. test_function

   1 /* Test of POSIX compatible vsnprintf() and snprintf() functions.
   2    Copyright (C) 2007-2021 Free Software Foundation, Inc.
   3 
   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.
   8 
   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.
  13 
  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/>.  */
  16 
  17 /* Written by Bruno Haible <bruno@clisp.org>, 2007.  */
  18 
  19 #include "minus-zero.h"
  20 #include "infinity.h"
  21 #include "nan.h"
  22 
  23 /* The SGI MIPS floating-point format does not distinguish 0.0 and -0.0.  */
  24 static int
  25 have_minus_zero ()
     /* [previous][next][first][last][top][bottom][index][help] */
  26 {
  27   static double plus_zero = 0.0;
  28   double minus_zero = minus_zerod;
  29   return memcmp (&plus_zero, &minus_zero, sizeof (double)) != 0;
  30 }
  31 
  32 /* Representation of an 80-bit 'long double' as an initializer for a sequence
  33    of 'unsigned int' words.  */
  34 #ifdef WORDS_BIGENDIAN
  35 # define LDBL80_WORDS(exponent,manthi,mantlo) \
  36     { ((unsigned int) (exponent) << 16) | ((unsigned int) (manthi) >> 16), \
  37       ((unsigned int) (manthi) << 16) | ((unsigned int) (mantlo) >> 16),   \
  38       (unsigned int) (mantlo) << 16                                        \
  39     }
  40 #else
  41 # define LDBL80_WORDS(exponent,manthi,mantlo) \
  42     { mantlo, manthi, exponent }
  43 #endif
  44 
  45 static int
  46 strmatch (const char *pattern, const char *string)
     /* [previous][next][first][last][top][bottom][index][help] */
  47 {
  48   if (strlen (pattern) != strlen (string))
  49     return 0;
  50   for (; *pattern != '\0'; pattern++, string++)
  51     if (*pattern != '*' && *string != *pattern)
  52       return 0;
  53   return 1;
  54 }
  55 
  56 /* Test whether string[start_index..end_index-1] is a valid textual
  57    representation of NaN.  */
  58 static int
  59 strisnan (const char *string, size_t start_index, size_t end_index, int uppercase)
     /* [previous][next][first][last][top][bottom][index][help] */
  60 {
  61   if (start_index < end_index)
  62     {
  63       if (string[start_index] == '-')
  64         start_index++;
  65       if (start_index + 3 <= end_index
  66           && memcmp (string + start_index, uppercase ? "NAN" : "nan", 3) == 0)
  67         {
  68           start_index += 3;
  69           if (start_index == end_index
  70               || (string[start_index] == '(' && string[end_index - 1] == ')'))
  71             return 1;
  72         }
  73     }
  74   return 0;
  75 }
  76 
  77 static void
  78 test_function (int (*my_snprintf) (char *, size_t, const char *, ...))
     /* [previous][next][first][last][top][bottom][index][help] */
  79 {
  80   char buf[8];
  81   int size;
  82   char result[5000];
  83 
  84   /* Test return value convention.  */
  85 
  86   for (size = 0; size <= 8; size++)
  87     {
  88       int retval;
  89 
  90       memcpy (buf, "DEADBEEF", 8);
  91       retval = my_snprintf (buf, size, "%d", 12345);
  92       ASSERT (retval == 5);
  93       if (size < 6)
  94         {
  95           if (size > 0)
  96             {
  97               ASSERT (memcmp (buf, "12345", size - 1) == 0);
  98               ASSERT (buf[size - 1] == '\0');
  99             }
 100           ASSERT (memcmp (buf + size, &"DEADBEEF"[size], 8 - size) == 0);
 101         }
 102       else
 103         {
 104           ASSERT (memcmp (buf, "12345\0EF", 8) == 0);
 105         }
 106     }
 107 
 108   /* Test support of size specifiers as in C99.  */
 109 
 110   {
 111     int retval =
 112       my_snprintf (result, sizeof (result), "%ju %d", (uintmax_t) 12345671, 33, 44, 55);
 113     ASSERT (strcmp (result, "12345671 33") == 0);
 114     ASSERT (retval == strlen (result));
 115   }
 116 
 117   {
 118     int retval =
 119       my_snprintf (result, sizeof (result), "%zu %d", (size_t) 12345672, 33, 44, 55);
 120     ASSERT (strcmp (result, "12345672 33") == 0);
 121     ASSERT (retval == strlen (result));
 122   }
 123 
 124   {
 125     int retval =
 126       my_snprintf (result, sizeof (result), "%tu %d", (ptrdiff_t) 12345673, 33, 44, 55);
 127     ASSERT (strcmp (result, "12345673 33") == 0);
 128     ASSERT (retval == strlen (result));
 129   }
 130 
 131   {
 132     int retval =
 133       my_snprintf (result, sizeof (result), "%Lg %d", (long double) 1.5, 33, 44, 55);
 134     ASSERT (strcmp (result, "1.5 33") == 0);
 135     ASSERT (retval == strlen (result));
 136   }
 137 
 138   /* Test the support of the 'a' and 'A' conversion specifier for hexadecimal
 139      output of floating-point numbers.  */
 140 
 141   { /* A positive number.  */
 142     int retval =
 143       my_snprintf (result, sizeof (result), "%a %d", 3.1416015625, 33, 44, 55);
 144     ASSERT (strcmp (result, "0x1.922p+1 33") == 0
 145             || strcmp (result, "0x3.244p+0 33") == 0
 146             || strcmp (result, "0x6.488p-1 33") == 0
 147             || strcmp (result, "0xc.91p-2 33") == 0);
 148     ASSERT (retval == strlen (result));
 149   }
 150 
 151   { /* A negative number.  */
 152     int retval =
 153       my_snprintf (result, sizeof (result), "%A %d", -3.1416015625, 33, 44, 55);
 154     ASSERT (strcmp (result, "-0X1.922P+1 33") == 0
 155             || strcmp (result, "-0X3.244P+0 33") == 0
 156             || strcmp (result, "-0X6.488P-1 33") == 0
 157             || strcmp (result, "-0XC.91P-2 33") == 0);
 158     ASSERT (retval == strlen (result));
 159   }
 160 
 161   { /* Positive zero.  */
 162     int retval =
 163       my_snprintf (result, sizeof (result), "%a %d", 0.0, 33, 44, 55);
 164     ASSERT (strcmp (result, "0x0p+0 33") == 0);
 165     ASSERT (retval == strlen (result));
 166   }
 167 
 168   { /* Negative zero.  */
 169     int retval =
 170       my_snprintf (result, sizeof (result), "%a %d", minus_zerod, 33, 44, 55);
 171     if (have_minus_zero ())
 172       ASSERT (strcmp (result, "-0x0p+0 33") == 0);
 173     ASSERT (retval == strlen (result));
 174   }
 175 
 176   { /* Positive infinity.  */
 177     int retval =
 178       my_snprintf (result, sizeof (result), "%a %d", Infinityd (), 33, 44, 55);
 179     ASSERT (strcmp (result, "inf 33") == 0);
 180     ASSERT (retval == strlen (result));
 181   }
 182 
 183   { /* Negative infinity.  */
 184     int retval =
 185       my_snprintf (result, sizeof (result), "%a %d", - Infinityd (), 33, 44, 55);
 186     ASSERT (strcmp (result, "-inf 33") == 0);
 187     ASSERT (retval == strlen (result));
 188   }
 189 
 190   { /* NaN.  */
 191     int retval =
 192       my_snprintf (result, sizeof (result), "%a %d", NaNd (), 33, 44, 55);
 193     ASSERT (strlen (result) >= 3 + 3
 194             && strisnan (result, 0, strlen (result) - 3, 0)
 195             && strcmp (result + strlen (result) - 3, " 33") == 0);
 196     ASSERT (retval == strlen (result));
 197   }
 198 
 199   { /* Rounding near the decimal point.  */
 200     int retval =
 201       my_snprintf (result, sizeof (result), "%.0a %d", 1.5, 33, 44, 55);
 202     ASSERT (strcmp (result, "0x2p+0 33") == 0
 203             || strcmp (result, "0x3p-1 33") == 0
 204             || strcmp (result, "0x6p-2 33") == 0
 205             || strcmp (result, "0xcp-3 33") == 0);
 206     ASSERT (retval == strlen (result));
 207   }
 208 
 209   { /* Rounding with precision 0.  */
 210     int retval =
 211       my_snprintf (result, sizeof (result), "%.0a %d", 1.51, 33, 44, 55);
 212     ASSERT (strcmp (result, "0x2p+0 33") == 0
 213             || strcmp (result, "0x3p-1 33") == 0
 214             || strcmp (result, "0x6p-2 33") == 0
 215             || strcmp (result, "0xcp-3 33") == 0);
 216     ASSERT (retval == strlen (result));
 217   }
 218 
 219   { /* Rounding with precision 1.  */
 220     int retval =
 221       my_snprintf (result, sizeof (result), "%.1a %d", 1.51, 33, 44, 55);
 222     ASSERT (strcmp (result, "0x1.8p+0 33") == 0
 223             || strcmp (result, "0x3.0p-1 33") == 0
 224             || strcmp (result, "0x6.1p-2 33") == 0
 225             || strcmp (result, "0xc.1p-3 33") == 0);
 226     ASSERT (retval == strlen (result));
 227   }
 228 
 229   { /* Rounding with precision 2.  */
 230     int retval =
 231       my_snprintf (result, sizeof (result), "%.2a %d", 1.51, 33, 44, 55);
 232     ASSERT (strcmp (result, "0x1.83p+0 33") == 0
 233             || strcmp (result, "0x3.05p-1 33") == 0
 234             || strcmp (result, "0x6.0ap-2 33") == 0
 235             || strcmp (result, "0xc.14p-3 33") == 0);
 236     ASSERT (retval == strlen (result));
 237   }
 238 
 239   { /* Rounding with precision 3.  */
 240     int retval =
 241       my_snprintf (result, sizeof (result), "%.3a %d", 1.51, 33, 44, 55);
 242     ASSERT (strcmp (result, "0x1.829p+0 33") == 0
 243             || strcmp (result, "0x3.052p-1 33") == 0
 244             || strcmp (result, "0x6.0a4p-2 33") == 0
 245             || strcmp (result, "0xc.148p-3 33") == 0);
 246     ASSERT (retval == strlen (result));
 247   }
 248 
 249   { /* Rounding can turn a ...FFF into a ...000.  */
 250     int retval =
 251       my_snprintf (result, sizeof (result), "%.3a %d", 1.49999, 33, 44, 55);
 252     ASSERT (strcmp (result, "0x1.800p+0 33") == 0
 253             || strcmp (result, "0x3.000p-1 33") == 0
 254             || strcmp (result, "0x6.000p-2 33") == 0
 255             || strcmp (result, "0xc.000p-3 33") == 0);
 256     ASSERT (retval == strlen (result));
 257   }
 258 
 259   { /* Rounding can turn a ...FFF into a ...000.
 260        This shows a Mac OS X 10.3.9 (Darwin 7.9) bug.  */
 261     int retval =
 262       my_snprintf (result, sizeof (result), "%.1a %d", 1.999, 33, 44, 55);
 263     ASSERT (strcmp (result, "0x1.0p+1 33") == 0
 264             || strcmp (result, "0x2.0p+0 33") == 0
 265             || strcmp (result, "0x4.0p-1 33") == 0
 266             || strcmp (result, "0x8.0p-2 33") == 0);
 267     ASSERT (retval == strlen (result));
 268   }
 269 
 270   { /* Width.  */
 271     int retval =
 272       my_snprintf (result, sizeof (result), "%10a %d", 1.75, 33, 44, 55);
 273     ASSERT (strcmp (result, "  0x1.cp+0 33") == 0
 274             || strcmp (result, "  0x3.8p-1 33") == 0
 275             || strcmp (result, "    0x7p-2 33") == 0
 276             || strcmp (result, "    0xep-3 33") == 0);
 277     ASSERT (retval == strlen (result));
 278   }
 279 
 280   { /* Small precision.  */
 281     int retval =
 282       my_snprintf (result, sizeof (result), "%.10a %d", 1.75, 33, 44, 55);
 283     ASSERT (strcmp (result, "0x1.c000000000p+0 33") == 0
 284             || strcmp (result, "0x3.8000000000p-1 33") == 0
 285             || strcmp (result, "0x7.0000000000p-2 33") == 0
 286             || strcmp (result, "0xe.0000000000p-3 33") == 0);
 287     ASSERT (retval == strlen (result));
 288   }
 289 
 290   { /* Large precision.  */
 291     int retval =
 292       my_snprintf (result, sizeof (result), "%.50a %d", 1.75, 33, 44, 55);
 293     ASSERT (strcmp (result, "0x1.c0000000000000000000000000000000000000000000000000p+0 33") == 0
 294             || strcmp (result, "0x3.80000000000000000000000000000000000000000000000000p-1 33") == 0
 295             || strcmp (result, "0x7.00000000000000000000000000000000000000000000000000p-2 33") == 0
 296             || strcmp (result, "0xe.00000000000000000000000000000000000000000000000000p-3 33") == 0);
 297     ASSERT (retval == strlen (result));
 298   }
 299 
 300   { /* FLAG_LEFT.  */
 301     int retval =
 302       my_snprintf (result, sizeof (result), "%-10a %d", 1.75, 33, 44, 55);
 303     ASSERT (strcmp (result, "0x1.cp+0   33") == 0
 304             || strcmp (result, "0x3.8p-1   33") == 0
 305             || strcmp (result, "0x7p-2     33") == 0
 306             || strcmp (result, "0xep-3     33") == 0);
 307     ASSERT (retval == strlen (result));
 308   }
 309 
 310   { /* FLAG_SHOWSIGN.  */
 311     int retval =
 312       my_snprintf (result, sizeof (result), "%+a %d", 1.75, 33, 44, 55);
 313     ASSERT (strcmp (result, "+0x1.cp+0 33") == 0
 314             || strcmp (result, "+0x3.8p-1 33") == 0
 315             || strcmp (result, "+0x7p-2 33") == 0
 316             || strcmp (result, "+0xep-3 33") == 0);
 317     ASSERT (retval == strlen (result));
 318   }
 319 
 320   { /* FLAG_SPACE.  */
 321     int retval =
 322       my_snprintf (result, sizeof (result), "% a %d", 1.75, 33, 44, 55);
 323     ASSERT (strcmp (result, " 0x1.cp+0 33") == 0
 324             || strcmp (result, " 0x3.8p-1 33") == 0
 325             || strcmp (result, " 0x7p-2 33") == 0
 326             || strcmp (result, " 0xep-3 33") == 0);
 327     ASSERT (retval == strlen (result));
 328   }
 329 
 330   { /* FLAG_ALT.  */
 331     int retval =
 332       my_snprintf (result, sizeof (result), "%#a %d", 1.75, 33, 44, 55);
 333     ASSERT (strcmp (result, "0x1.cp+0 33") == 0
 334             || strcmp (result, "0x3.8p-1 33") == 0
 335             || strcmp (result, "0x7.p-2 33") == 0
 336             || strcmp (result, "0xe.p-3 33") == 0);
 337     ASSERT (retval == strlen (result));
 338   }
 339 
 340   { /* FLAG_ALT.  */
 341     int retval =
 342       my_snprintf (result, sizeof (result), "%#a %d", 1.0, 33, 44, 55);
 343     ASSERT (strcmp (result, "0x1.p+0 33") == 0
 344             || strcmp (result, "0x2.p-1 33") == 0
 345             || strcmp (result, "0x4.p-2 33") == 0
 346             || strcmp (result, "0x8.p-3 33") == 0);
 347     ASSERT (retval == strlen (result));
 348   }
 349 
 350   { /* FLAG_ZERO with finite number.  */
 351     int retval =
 352       my_snprintf (result, sizeof (result), "%010a %d", 1.75, 33, 44, 55);
 353     ASSERT (strcmp (result, "0x001.cp+0 33") == 0
 354             || strcmp (result, "0x003.8p-1 33") == 0
 355             || strcmp (result, "0x00007p-2 33") == 0
 356             || strcmp (result, "0x0000ep-3 33") == 0);
 357     ASSERT (retval == strlen (result));
 358   }
 359 
 360   { /* FLAG_ZERO with infinite number.  */
 361     int retval =
 362       my_snprintf (result, sizeof (result), "%010a %d", Infinityd (), 33, 44, 55);
 363     /* "0000000inf 33" is not a valid result; see
 364        <https://lists.gnu.org/r/bug-gnulib/2007-04/msg00107.html> */
 365     ASSERT (strcmp (result, "       inf 33") == 0);
 366     ASSERT (retval == strlen (result));
 367   }
 368 
 369   { /* FLAG_ZERO with NaN.  */
 370     int retval =
 371       my_snprintf (result, sizeof (result), "%050a %d", NaNd (), 33, 44, 55);
 372     /* "0000000nan 33" is not a valid result; see
 373        <https://lists.gnu.org/r/bug-gnulib/2007-04/msg00107.html> */
 374     ASSERT (strlen (result) == 50 + 3
 375             && strisnan (result, strspn (result, " "), strlen (result) - 3, 0)
 376             && strcmp (result + strlen (result) - 3, " 33") == 0);
 377     ASSERT (retval == strlen (result));
 378   }
 379 
 380   { /* A positive number.  */
 381     int retval =
 382       my_snprintf (result, sizeof (result), "%La %d", 3.1416015625L, 33, 44, 55);
 383     ASSERT (strcmp (result, "0x1.922p+1 33") == 0
 384             || strcmp (result, "0x3.244p+0 33") == 0
 385             || strcmp (result, "0x6.488p-1 33") == 0
 386             || strcmp (result, "0xc.91p-2 33") == 0);
 387     ASSERT (retval == strlen (result));
 388   }
 389 
 390   { /* A negative number.  */
 391     int retval =
 392       my_snprintf (result, sizeof (result), "%LA %d", -3.1416015625L, 33, 44, 55);
 393     ASSERT (strcmp (result, "-0X1.922P+1 33") == 0
 394             || strcmp (result, "-0X3.244P+0 33") == 0
 395             || strcmp (result, "-0X6.488P-1 33") == 0
 396             || strcmp (result, "-0XC.91P-2 33") == 0);
 397     ASSERT (retval == strlen (result));
 398   }
 399 
 400   { /* Positive zero.  */
 401     int retval =
 402       my_snprintf (result, sizeof (result), "%La %d", 0.0L, 33, 44, 55);
 403     ASSERT (strcmp (result, "0x0p+0 33") == 0);
 404     ASSERT (retval == strlen (result));
 405   }
 406 
 407   { /* Negative zero.  */
 408     int retval =
 409       my_snprintf (result, sizeof (result), "%La %d", minus_zerol, 33, 44, 55);
 410     if (have_minus_zero ())
 411       ASSERT (strcmp (result, "-0x0p+0 33") == 0);
 412     ASSERT (retval == strlen (result));
 413   }
 414 
 415   { /* Positive infinity.  */
 416     int retval =
 417       my_snprintf (result, sizeof (result), "%La %d", Infinityl (), 33, 44, 55);
 418     ASSERT (strcmp (result, "inf 33") == 0);
 419     ASSERT (retval == strlen (result));
 420   }
 421 
 422   { /* Negative infinity.  */
 423     int retval =
 424       my_snprintf (result, sizeof (result), "%La %d", - Infinityl (), 33, 44, 55);
 425     ASSERT (strcmp (result, "-inf 33") == 0);
 426     ASSERT (retval == strlen (result));
 427   }
 428 
 429   { /* NaN.  */
 430     int retval =
 431       my_snprintf (result, sizeof (result), "%La %d", NaNl (), 33, 44, 55);
 432     ASSERT (strlen (result) >= 3 + 3
 433             && strisnan (result, 0, strlen (result) - 3, 0)
 434             && strcmp (result + strlen (result) - 3, " 33") == 0);
 435     ASSERT (retval == strlen (result));
 436   }
 437 #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
 438   { /* Quiet NaN.  */
 439     static union { unsigned int word[4]; long double value; } x =
 440       { LDBL80_WORDS (0xFFFF, 0xC3333333, 0x00000000) };
 441     int retval =
 442       my_snprintf (result, sizeof (result), "%La %d", x.value, 33, 44, 55);
 443     ASSERT (strlen (result) >= 3 + 3
 444             && strisnan (result, 0, strlen (result) - 3, 0)
 445             && strcmp (result + strlen (result) - 3, " 33") == 0);
 446     ASSERT (retval == strlen (result));
 447   }
 448   {
 449     /* Signalling NaN.  */
 450     static union { unsigned int word[4]; long double value; } x =
 451       { LDBL80_WORDS (0xFFFF, 0x83333333, 0x00000000) };
 452     int retval =
 453       my_snprintf (result, sizeof (result), "%La %d", x.value, 33, 44, 55);
 454     ASSERT (strlen (result) >= 3 + 3
 455             && strisnan (result, 0, strlen (result) - 3, 0)
 456             && strcmp (result + strlen (result) - 3, " 33") == 0);
 457     ASSERT (retval == strlen (result));
 458   }
 459   /* snprintf should print something for noncanonical values.  */
 460   { /* Pseudo-NaN.  */
 461     static union { unsigned int word[4]; long double value; } x =
 462       { LDBL80_WORDS (0xFFFF, 0x40000001, 0x00000000) };
 463     int retval =
 464       my_snprintf (result, sizeof (result), "%La %d", x.value, 33, 44, 55);
 465     ASSERT (retval == strlen (result));
 466     ASSERT (3 < retval && strcmp (result + retval - 3, " 33") == 0);
 467   }
 468   { /* Pseudo-Infinity.  */
 469     static union { unsigned int word[4]; long double value; } x =
 470       { LDBL80_WORDS (0xFFFF, 0x00000000, 0x00000000) };
 471     int retval =
 472       my_snprintf (result, sizeof (result), "%La %d", x.value, 33, 44, 55);
 473     ASSERT (retval == strlen (result));
 474     ASSERT (3 < retval && strcmp (result + retval - 3, " 33") == 0);
 475   }
 476   { /* Pseudo-Zero.  */
 477     static union { unsigned int word[4]; long double value; } x =
 478       { LDBL80_WORDS (0x4004, 0x00000000, 0x00000000) };
 479     int retval =
 480       my_snprintf (result, sizeof (result), "%La %d", x.value, 33, 44, 55);
 481     ASSERT (retval == strlen (result));
 482     ASSERT (3 < retval && strcmp (result + retval - 3, " 33") == 0);
 483   }
 484   { /* Unnormalized number.  */
 485     static union { unsigned int word[4]; long double value; } x =
 486       { LDBL80_WORDS (0x4000, 0x63333333, 0x00000000) };
 487     int retval =
 488       my_snprintf (result, sizeof (result), "%La %d", x.value, 33, 44, 55);
 489     ASSERT (retval == strlen (result));
 490     ASSERT (3 < retval && strcmp (result + retval - 3, " 33") == 0);
 491   }
 492   { /* Pseudo-Denormal.  */
 493     static union { unsigned int word[4]; long double value; } x =
 494       { LDBL80_WORDS (0x0000, 0x83333333, 0x00000000) };
 495     int retval =
 496       my_snprintf (result, sizeof (result), "%La %d", x.value, 33, 44, 55);
 497     ASSERT (retval == strlen (result));
 498     ASSERT (3 < retval && strcmp (result + retval - 3, " 33") == 0);
 499   }
 500 #endif
 501 
 502   { /* Rounding near the decimal point.  */
 503     int retval =
 504       my_snprintf (result, sizeof (result), "%.0La %d", 1.5L, 33, 44, 55);
 505     ASSERT (strcmp (result, "0x2p+0 33") == 0
 506             || strcmp (result, "0x3p-1 33") == 0
 507             || strcmp (result, "0x6p-2 33") == 0
 508             || strcmp (result, "0xcp-3 33") == 0);
 509     ASSERT (retval == strlen (result));
 510   }
 511 
 512   { /* Rounding with precision 0.  */
 513     int retval =
 514       my_snprintf (result, sizeof (result), "%.0La %d", 1.51L, 33, 44, 55);
 515     ASSERT (strcmp (result, "0x2p+0 33") == 0
 516             || strcmp (result, "0x3p-1 33") == 0
 517             || strcmp (result, "0x6p-2 33") == 0
 518             || strcmp (result, "0xcp-3 33") == 0);
 519     ASSERT (retval == strlen (result));
 520   }
 521 
 522   { /* Rounding with precision 1.  */
 523     int retval =
 524       my_snprintf (result, sizeof (result), "%.1La %d", 1.51L, 33, 44, 55);
 525     ASSERT (strcmp (result, "0x1.8p+0 33") == 0
 526             || strcmp (result, "0x3.0p-1 33") == 0
 527             || strcmp (result, "0x6.1p-2 33") == 0
 528             || strcmp (result, "0xc.1p-3 33") == 0);
 529     ASSERT (retval == strlen (result));
 530   }
 531 
 532   { /* Rounding with precision 2.  */
 533     int retval =
 534       my_snprintf (result, sizeof (result), "%.2La %d", 1.51L, 33, 44, 55);
 535     ASSERT (strcmp (result, "0x1.83p+0 33") == 0
 536             || strcmp (result, "0x3.05p-1 33") == 0
 537             || strcmp (result, "0x6.0ap-2 33") == 0
 538             || strcmp (result, "0xc.14p-3 33") == 0);
 539     ASSERT (retval == strlen (result));
 540   }
 541 
 542   { /* Rounding with precision 3.  */
 543     int retval =
 544       my_snprintf (result, sizeof (result), "%.3La %d", 1.51L, 33, 44, 55);
 545     ASSERT (strcmp (result, "0x1.829p+0 33") == 0
 546             || strcmp (result, "0x3.052p-1 33") == 0
 547             || strcmp (result, "0x6.0a4p-2 33") == 0
 548             || strcmp (result, "0xc.148p-3 33") == 0);
 549     ASSERT (retval == strlen (result));
 550   }
 551 
 552   { /* Rounding can turn a ...FFF into a ...000.  */
 553     int retval =
 554       my_snprintf (result, sizeof (result), "%.3La %d", 1.49999L, 33, 44, 55);
 555     ASSERT (strcmp (result, "0x1.800p+0 33") == 0
 556             || strcmp (result, "0x3.000p-1 33") == 0
 557             || strcmp (result, "0x6.000p-2 33") == 0
 558             || strcmp (result, "0xc.000p-3 33") == 0);
 559     ASSERT (retval == strlen (result));
 560   }
 561 
 562   { /* Rounding can turn a ...FFF into a ...000.
 563        This shows a Mac OS X 10.3.9 (Darwin 7.9) bug and a
 564        glibc 2.4 bug <https://sourceware.org/bugzilla/show_bug.cgi?id=2908>.  */
 565     int retval =
 566       my_snprintf (result, sizeof (result), "%.1La %d", 1.999L, 33, 44, 55);
 567     ASSERT (strcmp (result, "0x1.0p+1 33") == 0
 568             || strcmp (result, "0x2.0p+0 33") == 0
 569             || strcmp (result, "0x4.0p-1 33") == 0
 570             || strcmp (result, "0x8.0p-2 33") == 0);
 571     ASSERT (retval == strlen (result));
 572   }
 573 
 574   { /* Width.  */
 575     int retval =
 576       my_snprintf (result, sizeof (result), "%10La %d", 1.75L, 33, 44, 55);
 577     ASSERT (strcmp (result, "  0x1.cp+0 33") == 0
 578             || strcmp (result, "  0x3.8p-1 33") == 0
 579             || strcmp (result, "    0x7p-2 33") == 0
 580             || strcmp (result, "    0xep-3 33") == 0);
 581     ASSERT (retval == strlen (result));
 582   }
 583 
 584   { /* Small precision.  */
 585     int retval =
 586       my_snprintf (result, sizeof (result), "%.10La %d", 1.75L, 33, 44, 55);
 587     ASSERT (strcmp (result, "0x1.c000000000p+0 33") == 0
 588             || strcmp (result, "0x3.8000000000p-1 33") == 0
 589             || strcmp (result, "0x7.0000000000p-2 33") == 0
 590             || strcmp (result, "0xe.0000000000p-3 33") == 0);
 591     ASSERT (retval == strlen (result));
 592   }
 593 
 594   { /* Large precision.  */
 595     int retval =
 596       my_snprintf (result, sizeof (result), "%.50La %d", 1.75L, 33, 44, 55);
 597     ASSERT (strcmp (result, "0x1.c0000000000000000000000000000000000000000000000000p+0 33") == 0
 598             || strcmp (result, "0x3.80000000000000000000000000000000000000000000000000p-1 33") == 0
 599             || strcmp (result, "0x7.00000000000000000000000000000000000000000000000000p-2 33") == 0
 600             || strcmp (result, "0xe.00000000000000000000000000000000000000000000000000p-3 33") == 0);
 601     ASSERT (retval == strlen (result));
 602   }
 603 
 604   { /* FLAG_LEFT.  */
 605     int retval =
 606       my_snprintf (result, sizeof (result), "%-10La %d", 1.75L, 33, 44, 55);
 607     ASSERT (strcmp (result, "0x1.cp+0   33") == 0
 608             || strcmp (result, "0x3.8p-1   33") == 0
 609             || strcmp (result, "0x7p-2     33") == 0
 610             || strcmp (result, "0xep-3     33") == 0);
 611     ASSERT (retval == strlen (result));
 612   }
 613 
 614   { /* FLAG_SHOWSIGN.  */
 615     int retval =
 616       my_snprintf (result, sizeof (result), "%+La %d", 1.75L, 33, 44, 55);
 617     ASSERT (strcmp (result, "+0x1.cp+0 33") == 0
 618             || strcmp (result, "+0x3.8p-1 33") == 0
 619             || strcmp (result, "+0x7p-2 33") == 0
 620             || strcmp (result, "+0xep-3 33") == 0);
 621     ASSERT (retval == strlen (result));
 622   }
 623 
 624   { /* FLAG_SPACE.  */
 625     int retval =
 626       my_snprintf (result, sizeof (result), "% La %d", 1.75L, 33, 44, 55);
 627     ASSERT (strcmp (result, " 0x1.cp+0 33") == 0
 628             || strcmp (result, " 0x3.8p-1 33") == 0
 629             || strcmp (result, " 0x7p-2 33") == 0
 630             || strcmp (result, " 0xep-3 33") == 0);
 631     ASSERT (retval == strlen (result));
 632   }
 633 
 634   { /* FLAG_ALT.  */
 635     int retval =
 636       my_snprintf (result, sizeof (result), "%#La %d", 1.75L, 33, 44, 55);
 637     ASSERT (strcmp (result, "0x1.cp+0 33") == 0
 638             || strcmp (result, "0x3.8p-1 33") == 0
 639             || strcmp (result, "0x7.p-2 33") == 0
 640             || strcmp (result, "0xe.p-3 33") == 0);
 641     ASSERT (retval == strlen (result));
 642   }
 643 
 644   { /* FLAG_ALT.  */
 645     int retval =
 646       my_snprintf (result, sizeof (result), "%#La %d", 1.0L, 33, 44, 55);
 647     ASSERT (strcmp (result, "0x1.p+0 33") == 0
 648             || strcmp (result, "0x2.p-1 33") == 0
 649             || strcmp (result, "0x4.p-2 33") == 0
 650             || strcmp (result, "0x8.p-3 33") == 0);
 651     ASSERT (retval == strlen (result));
 652   }
 653 
 654   { /* FLAG_ZERO with finite number.  */
 655     int retval =
 656       my_snprintf (result, sizeof (result), "%010La %d", 1.75L, 33, 44, 55);
 657     ASSERT (strcmp (result, "0x001.cp+0 33") == 0
 658             || strcmp (result, "0x003.8p-1 33") == 0
 659             || strcmp (result, "0x00007p-2 33") == 0
 660             || strcmp (result, "0x0000ep-3 33") == 0);
 661     ASSERT (retval == strlen (result));
 662   }
 663 
 664   { /* FLAG_ZERO with infinite number.  */
 665     int retval =
 666       my_snprintf (result, sizeof (result), "%010La %d", Infinityl (), 33, 44, 55);
 667     /* "0000000inf 33" is not a valid result; see
 668        <https://lists.gnu.org/r/bug-gnulib/2007-04/msg00107.html> */
 669     ASSERT (strcmp (result, "       inf 33") == 0);
 670     ASSERT (retval == strlen (result));
 671   }
 672 
 673   { /* FLAG_ZERO with NaN.  */
 674     int retval =
 675       my_snprintf (result, sizeof (result), "%050La %d", NaNl (), 33, 44, 55);
 676     /* "0000000nan 33" is not a valid result; see
 677        <https://lists.gnu.org/r/bug-gnulib/2007-04/msg00107.html> */
 678     ASSERT (strlen (result) == 50 + 3
 679             && strisnan (result, strspn (result, " "), strlen (result) - 3, 0)
 680             && strcmp (result + strlen (result) - 3, " 33") == 0);
 681     ASSERT (retval == strlen (result));
 682   }
 683 
 684   /* Test the support of the %f format directive.  */
 685 
 686   { /* A positive number.  */
 687     int retval =
 688       my_snprintf (result, sizeof (result), "%f %d", 12.75, 33, 44, 55);
 689     ASSERT (strcmp (result, "12.750000 33") == 0);
 690     ASSERT (retval == strlen (result));
 691   }
 692 
 693   { /* A larger positive number.  */
 694     int retval =
 695       my_snprintf (result, sizeof (result), "%f %d", 1234567.0, 33, 44, 55);
 696     ASSERT (strcmp (result, "1234567.000000 33") == 0);
 697     ASSERT (retval == strlen (result));
 698   }
 699 
 700   { /* Small and large positive numbers.  */
 701     static struct { double value; const char *string; } data[] =
 702       {
 703         { 1.234321234321234e-37, "0.000000" },
 704         { 1.234321234321234e-36, "0.000000" },
 705         { 1.234321234321234e-35, "0.000000" },
 706         { 1.234321234321234e-34, "0.000000" },
 707         { 1.234321234321234e-33, "0.000000" },
 708         { 1.234321234321234e-32, "0.000000" },
 709         { 1.234321234321234e-31, "0.000000" },
 710         { 1.234321234321234e-30, "0.000000" },
 711         { 1.234321234321234e-29, "0.000000" },
 712         { 1.234321234321234e-28, "0.000000" },
 713         { 1.234321234321234e-27, "0.000000" },
 714         { 1.234321234321234e-26, "0.000000" },
 715         { 1.234321234321234e-25, "0.000000" },
 716         { 1.234321234321234e-24, "0.000000" },
 717         { 1.234321234321234e-23, "0.000000" },
 718         { 1.234321234321234e-22, "0.000000" },
 719         { 1.234321234321234e-21, "0.000000" },
 720         { 1.234321234321234e-20, "0.000000" },
 721         { 1.234321234321234e-19, "0.000000" },
 722         { 1.234321234321234e-18, "0.000000" },
 723         { 1.234321234321234e-17, "0.000000" },
 724         { 1.234321234321234e-16, "0.000000" },
 725         { 1.234321234321234e-15, "0.000000" },
 726         { 1.234321234321234e-14, "0.000000" },
 727         { 1.234321234321234e-13, "0.000000" },
 728         { 1.234321234321234e-12, "0.000000" },
 729         { 1.234321234321234e-11, "0.000000" },
 730         { 1.234321234321234e-10, "0.000000" },
 731         { 1.234321234321234e-9, "0.000000" },
 732         { 1.234321234321234e-8, "0.000000" },
 733         { 1.234321234321234e-7, "0.000000" },
 734         { 1.234321234321234e-6, "0.000001" },
 735         { 1.234321234321234e-5, "0.000012" },
 736         { 1.234321234321234e-4, "0.000123" },
 737         { 1.234321234321234e-3, "0.001234" },
 738         { 1.234321234321234e-2, "0.012343" },
 739         { 1.234321234321234e-1, "0.123432" },
 740         { 1.234321234321234, "1.234321" },
 741         { 1.234321234321234e1, "12.343212" },
 742         { 1.234321234321234e2, "123.432123" },
 743         { 1.234321234321234e3, "1234.321234" },
 744         { 1.234321234321234e4, "12343.212343" },
 745         { 1.234321234321234e5, "123432.123432" },
 746         { 1.234321234321234e6, "1234321.234321" },
 747         { 1.234321234321234e7, "12343212.343212" },
 748         { 1.234321234321234e8, "123432123.432123" },
 749         { 1.234321234321234e9, "1234321234.321234" },
 750         { 1.234321234321234e10, "12343212343.2123**" },
 751         { 1.234321234321234e11, "123432123432.123***" },
 752         { 1.234321234321234e12, "1234321234321.23****" },
 753         { 1.234321234321234e13, "12343212343212.3*****" },
 754         { 1.234321234321234e14, "123432123432123.******" },
 755         { 1.234321234321234e15, "1234321234321234.000000" },
 756         { 1.234321234321234e16, "123432123432123**.000000" },
 757         { 1.234321234321234e17, "123432123432123***.000000" },
 758         { 1.234321234321234e18, "123432123432123****.000000" },
 759         { 1.234321234321234e19, "123432123432123*****.000000" },
 760         { 1.234321234321234e20, "123432123432123******.000000" },
 761         { 1.234321234321234e21, "123432123432123*******.000000" },
 762         { 1.234321234321234e22, "123432123432123********.000000" },
 763         { 1.234321234321234e23, "123432123432123*********.000000" },
 764         { 1.234321234321234e24, "123432123432123**********.000000" },
 765         { 1.234321234321234e25, "123432123432123***********.000000" },
 766         { 1.234321234321234e26, "123432123432123************.000000" },
 767         { 1.234321234321234e27, "123432123432123*************.000000" },
 768         { 1.234321234321234e28, "123432123432123**************.000000" },
 769         { 1.234321234321234e29, "123432123432123***************.000000" },
 770         { 1.234321234321234e30, "123432123432123****************.000000" },
 771         { 1.234321234321234e31, "123432123432123*****************.000000" },
 772         { 1.234321234321234e32, "123432123432123******************.000000" },
 773         { 1.234321234321234e33, "123432123432123*******************.000000" },
 774         { 1.234321234321234e34, "123432123432123********************.000000" },
 775         { 1.234321234321234e35, "123432123432123*********************.000000" },
 776         { 1.234321234321234e36, "123432123432123**********************.000000" }
 777       };
 778     size_t k;
 779     for (k = 0; k < SIZEOF (data); k++)
 780       {
 781         int retval =
 782           my_snprintf (result, sizeof (result), "%f", data[k].value);
 783         ASSERT (strmatch (data[k].string, result));
 784         ASSERT (retval == strlen (result));
 785       }
 786   }
 787 
 788   { /* A negative number.  */
 789     int retval =
 790       my_snprintf (result, sizeof (result), "%f %d", -0.03125, 33, 44, 55);
 791     ASSERT (strcmp (result, "-0.031250 33") == 0);
 792     ASSERT (retval == strlen (result));
 793   }
 794 
 795   { /* Positive zero.  */
 796     int retval =
 797       my_snprintf (result, sizeof (result), "%f %d", 0.0, 33, 44, 55);
 798     ASSERT (strcmp (result, "0.000000 33") == 0);
 799     ASSERT (retval == strlen (result));
 800   }
 801 
 802   { /* Negative zero.  */
 803     int retval =
 804       my_snprintf (result, sizeof (result), "%f %d", minus_zerod, 33, 44, 55);
 805     if (have_minus_zero ())
 806       ASSERT (strcmp (result, "-0.000000 33") == 0);
 807     ASSERT (retval == strlen (result));
 808   }
 809 
 810   { /* Positive infinity.  */
 811     int retval =
 812       my_snprintf (result, sizeof (result), "%f %d", Infinityd (), 33, 44, 55);
 813     ASSERT (strcmp (result, "inf 33") == 0
 814             || strcmp (result, "infinity 33") == 0);
 815     ASSERT (retval == strlen (result));
 816   }
 817 
 818   { /* Negative infinity.  */
 819     int retval =
 820       my_snprintf (result, sizeof (result), "%f %d", - Infinityd (), 33, 44, 55);
 821     ASSERT (strcmp (result, "-inf 33") == 0
 822             || strcmp (result, "-infinity 33") == 0);
 823     ASSERT (retval == strlen (result));
 824   }
 825 
 826   { /* NaN.  */
 827     int retval =
 828       my_snprintf (result, sizeof (result), "%f %d", NaNd (), 33, 44, 55);
 829     ASSERT (strlen (result) >= 3 + 3
 830             && strisnan (result, 0, strlen (result) - 3, 0)
 831             && strcmp (result + strlen (result) - 3, " 33") == 0);
 832     ASSERT (retval == strlen (result));
 833   }
 834 
 835   { /* Width.  */
 836     int retval =
 837       my_snprintf (result, sizeof (result), "%10f %d", 1.75, 33, 44, 55);
 838     ASSERT (strcmp (result, "  1.750000 33") == 0);
 839     ASSERT (retval == strlen (result));
 840   }
 841 
 842   { /* FLAG_LEFT.  */
 843     int retval =
 844       my_snprintf (result, sizeof (result), "%-10f %d", 1.75, 33, 44, 55);
 845     ASSERT (strcmp (result, "1.750000   33") == 0);
 846     ASSERT (retval == strlen (result));
 847   }
 848 
 849   { /* FLAG_SHOWSIGN.  */
 850     int retval =
 851       my_snprintf (result, sizeof (result), "%+f %d", 1.75, 33, 44, 55);
 852     ASSERT (strcmp (result, "+1.750000 33") == 0);
 853     ASSERT (retval == strlen (result));
 854   }
 855 
 856   { /* FLAG_SPACE.  */
 857     int retval =
 858       my_snprintf (result, sizeof (result), "% f %d", 1.75, 33, 44, 55);
 859     ASSERT (strcmp (result, " 1.750000 33") == 0);
 860     ASSERT (retval == strlen (result));
 861   }
 862 
 863   { /* FLAG_ALT.  */
 864     int retval =
 865       my_snprintf (result, sizeof (result), "%#f %d", 1.75, 33, 44, 55);
 866     ASSERT (strcmp (result, "1.750000 33") == 0);
 867     ASSERT (retval == strlen (result));
 868   }
 869 
 870   { /* FLAG_ALT.  */
 871     int retval =
 872       my_snprintf (result, sizeof (result), "%#.f %d", 1.75, 33, 44, 55);
 873     ASSERT (strcmp (result, "2. 33") == 0);
 874     ASSERT (retval == strlen (result));
 875   }
 876 
 877   { /* FLAG_ZERO with finite number.  */
 878     int retval =
 879       my_snprintf (result, sizeof (result), "%015f %d", 1234.0, 33, 44, 55);
 880     ASSERT (strcmp (result, "00001234.000000 33") == 0);
 881     ASSERT (retval == strlen (result));
 882   }
 883 
 884   { /* FLAG_ZERO with infinite number.  */
 885     int retval =
 886       my_snprintf (result, sizeof (result), "%015f %d", - Infinityd (), 33, 44, 55);
 887     ASSERT (strcmp (result, "           -inf 33") == 0
 888             || strcmp (result, "      -infinity 33") == 0);
 889     ASSERT (retval == strlen (result));
 890   }
 891 
 892   { /* FLAG_ZERO with NaN.  */
 893     int retval =
 894       my_snprintf (result, sizeof (result), "%050f %d", NaNd (), 33, 44, 55);
 895     ASSERT (strlen (result) == 50 + 3
 896             && strisnan (result, strspn (result, " "), strlen (result) - 3, 0)
 897             && strcmp (result + strlen (result) - 3, " 33") == 0);
 898     ASSERT (retval == strlen (result));
 899   }
 900 
 901   { /* Precision.  */
 902     int retval =
 903       my_snprintf (result, sizeof (result), "%.f %d", 1234.0, 33, 44, 55);
 904     ASSERT (strcmp (result, "1234 33") == 0);
 905     ASSERT (retval == strlen (result));
 906   }
 907 
 908   { /* Precision with no rounding.  */
 909     int retval =
 910       my_snprintf (result, sizeof (result), "%.2f %d", 999.951, 33, 44, 55);
 911     ASSERT (strcmp (result, "999.95 33") == 0);
 912     ASSERT (retval == strlen (result));
 913   }
 914 
 915   { /* Precision with rounding.  */
 916     int retval =
 917       my_snprintf (result, sizeof (result), "%.2f %d", 999.996, 33, 44, 55);
 918     ASSERT (strcmp (result, "1000.00 33") == 0);
 919     ASSERT (retval == strlen (result));
 920   }
 921 
 922   { /* A positive number.  */
 923     int retval =
 924       my_snprintf (result, sizeof (result), "%Lf %d", 12.75L, 33, 44, 55);
 925     ASSERT (strcmp (result, "12.750000 33") == 0);
 926     ASSERT (retval == strlen (result));
 927   }
 928 
 929   { /* A larger positive number.  */
 930     int retval =
 931       my_snprintf (result, sizeof (result), "%Lf %d", 1234567.0L, 33, 44, 55);
 932     ASSERT (strcmp (result, "1234567.000000 33") == 0);
 933     ASSERT (retval == strlen (result));
 934   }
 935 
 936   { /* Small and large positive numbers.  */
 937     static struct { long double value; const char *string; } data[] =
 938       {
 939         { 1.234321234321234e-37L, "0.000000" },
 940         { 1.234321234321234e-36L, "0.000000" },
 941         { 1.234321234321234e-35L, "0.000000" },
 942         { 1.234321234321234e-34L, "0.000000" },
 943         { 1.234321234321234e-33L, "0.000000" },
 944         { 1.234321234321234e-32L, "0.000000" },
 945         { 1.234321234321234e-31L, "0.000000" },
 946         { 1.234321234321234e-30L, "0.000000" },
 947         { 1.234321234321234e-29L, "0.000000" },
 948         { 1.234321234321234e-28L, "0.000000" },
 949         { 1.234321234321234e-27L, "0.000000" },
 950         { 1.234321234321234e-26L, "0.000000" },
 951         { 1.234321234321234e-25L, "0.000000" },
 952         { 1.234321234321234e-24L, "0.000000" },
 953         { 1.234321234321234e-23L, "0.000000" },
 954         { 1.234321234321234e-22L, "0.000000" },
 955         { 1.234321234321234e-21L, "0.000000" },
 956         { 1.234321234321234e-20L, "0.000000" },
 957         { 1.234321234321234e-19L, "0.000000" },
 958         { 1.234321234321234e-18L, "0.000000" },
 959         { 1.234321234321234e-17L, "0.000000" },
 960         { 1.234321234321234e-16L, "0.000000" },
 961         { 1.234321234321234e-15L, "0.000000" },
 962         { 1.234321234321234e-14L, "0.000000" },
 963         { 1.234321234321234e-13L, "0.000000" },
 964         { 1.234321234321234e-12L, "0.000000" },
 965         { 1.234321234321234e-11L, "0.000000" },
 966         { 1.234321234321234e-10L, "0.000000" },
 967         { 1.234321234321234e-9L, "0.000000" },
 968         { 1.234321234321234e-8L, "0.000000" },
 969         { 1.234321234321234e-7L, "0.000000" },
 970         { 1.234321234321234e-6L, "0.000001" },
 971         { 1.234321234321234e-5L, "0.000012" },
 972         { 1.234321234321234e-4L, "0.000123" },
 973         { 1.234321234321234e-3L, "0.001234" },
 974         { 1.234321234321234e-2L, "0.012343" },
 975         { 1.234321234321234e-1L, "0.123432" },
 976         { 1.234321234321234L, "1.234321" },
 977         { 1.234321234321234e1L, "12.343212" },
 978         { 1.234321234321234e2L, "123.432123" },
 979         { 1.234321234321234e3L, "1234.321234" },
 980         { 1.234321234321234e4L, "12343.212343" },
 981         { 1.234321234321234e5L, "123432.123432" },
 982         { 1.234321234321234e6L, "1234321.234321" },
 983         { 1.234321234321234e7L, "12343212.343212" },
 984         { 1.234321234321234e8L, "123432123.432123" },
 985         { 1.234321234321234e9L, "1234321234.321234" },
 986         { 1.234321234321234e10L, "12343212343.2123**" },
 987         { 1.234321234321234e11L, "123432123432.123***" },
 988         { 1.234321234321234e12L, "1234321234321.23****" },
 989         { 1.234321234321234e13L, "12343212343212.3*****" },
 990         { 1.234321234321234e14L, "123432123432123.******" },
 991         { 1.234321234321234e15L, "1234321234321234.000000" },
 992         { 1.234321234321234e16L, "123432123432123**.000000" },
 993         { 1.234321234321234e17L, "123432123432123***.000000" },
 994         { 1.234321234321234e18L, "123432123432123****.000000" },
 995         { 1.234321234321234e19L, "123432123432123*****.000000" },
 996         { 1.234321234321234e20L, "123432123432123******.000000" },
 997         { 1.234321234321234e21L, "123432123432123*******.000000" },
 998         { 1.234321234321234e22L, "123432123432123********.000000" },
 999         { 1.234321234321234e23L, "123432123432123*********.000000" },
1000         { 1.234321234321234e24L, "123432123432123**********.000000" },
1001         { 1.234321234321234e25L, "123432123432123***********.000000" },
1002         { 1.234321234321234e26L, "123432123432123************.000000" },
1003         { 1.234321234321234e27L, "123432123432123*************.000000" },
1004         { 1.234321234321234e28L, "123432123432123**************.000000" },
1005         { 1.234321234321234e29L, "123432123432123***************.000000" },
1006         { 1.234321234321234e30L, "123432123432123****************.000000" },
1007         { 1.234321234321234e31L, "123432123432123*****************.000000" },
1008         { 1.234321234321234e32L, "123432123432123******************.000000" },
1009         { 1.234321234321234e33L, "123432123432123*******************.000000" },
1010         { 1.234321234321234e34L, "123432123432123********************.000000" },
1011         { 1.234321234321234e35L, "123432123432123*********************.000000" },
1012         { 1.234321234321234e36L, "123432123432123**********************.000000" }
1013       };
1014     size_t k;
1015     for (k = 0; k < SIZEOF (data); k++)
1016       {
1017         int retval =
1018           my_snprintf (result, sizeof (result), "%Lf", data[k].value);
1019         ASSERT (strmatch (data[k].string, result));
1020         ASSERT (retval == strlen (result));
1021       }
1022   }
1023 
1024   { /* A negative number.  */
1025     int retval =
1026       my_snprintf (result, sizeof (result), "%Lf %d", -0.03125L, 33, 44, 55);
1027     ASSERT (strcmp (result, "-0.031250 33") == 0);
1028     ASSERT (retval == strlen (result));
1029   }
1030 
1031   { /* Positive zero.  */
1032     int retval =
1033       my_snprintf (result, sizeof (result), "%Lf %d", 0.0L, 33, 44, 55);
1034     ASSERT (strcmp (result, "0.000000 33") == 0);
1035     ASSERT (retval == strlen (result));
1036   }
1037 
1038   { /* Negative zero.  */
1039     int retval =
1040       my_snprintf (result, sizeof (result), "%Lf %d", minus_zerol, 33, 44, 55);
1041     if (have_minus_zero ())
1042       ASSERT (strcmp (result, "-0.000000 33") == 0);
1043     ASSERT (retval == strlen (result));
1044   }
1045 
1046   { /* Positive infinity.  */
1047     int retval =
1048       my_snprintf (result, sizeof (result), "%Lf %d", Infinityl (), 33, 44, 55);
1049     ASSERT (strcmp (result, "inf 33") == 0
1050             || strcmp (result, "infinity 33") == 0);
1051     ASSERT (retval == strlen (result));
1052   }
1053 
1054   { /* Negative infinity.  */
1055     int retval =
1056       my_snprintf (result, sizeof (result), "%Lf %d", - Infinityl (), 33, 44, 55);
1057     ASSERT (strcmp (result, "-inf 33") == 0
1058             || strcmp (result, "-infinity 33") == 0);
1059     ASSERT (retval == strlen (result));
1060   }
1061 
1062   { /* NaN.  */
1063     int retval =
1064       my_snprintf (result, sizeof (result), "%Lf %d", NaNl (), 33, 44, 55);
1065     ASSERT (strlen (result) >= 3 + 3
1066             && strisnan (result, 0, strlen (result) - 3, 0)
1067             && strcmp (result + strlen (result) - 3, " 33") == 0);
1068     ASSERT (retval == strlen (result));
1069   }
1070 #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
1071   { /* Quiet NaN.  */
1072     static union { unsigned int word[4]; long double value; } x =
1073       { LDBL80_WORDS (0xFFFF, 0xC3333333, 0x00000000) };
1074     int retval =
1075       my_snprintf (result, sizeof (result), "%Lf %d", x.value, 33, 44, 55);
1076     ASSERT (strlen (result) >= 3 + 3
1077             && strisnan (result, 0, strlen (result) - 3, 0)
1078             && strcmp (result + strlen (result) - 3, " 33") == 0);
1079     ASSERT (retval == strlen (result));
1080   }
1081   {
1082     /* Signalling NaN.  */
1083     static union { unsigned int word[4]; long double value; } x =
1084       { LDBL80_WORDS (0xFFFF, 0x83333333, 0x00000000) };
1085     int retval =
1086       my_snprintf (result, sizeof (result), "%Lf %d", x.value, 33, 44, 55);
1087     ASSERT (strlen (result) >= 3 + 3
1088             && strisnan (result, 0, strlen (result) - 3, 0)
1089             && strcmp (result + strlen (result) - 3, " 33") == 0);
1090     ASSERT (retval == strlen (result));
1091   }
1092   /* snprintf should print something for noncanonical values.  */
1093   { /* Pseudo-NaN.  */
1094     static union { unsigned int word[4]; long double value; } x =
1095       { LDBL80_WORDS (0xFFFF, 0x40000001, 0x00000000) };
1096     int retval =
1097       my_snprintf (result, sizeof (result), "%Lf %d", x.value, 33, 44, 55);
1098     ASSERT (retval == strlen (result));
1099     ASSERT (3 < retval && strcmp (result + retval - 3, " 33") == 0);
1100   }
1101   { /* Pseudo-Infinity.  */
1102     static union { unsigned int word[4]; long double value; } x =
1103       { LDBL80_WORDS (0xFFFF, 0x00000000, 0x00000000) };
1104     int retval =
1105       my_snprintf (result, sizeof (result), "%Lf %d", x.value, 33, 44, 55);
1106     ASSERT (retval == strlen (result));
1107     ASSERT (3 < retval && strcmp (result + retval - 3, " 33") == 0);
1108   }
1109   { /* Pseudo-Zero.  */
1110     static union { unsigned int word[4]; long double value; } x =
1111       { LDBL80_WORDS (0x4004, 0x00000000, 0x00000000) };
1112     int retval =
1113       my_snprintf (result, sizeof (result), "%Lf %d", x.value, 33, 44, 55);
1114     ASSERT (retval == strlen (result));
1115     ASSERT (3 < retval && strcmp (result + retval - 3, " 33") == 0);
1116   }
1117   { /* Unnormalized number.  */
1118     static union { unsigned int word[4]; long double value; } x =
1119       { LDBL80_WORDS (0x4000, 0x63333333, 0x00000000) };
1120     int retval =
1121       my_snprintf (result, sizeof (result), "%Lf %d", x.value, 33, 44, 55);
1122     ASSERT (retval == strlen (result));
1123     ASSERT (3 < retval && strcmp (result + retval - 3, " 33") == 0);
1124   }
1125   { /* Pseudo-Denormal.  */
1126     static union { unsigned int word[4]; long double value; } x =
1127       { LDBL80_WORDS (0x0000, 0x83333333, 0x00000000) };
1128     int retval =
1129       my_snprintf (result, sizeof (result), "%Lf %d", x.value, 33, 44, 55);
1130     ASSERT (retval == strlen (result));
1131     ASSERT (3 < retval && strcmp (result + retval - 3, " 33") == 0);
1132   }
1133 #endif
1134 
1135   { /* Width.  */
1136     int retval =
1137       my_snprintf (result, sizeof (result), "%10Lf %d", 1.75L, 33, 44, 55);
1138     ASSERT (strcmp (result, "  1.750000 33") == 0);
1139     ASSERT (retval == strlen (result));
1140   }
1141 
1142   { /* FLAG_LEFT.  */
1143     int retval =
1144       my_snprintf (result, sizeof (result), "%-10Lf %d", 1.75L, 33, 44, 55);
1145     ASSERT (strcmp (result, "1.750000   33") == 0);
1146     ASSERT (retval == strlen (result));
1147   }
1148 
1149   { /* FLAG_SHOWSIGN.  */
1150     int retval =
1151       my_snprintf (result, sizeof (result), "%+Lf %d", 1.75L, 33, 44, 55);
1152     ASSERT (strcmp (result, "+1.750000 33") == 0);
1153     ASSERT (retval == strlen (result));
1154   }
1155 
1156   { /* FLAG_SPACE.  */
1157     int retval =
1158       my_snprintf (result, sizeof (result), "% Lf %d", 1.75L, 33, 44, 55);
1159     ASSERT (strcmp (result, " 1.750000 33") == 0);
1160     ASSERT (retval == strlen (result));
1161   }
1162 
1163   { /* FLAG_ALT.  */
1164     int retval =
1165       my_snprintf (result, sizeof (result), "%#Lf %d", 1.75L, 33, 44, 55);
1166     ASSERT (strcmp (result, "1.750000 33") == 0);
1167     ASSERT (retval == strlen (result));
1168   }
1169 
1170   { /* FLAG_ALT.  */
1171     int retval =
1172       my_snprintf (result, sizeof (result), "%#.Lf %d", 1.75L, 33, 44, 55);
1173     ASSERT (strcmp (result, "2. 33") == 0);
1174     ASSERT (retval == strlen (result));
1175   }
1176 
1177   { /* FLAG_ZERO with finite number.  */
1178     int retval =
1179       my_snprintf (result, sizeof (result), "%015Lf %d", 1234.0L, 33, 44, 55);
1180     ASSERT (strcmp (result, "00001234.000000 33") == 0);
1181     ASSERT (retval == strlen (result));
1182   }
1183 
1184   { /* FLAG_ZERO with infinite number.  */
1185     int retval =
1186       my_snprintf (result, sizeof (result), "%015Lf %d", - Infinityl (), 33, 44, 55);
1187     ASSERT (strcmp (result, "           -inf 33") == 0
1188             || strcmp (result, "      -infinity 33") == 0);
1189     ASSERT (retval == strlen (result));
1190   }
1191 
1192   { /* FLAG_ZERO with NaN.  */
1193     int retval =
1194       my_snprintf (result, sizeof (result), "%050Lf %d", NaNl (), 33, 44, 55);
1195     ASSERT (strlen (result) == 50 + 3
1196             && strisnan (result, strspn (result, " "), strlen (result) - 3, 0)
1197             && strcmp (result + strlen (result) - 3, " 33") == 0);
1198     ASSERT (retval == strlen (result));
1199   }
1200 
1201   { /* Precision.  */
1202     int retval =
1203       my_snprintf (result, sizeof (result), "%.Lf %d", 1234.0L, 33, 44, 55);
1204     ASSERT (strcmp (result, "1234 33") == 0);
1205     ASSERT (retval == strlen (result));
1206   }
1207 
1208   { /* Precision with no rounding.  */
1209     int retval =
1210       my_snprintf (result, sizeof (result), "%.2Lf %d", 999.951L, 33, 44, 55);
1211     ASSERT (strcmp (result, "999.95 33") == 0);
1212     ASSERT (retval == strlen (result));
1213   }
1214 
1215   { /* Precision with rounding.  */
1216     int retval =
1217       my_snprintf (result, sizeof (result), "%.2Lf %d", 999.996L, 33, 44, 55);
1218     ASSERT (strcmp (result, "1000.00 33") == 0);
1219     ASSERT (retval == strlen (result));
1220   }
1221 
1222   /* Test the support of the %F format directive.  */
1223 
1224   { /* A positive number.  */
1225     int retval =
1226       my_snprintf (result, sizeof (result), "%F %d", 12.75, 33, 44, 55);
1227     ASSERT (strcmp (result, "12.750000 33") == 0);
1228     ASSERT (retval == strlen (result));
1229   }
1230 
1231   { /* A larger positive number.  */
1232     int retval =
1233       my_snprintf (result, sizeof (result), "%F %d", 1234567.0, 33, 44, 55);
1234     ASSERT (strcmp (result, "1234567.000000 33") == 0);
1235     ASSERT (retval == strlen (result));
1236   }
1237 
1238   { /* A negative number.  */
1239     int retval =
1240       my_snprintf (result, sizeof (result), "%F %d", -0.03125, 33, 44, 55);
1241     ASSERT (strcmp (result, "-0.031250 33") == 0);
1242     ASSERT (retval == strlen (result));
1243   }
1244 
1245   { /* Positive zero.  */
1246     int retval =
1247       my_snprintf (result, sizeof (result), "%F %d", 0.0, 33, 44, 55);
1248     ASSERT (strcmp (result, "0.000000 33") == 0);
1249     ASSERT (retval == strlen (result));
1250   }
1251 
1252   { /* Negative zero.  */
1253     int retval =
1254       my_snprintf (result, sizeof (result), "%F %d", minus_zerod, 33, 44, 55);
1255     if (have_minus_zero ())
1256       ASSERT (strcmp (result, "-0.000000 33") == 0);
1257     ASSERT (retval == strlen (result));
1258   }
1259 
1260   { /* Positive infinity.  */
1261     int retval =
1262       my_snprintf (result, sizeof (result), "%F %d", Infinityd (), 33, 44, 55);
1263     ASSERT (strcmp (result, "INF 33") == 0
1264             || strcmp (result, "INFINITY 33") == 0);
1265     ASSERT (retval == strlen (result));
1266   }
1267 
1268   { /* Negative infinity.  */
1269     int retval =
1270       my_snprintf (result, sizeof (result), "%F %d", - Infinityd (), 33, 44, 55);
1271     ASSERT (strcmp (result, "-INF 33") == 0
1272             || strcmp (result, "-INFINITY 33") == 0);
1273     ASSERT (retval == strlen (result));
1274   }
1275 
1276   { /* NaN.  */
1277     int retval =
1278       my_snprintf (result, sizeof (result), "%F %d", NaNd (), 33, 44, 55);
1279     ASSERT (strlen (result) >= 3 + 3
1280             && strisnan (result, 0, strlen (result) - 3, 1)
1281             && strcmp (result + strlen (result) - 3, " 33") == 0);
1282     ASSERT (retval == strlen (result));
1283   }
1284 
1285   { /* FLAG_ZERO.  */
1286     int retval =
1287       my_snprintf (result, sizeof (result), "%015F %d", 1234.0, 33, 44, 55);
1288     ASSERT (strcmp (result, "00001234.000000 33") == 0);
1289     ASSERT (retval == strlen (result));
1290   }
1291 
1292   { /* FLAG_ZERO with infinite number.  */
1293     int retval =
1294       my_snprintf (result, sizeof (result), "%015F %d", - Infinityd (), 33, 44, 55);
1295     ASSERT (strcmp (result, "           -INF 33") == 0
1296             || strcmp (result, "      -INFINITY 33") == 0);
1297     ASSERT (retval == strlen (result));
1298   }
1299 
1300   { /* Precision.  */
1301     int retval =
1302       my_snprintf (result, sizeof (result), "%.F %d", 1234.0, 33, 44, 55);
1303     ASSERT (strcmp (result, "1234 33") == 0);
1304     ASSERT (retval == strlen (result));
1305   }
1306 
1307   { /* Precision with no rounding.  */
1308     int retval =
1309       my_snprintf (result, sizeof (result), "%.2F %d", 999.951, 33, 44, 55);
1310     ASSERT (strcmp (result, "999.95 33") == 0);
1311     ASSERT (retval == strlen (result));
1312   }
1313 
1314   { /* Precision with rounding.  */
1315     int retval =
1316       my_snprintf (result, sizeof (result), "%.2F %d", 999.996, 33, 44, 55);
1317     ASSERT (strcmp (result, "1000.00 33") == 0);
1318     ASSERT (retval == strlen (result));
1319   }
1320 
1321   { /* A positive number.  */
1322     int retval =
1323       my_snprintf (result, sizeof (result), "%LF %d", 12.75L, 33, 44, 55);
1324     ASSERT (strcmp (result, "12.750000 33") == 0);
1325     ASSERT (retval == strlen (result));
1326   }
1327 
1328   { /* A larger positive number.  */
1329     int retval =
1330       my_snprintf (result, sizeof (result), "%LF %d", 1234567.0L, 33, 44, 55);
1331     ASSERT (strcmp (result, "1234567.000000 33") == 0);
1332     ASSERT (retval == strlen (result));
1333   }
1334 
1335   { /* A negative number.  */
1336     int retval =
1337       my_snprintf (result, sizeof (result), "%LF %d", -0.03125L, 33, 44, 55);
1338     ASSERT (strcmp (result, "-0.031250 33") == 0);
1339     ASSERT (retval == strlen (result));
1340   }
1341 
1342   { /* Positive zero.  */
1343     int retval =
1344       my_snprintf (result, sizeof (result), "%LF %d", 0.0L, 33, 44, 55);
1345     ASSERT (strcmp (result, "0.000000 33") == 0);
1346     ASSERT (retval == strlen (result));
1347   }
1348 
1349   { /* Negative zero.  */
1350     int retval =
1351       my_snprintf (result, sizeof (result), "%LF %d", minus_zerol, 33, 44, 55);
1352     if (have_minus_zero ())
1353       ASSERT (strcmp (result, "-0.000000 33") == 0);
1354     ASSERT (retval == strlen (result));
1355   }
1356 
1357   { /* Positive infinity.  */
1358     int retval =
1359       my_snprintf (result, sizeof (result), "%LF %d", Infinityl (), 33, 44, 55);
1360     ASSERT (strcmp (result, "INF 33") == 0
1361             || strcmp (result, "INFINITY 33") == 0);
1362     ASSERT (retval == strlen (result));
1363   }
1364 
1365   { /* Negative infinity.  */
1366     int retval =
1367       my_snprintf (result, sizeof (result), "%LF %d", - Infinityl (), 33, 44, 55);
1368     ASSERT (strcmp (result, "-INF 33") == 0
1369             || strcmp (result, "-INFINITY 33") == 0);
1370     ASSERT (retval == strlen (result));
1371   }
1372 
1373   { /* NaN.  */
1374     int retval =
1375       my_snprintf (result, sizeof (result), "%LF %d", NaNl (), 33, 44, 55);
1376     ASSERT (strlen (result) >= 3 + 3
1377             && strisnan (result, 0, strlen (result) - 3, 1)
1378             && strcmp (result + strlen (result) - 3, " 33") == 0);
1379     ASSERT (retval == strlen (result));
1380   }
1381 
1382   { /* FLAG_ZERO.  */
1383     int retval =
1384       my_snprintf (result, sizeof (result), "%015LF %d", 1234.0L, 33, 44, 55);
1385     ASSERT (strcmp (result, "00001234.000000 33") == 0);
1386     ASSERT (retval == strlen (result));
1387   }
1388 
1389   { /* FLAG_ZERO with infinite number.  */
1390     int retval =
1391       my_snprintf (result, sizeof (result), "%015LF %d", - Infinityl (), 33, 44, 55);
1392     ASSERT (strcmp (result, "           -INF 33") == 0
1393             || strcmp (result, "      -INFINITY 33") == 0);
1394     ASSERT (retval == strlen (result));
1395   }
1396 
1397   { /* Precision.  */
1398     int retval =
1399       my_snprintf (result, sizeof (result), "%.LF %d", 1234.0L, 33, 44, 55);
1400     ASSERT (strcmp (result, "1234 33") == 0);
1401     ASSERT (retval == strlen (result));
1402   }
1403 
1404   { /* Precision with no rounding.  */
1405     int retval =
1406       my_snprintf (result, sizeof (result), "%.2LF %d", 999.951L, 33, 44, 55);
1407     ASSERT (strcmp (result, "999.95 33") == 0);
1408     ASSERT (retval == strlen (result));
1409   }
1410 
1411   { /* Precision with rounding.  */
1412     int retval =
1413       my_snprintf (result, sizeof (result), "%.2LF %d", 999.996L, 33, 44, 55);
1414     ASSERT (strcmp (result, "1000.00 33") == 0);
1415     ASSERT (retval == strlen (result));
1416   }
1417 
1418   /* Test the support of the %e format directive.  */
1419 
1420   { /* A positive number.  */
1421     int retval =
1422       my_snprintf (result, sizeof (result), "%e %d", 12.75, 33, 44, 55);
1423     ASSERT (strcmp (result, "1.275000e+01 33") == 0
1424             || strcmp (result, "1.275000e+001 33") == 0);
1425     ASSERT (retval == strlen (result));
1426   }
1427 
1428   { /* A larger positive number.  */
1429     int retval =
1430       my_snprintf (result, sizeof (result), "%e %d", 1234567.0, 33, 44, 55);
1431     ASSERT (strcmp (result, "1.234567e+06 33") == 0
1432             || strcmp (result, "1.234567e+006 33") == 0);
1433     ASSERT (retval == strlen (result));
1434   }
1435 
1436   { /* Small and large positive numbers.  */
1437     static struct { double value; const char *string; } data[] =
1438       {
1439         { 1.234321234321234e-37, "1.234321e-37" },
1440         { 1.234321234321234e-36, "1.234321e-36" },
1441         { 1.234321234321234e-35, "1.234321e-35" },
1442         { 1.234321234321234e-34, "1.234321e-34" },
1443         { 1.234321234321234e-33, "1.234321e-33" },
1444         { 1.234321234321234e-32, "1.234321e-32" },
1445         { 1.234321234321234e-31, "1.234321e-31" },
1446         { 1.234321234321234e-30, "1.234321e-30" },
1447         { 1.234321234321234e-29, "1.234321e-29" },
1448         { 1.234321234321234e-28, "1.234321e-28" },
1449         { 1.234321234321234e-27, "1.234321e-27" },
1450         { 1.234321234321234e-26, "1.234321e-26" },
1451         { 1.234321234321234e-25, "1.234321e-25" },
1452         { 1.234321234321234e-24, "1.234321e-24" },
1453         { 1.234321234321234e-23, "1.234321e-23" },
1454         { 1.234321234321234e-22, "1.234321e-22" },
1455         { 1.234321234321234e-21, "1.234321e-21" },
1456         { 1.234321234321234e-20, "1.234321e-20" },
1457         { 1.234321234321234e-19, "1.234321e-19" },
1458         { 1.234321234321234e-18, "1.234321e-18" },
1459         { 1.234321234321234e-17, "1.234321e-17" },
1460         { 1.234321234321234e-16, "1.234321e-16" },
1461         { 1.234321234321234e-15, "1.234321e-15" },
1462         { 1.234321234321234e-14, "1.234321e-14" },
1463         { 1.234321234321234e-13, "1.234321e-13" },
1464         { 1.234321234321234e-12, "1.234321e-12" },
1465         { 1.234321234321234e-11, "1.234321e-11" },
1466         { 1.234321234321234e-10, "1.234321e-10" },
1467         { 1.234321234321234e-9, "1.234321e-09" },
1468         { 1.234321234321234e-8, "1.234321e-08" },
1469         { 1.234321234321234e-7, "1.234321e-07" },
1470         { 1.234321234321234e-6, "1.234321e-06" },
1471         { 1.234321234321234e-5, "1.234321e-05" },
1472         { 1.234321234321234e-4, "1.234321e-04" },
1473         { 1.234321234321234e-3, "1.234321e-03" },
1474         { 1.234321234321234e-2, "1.234321e-02" },
1475         { 1.234321234321234e-1, "1.234321e-01" },
1476         { 1.234321234321234, "1.234321e+00" },
1477         { 1.234321234321234e1, "1.234321e+01" },
1478         { 1.234321234321234e2, "1.234321e+02" },
1479         { 1.234321234321234e3, "1.234321e+03" },
1480         { 1.234321234321234e4, "1.234321e+04" },
1481         { 1.234321234321234e5, "1.234321e+05" },
1482         { 1.234321234321234e6, "1.234321e+06" },
1483         { 1.234321234321234e7, "1.234321e+07" },
1484         { 1.234321234321234e8, "1.234321e+08" },
1485         { 1.234321234321234e9, "1.234321e+09" },
1486         { 1.234321234321234e10, "1.234321e+10" },
1487         { 1.234321234321234e11, "1.234321e+11" },
1488         { 1.234321234321234e12, "1.234321e+12" },
1489         { 1.234321234321234e13, "1.234321e+13" },
1490         { 1.234321234321234e14, "1.234321e+14" },
1491         { 1.234321234321234e15, "1.234321e+15" },
1492         { 1.234321234321234e16, "1.234321e+16" },
1493         { 1.234321234321234e17, "1.234321e+17" },
1494         { 1.234321234321234e18, "1.234321e+18" },
1495         { 1.234321234321234e19, "1.234321e+19" },
1496         { 1.234321234321234e20, "1.234321e+20" },
1497         { 1.234321234321234e21, "1.234321e+21" },
1498         { 1.234321234321234e22, "1.234321e+22" },
1499         { 1.234321234321234e23, "1.234321e+23" },
1500         { 1.234321234321234e24, "1.234321e+24" },
1501         { 1.234321234321234e25, "1.234321e+25" },
1502         { 1.234321234321234e26, "1.234321e+26" },
1503         { 1.234321234321234e27, "1.234321e+27" },
1504         { 1.234321234321234e28, "1.234321e+28" },
1505         { 1.234321234321234e29, "1.234321e+29" },
1506         { 1.234321234321234e30, "1.234321e+30" },
1507         { 1.234321234321234e31, "1.234321e+31" },
1508         { 1.234321234321234e32, "1.234321e+32" },
1509         { 1.234321234321234e33, "1.234321e+33" },
1510         { 1.234321234321234e34, "1.234321e+34" },
1511         { 1.234321234321234e35, "1.234321e+35" },
1512         { 1.234321234321234e36, "1.234321e+36" }
1513       };
1514     size_t k;
1515     for (k = 0; k < SIZEOF (data); k++)
1516       {
1517         int retval =
1518           my_snprintf (result, sizeof (result), "%e", data[k].value);
1519         const char *expected = data[k].string;
1520         ASSERT (strcmp (result, expected) == 0
1521                 /* Some implementations produce exponents with 3 digits.  */
1522                 || (strlen (result) == strlen (expected) + 1
1523                     && memcmp (result, expected, strlen (expected) - 2) == 0
1524                     && result[strlen (expected) - 2] == '0'
1525                     && strcmp (result + strlen (expected) - 1,
1526                                expected + strlen (expected) - 2)
1527                        == 0));
1528         ASSERT (retval == strlen (result));
1529       }
1530   }
1531 
1532   { /* A negative number.  */
1533     int retval =
1534       my_snprintf (result, sizeof (result), "%e %d", -0.03125, 33, 44, 55);
1535     ASSERT (strcmp (result, "-3.125000e-02 33") == 0
1536             || strcmp (result, "-3.125000e-002 33") == 0);
1537     ASSERT (retval == strlen (result));
1538   }
1539 
1540   { /* Positive zero.  */
1541     int retval =
1542       my_snprintf (result, sizeof (result), "%e %d", 0.0, 33, 44, 55);
1543     ASSERT (strcmp (result, "0.000000e+00 33") == 0
1544             || strcmp (result, "0.000000e+000 33") == 0);
1545     ASSERT (retval == strlen (result));
1546   }
1547 
1548   { /* Negative zero.  */
1549     int retval =
1550       my_snprintf (result, sizeof (result), "%e %d", minus_zerod, 33, 44, 55);
1551     if (have_minus_zero ())
1552       ASSERT (strcmp (result, "-0.000000e+00 33") == 0
1553               || strcmp (result, "-0.000000e+000 33") == 0);
1554     ASSERT (retval == strlen (result));
1555   }
1556 
1557   { /* Positive infinity.  */
1558     int retval =
1559       my_snprintf (result, sizeof (result), "%e %d", Infinityd (), 33, 44, 55);
1560     ASSERT (strcmp (result, "inf 33") == 0
1561             || strcmp (result, "infinity 33") == 0);
1562     ASSERT (retval == strlen (result));
1563   }
1564 
1565   { /* Negative infinity.  */
1566     int retval =
1567       my_snprintf (result, sizeof (result), "%e %d", - Infinityd (), 33, 44, 55);
1568     ASSERT (strcmp (result, "-inf 33") == 0
1569             || strcmp (result, "-infinity 33") == 0);
1570     ASSERT (retval == strlen (result));
1571   }
1572 
1573   { /* NaN.  */
1574     int retval =
1575       my_snprintf (result, sizeof (result), "%e %d", NaNd (), 33, 44, 55);
1576     ASSERT (strlen (result) >= 3 + 3
1577             && strisnan (result, 0, strlen (result) - 3, 0)
1578             && strcmp (result + strlen (result) - 3, " 33") == 0);
1579     ASSERT (retval == strlen (result));
1580   }
1581 
1582   { /* Width.  */
1583     int retval =
1584       my_snprintf (result, sizeof (result), "%15e %d", 1.75, 33, 44, 55);
1585     ASSERT (strcmp (result, "   1.750000e+00 33") == 0
1586             || strcmp (result, "  1.750000e+000 33") == 0);
1587     ASSERT (retval == strlen (result));
1588   }
1589 
1590   { /* FLAG_LEFT.  */
1591     int retval =
1592       my_snprintf (result, sizeof (result), "%-15e %d", 1.75, 33, 44, 55);
1593     ASSERT (strcmp (result, "1.750000e+00    33") == 0
1594             || strcmp (result, "1.750000e+000   33") == 0);
1595     ASSERT (retval == strlen (result));
1596   }
1597 
1598   { /* FLAG_SHOWSIGN.  */
1599     int retval =
1600       my_snprintf (result, sizeof (result), "%+e %d", 1.75, 33, 44, 55);
1601     ASSERT (strcmp (result, "+1.750000e+00 33") == 0
1602             || strcmp (result, "+1.750000e+000 33") == 0);
1603     ASSERT (retval == strlen (result));
1604   }
1605 
1606   { /* FLAG_SPACE.  */
1607     int retval =
1608       my_snprintf (result, sizeof (result), "% e %d", 1.75, 33, 44, 55);
1609     ASSERT (strcmp (result, " 1.750000e+00 33") == 0
1610             || strcmp (result, " 1.750000e+000 33") == 0);
1611     ASSERT (retval == strlen (result));
1612   }
1613 
1614   { /* FLAG_ALT.  */
1615     int retval =
1616       my_snprintf (result, sizeof (result), "%#e %d", 1.75, 33, 44, 55);
1617     ASSERT (strcmp (result, "1.750000e+00 33") == 0
1618             || strcmp (result, "1.750000e+000 33") == 0);
1619     ASSERT (retval == strlen (result));
1620   }
1621 
1622   { /* FLAG_ALT.  */
1623     int retval =
1624       my_snprintf (result, sizeof (result), "%#.e %d", 1.75, 33, 44, 55);
1625     ASSERT (strcmp (result, "2.e+00 33") == 0
1626             || strcmp (result, "2.e+000 33") == 0);
1627     ASSERT (retval == strlen (result));
1628   }
1629 
1630   { /* FLAG_ALT.  */
1631     int retval =
1632       my_snprintf (result, sizeof (result), "%#.e %d", 9.75, 33, 44, 55);
1633     ASSERT (strcmp (result, "1.e+01 33") == 0
1634             || strcmp (result, "1.e+001 33") == 0);
1635     ASSERT (retval == strlen (result));
1636   }
1637 
1638   { /* FLAG_ZERO with finite number.  */
1639     int retval =
1640       my_snprintf (result, sizeof (result), "%015e %d", 1234.0, 33, 44, 55);
1641     ASSERT (strcmp (result, "0001.234000e+03 33") == 0
1642             || strcmp (result, "001.234000e+003 33") == 0);
1643     ASSERT (retval == strlen (result));
1644   }
1645 
1646   { /* FLAG_ZERO with infinite number.  */
1647     int retval =
1648       my_snprintf (result, sizeof (result), "%015e %d", - Infinityd (), 33, 44, 55);
1649     ASSERT (strcmp (result, "           -inf 33") == 0
1650             || strcmp (result, "      -infinity 33") == 0);
1651     ASSERT (retval == strlen (result));
1652   }
1653 
1654   { /* FLAG_ZERO with NaN.  */
1655     int retval =
1656       my_snprintf (result, sizeof (result), "%050e %d", NaNd (), 33, 44, 55);
1657     ASSERT (strlen (result) == 50 + 3
1658             && strisnan (result, strspn (result, " "), strlen (result) - 3, 0)
1659             && strcmp (result + strlen (result) - 3, " 33") == 0);
1660     ASSERT (retval == strlen (result));
1661   }
1662 
1663   { /* Precision.  */
1664     int retval =
1665       my_snprintf (result, sizeof (result), "%.e %d", 1234.0, 33, 44, 55);
1666     ASSERT (strcmp (result, "1e+03 33") == 0
1667             || strcmp (result, "1e+003 33") == 0);
1668     ASSERT (retval == strlen (result));
1669   }
1670 
1671   { /* Precision with no rounding.  */
1672     int retval =
1673       my_snprintf (result, sizeof (result), "%.4e %d", 999.951, 33, 44, 55);
1674     ASSERT (strcmp (result, "9.9995e+02 33") == 0
1675             || strcmp (result, "9.9995e+002 33") == 0);
1676     ASSERT (retval == strlen (result));
1677   }
1678 
1679   { /* Precision with rounding.  */
1680     int retval =
1681       my_snprintf (result, sizeof (result), "%.4e %d", 999.996, 33, 44, 55);
1682     ASSERT (strcmp (result, "1.0000e+03 33") == 0
1683             || strcmp (result, "1.0000e+003 33") == 0);
1684     ASSERT (retval == strlen (result));
1685   }
1686 
1687   { /* A positive number.  */
1688     int retval =
1689       my_snprintf (result, sizeof (result), "%Le %d", 12.75L, 33, 44, 55);
1690     ASSERT (strcmp (result, "1.275000e+01 33") == 0
1691             || strcmp (result, "1.275000e+001 33") == 0);
1692     ASSERT (retval == strlen (result));
1693   }
1694 
1695   { /* A larger positive number.  */
1696     int retval =
1697       my_snprintf (result, sizeof (result), "%Le %d", 1234567.0L, 33, 44, 55);
1698     ASSERT (strcmp (result, "1.234567e+06 33") == 0
1699             || strcmp (result, "1.234567e+006 33") == 0);
1700     ASSERT (retval == strlen (result));
1701   }
1702 
1703   { /* Small and large positive numbers.  */
1704     static struct { long double value; const char *string; } data[] =
1705       {
1706         { 1.234321234321234e-37L, "1.234321e-37" },
1707         { 1.234321234321234e-36L, "1.234321e-36" },
1708         { 1.234321234321234e-35L, "1.234321e-35" },
1709         { 1.234321234321234e-34L, "1.234321e-34" },
1710         { 1.234321234321234e-33L, "1.234321e-33" },
1711         { 1.234321234321234e-32L, "1.234321e-32" },
1712         { 1.234321234321234e-31L, "1.234321e-31" },
1713         { 1.234321234321234e-30L, "1.234321e-30" },
1714         { 1.234321234321234e-29L, "1.234321e-29" },
1715         { 1.234321234321234e-28L, "1.234321e-28" },
1716         { 1.234321234321234e-27L, "1.234321e-27" },
1717         { 1.234321234321234e-26L, "1.234321e-26" },
1718         { 1.234321234321234e-25L, "1.234321e-25" },
1719         { 1.234321234321234e-24L, "1.234321e-24" },
1720         { 1.234321234321234e-23L, "1.234321e-23" },
1721         { 1.234321234321234e-22L, "1.234321e-22" },
1722         { 1.234321234321234e-21L, "1.234321e-21" },
1723         { 1.234321234321234e-20L, "1.234321e-20" },
1724         { 1.234321234321234e-19L, "1.234321e-19" },
1725         { 1.234321234321234e-18L, "1.234321e-18" },
1726         { 1.234321234321234e-17L, "1.234321e-17" },
1727         { 1.234321234321234e-16L, "1.234321e-16" },
1728         { 1.234321234321234e-15L, "1.234321e-15" },
1729         { 1.234321234321234e-14L, "1.234321e-14" },
1730         { 1.234321234321234e-13L, "1.234321e-13" },
1731         { 1.234321234321234e-12L, "1.234321e-12" },
1732         { 1.234321234321234e-11L, "1.234321e-11" },
1733         { 1.234321234321234e-10L, "1.234321e-10" },
1734         { 1.234321234321234e-9L, "1.234321e-09" },
1735         { 1.234321234321234e-8L, "1.234321e-08" },
1736         { 1.234321234321234e-7L, "1.234321e-07" },
1737         { 1.234321234321234e-6L, "1.234321e-06" },
1738         { 1.234321234321234e-5L, "1.234321e-05" },
1739         { 1.234321234321234e-4L, "1.234321e-04" },
1740         { 1.234321234321234e-3L, "1.234321e-03" },
1741         { 1.234321234321234e-2L, "1.234321e-02" },
1742         { 1.234321234321234e-1L, "1.234321e-01" },
1743         { 1.234321234321234L, "1.234321e+00" },
1744         { 1.234321234321234e1L, "1.234321e+01" },
1745         { 1.234321234321234e2L, "1.234321e+02" },
1746         { 1.234321234321234e3L, "1.234321e+03" },
1747         { 1.234321234321234e4L, "1.234321e+04" },
1748         { 1.234321234321234e5L, "1.234321e+05" },
1749         { 1.234321234321234e6L, "1.234321e+06" },
1750         { 1.234321234321234e7L, "1.234321e+07" },
1751         { 1.234321234321234e8L, "1.234321e+08" },
1752         { 1.234321234321234e9L, "1.234321e+09" },
1753         { 1.234321234321234e10L, "1.234321e+10" },
1754         { 1.234321234321234e11L, "1.234321e+11" },
1755         { 1.234321234321234e12L, "1.234321e+12" },
1756         { 1.234321234321234e13L, "1.234321e+13" },
1757         { 1.234321234321234e14L, "1.234321e+14" },
1758         { 1.234321234321234e15L, "1.234321e+15" },
1759         { 1.234321234321234e16L, "1.234321e+16" },
1760         { 1.234321234321234e17L, "1.234321e+17" },
1761         { 1.234321234321234e18L, "1.234321e+18" },
1762         { 1.234321234321234e19L, "1.234321e+19" },
1763         { 1.234321234321234e20L, "1.234321e+20" },
1764         { 1.234321234321234e21L, "1.234321e+21" },
1765         { 1.234321234321234e22L, "1.234321e+22" },
1766         { 1.234321234321234e23L, "1.234321e+23" },
1767         { 1.234321234321234e24L, "1.234321e+24" },
1768         { 1.234321234321234e25L, "1.234321e+25" },
1769         { 1.234321234321234e26L, "1.234321e+26" },
1770         { 1.234321234321234e27L, "1.234321e+27" },
1771         { 1.234321234321234e28L, "1.234321e+28" },
1772         { 1.234321234321234e29L, "1.234321e+29" },
1773         { 1.234321234321234e30L, "1.234321e+30" },
1774         { 1.234321234321234e31L, "1.234321e+31" },
1775         { 1.234321234321234e32L, "1.234321e+32" },
1776         { 1.234321234321234e33L, "1.234321e+33" },
1777         { 1.234321234321234e34L, "1.234321e+34" },
1778         { 1.234321234321234e35L, "1.234321e+35" },
1779         { 1.234321234321234e36L, "1.234321e+36" }
1780       };
1781     size_t k;
1782     for (k = 0; k < SIZEOF (data); k++)
1783       {
1784         int retval =
1785           my_snprintf (result, sizeof (result), "%Le", data[k].value);
1786         const char *expected = data[k].string;
1787         ASSERT (strcmp (result, expected) == 0
1788                 /* Some implementations produce exponents with 3 digits.  */
1789                 || (strlen (result) == strlen (expected) + 1
1790                     && memcmp (result, expected, strlen (expected) - 2) == 0
1791                     && result[strlen (expected) - 2] == '0'
1792                     && strcmp (result + strlen (expected) - 1,
1793                                expected + strlen (expected) - 2)
1794                        == 0));
1795         ASSERT (retval == strlen (result));
1796       }
1797   }
1798 
1799   { /* A negative number.  */
1800     int retval =
1801       my_snprintf (result, sizeof (result), "%Le %d", -0.03125L, 33, 44, 55);
1802     ASSERT (strcmp (result, "-3.125000e-02 33") == 0
1803             || strcmp (result, "-3.125000e-002 33") == 0);
1804     ASSERT (retval == strlen (result));
1805   }
1806 
1807   { /* Positive zero.  */
1808     int retval =
1809       my_snprintf (result, sizeof (result), "%Le %d", 0.0L, 33, 44, 55);
1810     ASSERT (strcmp (result, "0.000000e+00 33") == 0
1811             || strcmp (result, "0.000000e+000 33") == 0);
1812     ASSERT (retval == strlen (result));
1813   }
1814 
1815   { /* Negative zero.  */
1816     int retval =
1817       my_snprintf (result, sizeof (result), "%Le %d", minus_zerol, 33, 44, 55);
1818     if (have_minus_zero ())
1819       ASSERT (strcmp (result, "-0.000000e+00 33") == 0
1820               || strcmp (result, "-0.000000e+000 33") == 0);
1821     ASSERT (retval == strlen (result));
1822   }
1823 
1824   { /* Positive infinity.  */
1825     int retval =
1826       my_snprintf (result, sizeof (result), "%Le %d", Infinityl (), 33, 44, 55);
1827     ASSERT (strcmp (result, "inf 33") == 0
1828             || strcmp (result, "infinity 33") == 0);
1829     ASSERT (retval == strlen (result));
1830   }
1831 
1832   { /* Negative infinity.  */
1833     int retval =
1834       my_snprintf (result, sizeof (result), "%Le %d", - Infinityl (), 33, 44, 55);
1835     ASSERT (strcmp (result, "-inf 33") == 0
1836             || strcmp (result, "-infinity 33") == 0);
1837     ASSERT (retval == strlen (result));
1838   }
1839 
1840   { /* NaN.  */
1841     int retval =
1842       my_snprintf (result, sizeof (result), "%Le %d", NaNl (), 33, 44, 55);
1843     ASSERT (strlen (result) >= 3 + 3
1844             && strisnan (result, 0, strlen (result) - 3, 0)
1845             && strcmp (result + strlen (result) - 3, " 33") == 0);
1846     ASSERT (retval == strlen (result));
1847   }
1848 #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
1849   { /* Quiet NaN.  */
1850     static union { unsigned int word[4]; long double value; } x =
1851       { LDBL80_WORDS (0xFFFF, 0xC3333333, 0x00000000) };
1852     int retval =
1853       my_snprintf (result, sizeof (result), "%Le %d", x.value, 33, 44, 55);
1854     ASSERT (strlen (result) >= 3 + 3
1855             && strisnan (result, 0, strlen (result) - 3, 0)
1856             && strcmp (result + strlen (result) - 3, " 33") == 0);
1857     ASSERT (retval == strlen (result));
1858   }
1859   {
1860     /* Signalling NaN.  */
1861     static union { unsigned int word[4]; long double value; } x =
1862       { LDBL80_WORDS (0xFFFF, 0x83333333, 0x00000000) };
1863     int retval =
1864       my_snprintf (result, sizeof (result), "%Le %d", x.value, 33, 44, 55);
1865     ASSERT (strlen (result) >= 3 + 3
1866             && strisnan (result, 0, strlen (result) - 3, 0)
1867             && strcmp (result + strlen (result) - 3, " 33") == 0);
1868     ASSERT (retval == strlen (result));
1869   }
1870   /* snprintf should print something for noncanonical values.  */
1871   { /* Pseudo-NaN.  */
1872     static union { unsigned int word[4]; long double value; } x =
1873       { LDBL80_WORDS (0xFFFF, 0x40000001, 0x00000000) };
1874     int retval =
1875       my_snprintf (result, sizeof (result), "%Le %d", x.value, 33, 44, 55);
1876     ASSERT (retval == strlen (result));
1877     ASSERT (3 < retval && strcmp (result + retval - 3, " 33") == 0);
1878   }
1879   { /* Pseudo-Infinity.  */
1880     static union { unsigned int word[4]; long double value; } x =
1881       { LDBL80_WORDS (0xFFFF, 0x00000000, 0x00000000) };
1882     int retval =
1883       my_snprintf (result, sizeof (result), "%Le %d", x.value, 33, 44, 55);
1884     ASSERT (retval == strlen (result));
1885     ASSERT (3 < retval && strcmp (result + retval - 3, " 33") == 0);
1886   }
1887   { /* Pseudo-Zero.  */
1888     static union { unsigned int word[4]; long double value; } x =
1889       { LDBL80_WORDS (0x4004, 0x00000000, 0x00000000) };
1890     int retval =
1891       my_snprintf (result, sizeof (result), "%Le %d", x.value, 33, 44, 55);
1892     ASSERT (retval == strlen (result));
1893     ASSERT (3 < retval && strcmp (result + retval - 3, " 33") == 0);
1894   }
1895   { /* Unnormalized number.  */
1896     static union { unsigned int word[4]; long double value; } x =
1897       { LDBL80_WORDS (0x4000, 0x63333333, 0x00000000) };
1898     int retval =
1899       my_snprintf (result, sizeof (result), "%Le %d", x.value, 33, 44, 55);
1900     ASSERT (retval == strlen (result));
1901     ASSERT (3 < retval && strcmp (result + retval - 3, " 33") == 0);
1902   }
1903   { /* Pseudo-Denormal.  */
1904     static union { unsigned int word[4]; long double value; } x =
1905       { LDBL80_WORDS (0x0000, 0x83333333, 0x00000000) };
1906     int retval =
1907       my_snprintf (result, sizeof (result), "%Le %d", x.value, 33, 44, 55);
1908     ASSERT (retval == strlen (result));
1909     ASSERT (3 < retval && strcmp (result + retval - 3, " 33") == 0);
1910   }
1911 #endif
1912 
1913   { /* Width.  */
1914     int retval =
1915       my_snprintf (result, sizeof (result), "%15Le %d", 1.75L, 33, 44, 55);
1916     ASSERT (strcmp (result, "   1.750000e+00 33") == 0
1917             || strcmp (result, "  1.750000e+000 33") == 0);
1918     ASSERT (retval == strlen (result));
1919   }
1920 
1921   { /* FLAG_LEFT.  */
1922     int retval =
1923       my_snprintf (result, sizeof (result), "%-15Le %d", 1.75L, 33, 44, 55);
1924     ASSERT (strcmp (result, "1.750000e+00    33") == 0
1925             || strcmp (result, "1.750000e+000   33") == 0);
1926     ASSERT (retval == strlen (result));
1927   }
1928 
1929   { /* FLAG_SHOWSIGN.  */
1930     int retval =
1931       my_snprintf (result, sizeof (result), "%+Le %d", 1.75L, 33, 44, 55);
1932     ASSERT (strcmp (result, "+1.750000e+00 33") == 0
1933             || strcmp (result, "+1.750000e+000 33") == 0);
1934     ASSERT (retval == strlen (result));
1935   }
1936 
1937   { /* FLAG_SPACE.  */
1938     int retval =
1939       my_snprintf (result, sizeof (result), "% Le %d", 1.75L, 33, 44, 55);
1940     ASSERT (strcmp (result, " 1.750000e+00 33") == 0
1941             || strcmp (result, " 1.750000e+000 33") == 0);
1942     ASSERT (retval == strlen (result));
1943   }
1944 
1945   { /* FLAG_ALT.  */
1946     int retval =
1947       my_snprintf (result, sizeof (result), "%#Le %d", 1.75L, 33, 44, 55);
1948     ASSERT (strcmp (result, "1.750000e+00 33") == 0
1949             || strcmp (result, "1.750000e+000 33") == 0);
1950     ASSERT (retval == strlen (result));
1951   }
1952 
1953   { /* FLAG_ALT.  */
1954     int retval =
1955       my_snprintf (result, sizeof (result), "%#.Le %d", 1.75L, 33, 44, 55);
1956     ASSERT (strcmp (result, "2.e+00 33") == 0
1957             || strcmp (result, "2.e+000 33") == 0);
1958     ASSERT (retval == strlen (result));
1959   }
1960 
1961   { /* FLAG_ALT.  */
1962     int retval =
1963       my_snprintf (result, sizeof (result), "%#.Le %d", 9.75L, 33, 44, 55);
1964     ASSERT (strcmp (result, "1.e+01 33") == 0
1965             || strcmp (result, "1.e+001 33") == 0);
1966     ASSERT (retval == strlen (result));
1967   }
1968 
1969   { /* FLAG_ZERO with finite number.  */
1970     int retval =
1971       my_snprintf (result, sizeof (result), "%015Le %d", 1234.0L, 33, 44, 55);
1972     ASSERT (strcmp (result, "0001.234000e+03 33") == 0
1973             || strcmp (result, "001.234000e+003 33") == 0);
1974     ASSERT (retval == strlen (result));
1975   }
1976 
1977   { /* FLAG_ZERO with infinite number.  */
1978     int retval =
1979       my_snprintf (result, sizeof (result), "%015Le %d", - Infinityl (), 33, 44, 55);
1980     ASSERT (strcmp (result, "           -inf 33") == 0
1981             || strcmp (result, "      -infinity 33") == 0);
1982     ASSERT (retval == strlen (result));
1983   }
1984 
1985   { /* FLAG_ZERO with NaN.  */
1986     int retval =
1987       my_snprintf (result, sizeof (result), "%050Le %d", NaNl (), 33, 44, 55);
1988     ASSERT (strlen (result) == 50 + 3
1989             && strisnan (result, strspn (result, " "), strlen (result) - 3, 0)
1990             && strcmp (result + strlen (result) - 3, " 33") == 0);
1991     ASSERT (retval == strlen (result));
1992   }
1993 
1994   { /* Precision.  */
1995     int retval =
1996       my_snprintf (result, sizeof (result), "%.Le %d", 1234.0L, 33, 44, 55);
1997     ASSERT (strcmp (result, "1e+03 33") == 0
1998             || strcmp (result, "1e+003 33") == 0);
1999     ASSERT (retval == strlen (result));
2000   }
2001 
2002   { /* Precision with no rounding.  */
2003     int retval =
2004       my_snprintf (result, sizeof (result), "%.4Le %d", 999.951L, 33, 44, 55);
2005     ASSERT (strcmp (result, "9.9995e+02 33") == 0
2006             || strcmp (result, "9.9995e+002 33") == 0);
2007     ASSERT (retval == strlen (result));
2008   }
2009 
2010   { /* Precision with rounding.  */
2011     int retval =
2012       my_snprintf (result, sizeof (result), "%.4Le %d", 999.996L, 33, 44, 55);
2013     ASSERT (strcmp (result, "1.0000e+03 33") == 0
2014             || strcmp (result, "1.0000e+003 33") == 0);
2015     ASSERT (retval == strlen (result));
2016   }
2017 
2018   /* Test the support of the %g format directive.  */
2019 
2020   { /* A positive number.  */
2021     int retval =
2022       my_snprintf (result, sizeof (result), "%g %d", 12.75, 33, 44, 55);
2023     ASSERT (strcmp (result, "12.75 33") == 0);
2024     ASSERT (retval == strlen (result));
2025   }
2026 
2027   { /* A larger positive number.  */
2028     int retval =
2029       my_snprintf (result, sizeof (result), "%g %d", 1234567.0, 33, 44, 55);
2030     ASSERT (strcmp (result, "1.23457e+06 33") == 0
2031             || strcmp (result, "1.23457e+006 33") == 0);
2032     ASSERT (retval == strlen (result));
2033   }
2034 
2035   { /* Small and large positive numbers.  */
2036     static struct { double value; const char *string; } data[] =
2037       {
2038         { 1.234321234321234e-37, "1.23432e-37" },
2039         { 1.234321234321234e-36, "1.23432e-36" },
2040         { 1.234321234321234e-35, "1.23432e-35" },
2041         { 1.234321234321234e-34, "1.23432e-34" },
2042         { 1.234321234321234e-33, "1.23432e-33" },
2043         { 1.234321234321234e-32, "1.23432e-32" },
2044         { 1.234321234321234e-31, "1.23432e-31" },
2045         { 1.234321234321234e-30, "1.23432e-30" },
2046         { 1.234321234321234e-29, "1.23432e-29" },
2047         { 1.234321234321234e-28, "1.23432e-28" },
2048         { 1.234321234321234e-27, "1.23432e-27" },
2049         { 1.234321234321234e-26, "1.23432e-26" },
2050         { 1.234321234321234e-25, "1.23432e-25" },
2051         { 1.234321234321234e-24, "1.23432e-24" },
2052         { 1.234321234321234e-23, "1.23432e-23" },
2053         { 1.234321234321234e-22, "1.23432e-22" },
2054         { 1.234321234321234e-21, "1.23432e-21" },
2055         { 1.234321234321234e-20, "1.23432e-20" },
2056         { 1.234321234321234e-19, "1.23432e-19" },
2057         { 1.234321234321234e-18, "1.23432e-18" },
2058         { 1.234321234321234e-17, "1.23432e-17" },
2059         { 1.234321234321234e-16, "1.23432e-16" },
2060         { 1.234321234321234e-15, "1.23432e-15" },
2061         { 1.234321234321234e-14, "1.23432e-14" },
2062         { 1.234321234321234e-13, "1.23432e-13" },
2063         { 1.234321234321234e-12, "1.23432e-12" },
2064         { 1.234321234321234e-11, "1.23432e-11" },
2065         { 1.234321234321234e-10, "1.23432e-10" },
2066         { 1.234321234321234e-9, "1.23432e-09" },
2067         { 1.234321234321234e-8, "1.23432e-08" },
2068         { 1.234321234321234e-7, "1.23432e-07" },
2069         { 1.234321234321234e-6, "1.23432e-06" },
2070         { 1.234321234321234e-5, "1.23432e-05" },
2071         { 1.234321234321234e-4, "0.000123432" },
2072         { 1.234321234321234e-3, "0.00123432" },
2073         { 1.234321234321234e-2, "0.0123432" },
2074         { 1.234321234321234e-1, "0.123432" },
2075         { 1.234321234321234, "1.23432" },
2076         { 1.234321234321234e1, "12.3432" },
2077         { 1.234321234321234e2, "123.432" },
2078         { 1.234321234321234e3, "1234.32" },
2079         { 1.234321234321234e4, "12343.2" },
2080         { 1.234321234321234e5, "123432" },
2081         { 1.234321234321234e6, "1.23432e+06" },
2082         { 1.234321234321234e7, "1.23432e+07" },
2083         { 1.234321234321234e8, "1.23432e+08" },
2084         { 1.234321234321234e9, "1.23432e+09" },
2085         { 1.234321234321234e10, "1.23432e+10" },
2086         { 1.234321234321234e11, "1.23432e+11" },
2087         { 1.234321234321234e12, "1.23432e+12" },
2088         { 1.234321234321234e13, "1.23432e+13" },
2089         { 1.234321234321234e14, "1.23432e+14" },
2090         { 1.234321234321234e15, "1.23432e+15" },
2091         { 1.234321234321234e16, "1.23432e+16" },
2092         { 1.234321234321234e17, "1.23432e+17" },
2093         { 1.234321234321234e18, "1.23432e+18" },
2094         { 1.234321234321234e19, "1.23432e+19" },
2095         { 1.234321234321234e20, "1.23432e+20" },
2096         { 1.234321234321234e21, "1.23432e+21" },
2097         { 1.234321234321234e22, "1.23432e+22" },
2098         { 1.234321234321234e23, "1.23432e+23" },
2099         { 1.234321234321234e24, "1.23432e+24" },
2100         { 1.234321234321234e25, "1.23432e+25" },
2101         { 1.234321234321234e26, "1.23432e+26" },
2102         { 1.234321234321234e27, "1.23432e+27" },
2103         { 1.234321234321234e28, "1.23432e+28" },
2104         { 1.234321234321234e29, "1.23432e+29" },
2105         { 1.234321234321234e30, "1.23432e+30" },
2106         { 1.234321234321234e31, "1.23432e+31" },
2107         { 1.234321234321234e32, "1.23432e+32" },
2108         { 1.234321234321234e33, "1.23432e+33" },
2109         { 1.234321234321234e34, "1.23432e+34" },
2110         { 1.234321234321234e35, "1.23432e+35" },
2111         { 1.234321234321234e36, "1.23432e+36" }
2112       };
2113     size_t k;
2114     for (k = 0; k < SIZEOF (data); k++)
2115       {
2116         int retval =
2117           my_snprintf (result, sizeof (result), "%g", data[k].value);
2118         const char *expected = data[k].string;
2119         ASSERT (strcmp (result, expected) == 0
2120                 /* Some implementations produce exponents with 3 digits.  */
2121                 || (expected[strlen (expected) - 4] == 'e'
2122                     && strlen (result) == strlen (expected) + 1
2123                     && memcmp (result, expected, strlen (expected) - 2) == 0
2124                     && result[strlen (expected) - 2] == '0'
2125                     && strcmp (result + strlen (expected) - 1,
2126                                expected + strlen (expected) - 2)
2127                        == 0));
2128         ASSERT (retval == strlen (result));
2129       }
2130   }
2131 
2132   { /* A negative number.  */
2133     int retval =
2134       my_snprintf (result, sizeof (result), "%g %d", -0.03125, 33, 44, 55);
2135     ASSERT (strcmp (result, "-0.03125 33") == 0);
2136     ASSERT (retval == strlen (result));
2137   }
2138 
2139   { /* Positive zero.  */
2140     int retval =
2141       my_snprintf (result, sizeof (result), "%g %d", 0.0, 33, 44, 55);
2142     ASSERT (strcmp (result, "0 33") == 0);
2143     ASSERT (retval == strlen (result));
2144   }
2145 
2146   { /* Negative zero.  */
2147     int retval =
2148       my_snprintf (result, sizeof (result), "%g %d", minus_zerod, 33, 44, 55);
2149     if (have_minus_zero ())
2150       ASSERT (strcmp (result, "-0 33") == 0);
2151     ASSERT (retval == strlen (result));
2152   }
2153 
2154   { /* Positive infinity.  */
2155     int retval =
2156       my_snprintf (result, sizeof (result), "%g %d", Infinityd (), 33, 44, 55);
2157     ASSERT (strcmp (result, "inf 33") == 0
2158             || strcmp (result, "infinity 33") == 0);
2159     ASSERT (retval == strlen (result));
2160   }
2161 
2162   { /* Negative infinity.  */
2163     int retval =
2164       my_snprintf (result, sizeof (result), "%g %d", - Infinityd (), 33, 44, 55);
2165     ASSERT (strcmp (result, "-inf 33") == 0
2166             || strcmp (result, "-infinity 33") == 0);
2167     ASSERT (retval == strlen (result));
2168   }
2169 
2170   { /* NaN.  */
2171     int retval =
2172       my_snprintf (result, sizeof (result), "%g %d", NaNd (), 33, 44, 55);
2173     ASSERT (strlen (result) >= 3 + 3
2174             && strisnan (result, 0, strlen (result) - 3, 0)
2175             && strcmp (result + strlen (result) - 3, " 33") == 0);
2176     ASSERT (retval == strlen (result));
2177   }
2178 
2179   { /* Width.  */
2180     int retval =
2181       my_snprintf (result, sizeof (result), "%10g %d", 1.75, 33, 44, 55);
2182     ASSERT (strcmp (result, "      1.75 33") == 0);
2183     ASSERT (retval == strlen (result));
2184   }
2185 
2186   { /* FLAG_LEFT.  */
2187     int retval =
2188       my_snprintf (result, sizeof (result), "%-10g %d", 1.75, 33, 44, 55);
2189     ASSERT (strcmp (result, "1.75       33") == 0);
2190     ASSERT (retval == strlen (result));
2191   }
2192 
2193   { /* FLAG_SHOWSIGN.  */
2194     int retval =
2195       my_snprintf (result, sizeof (result), "%+g %d", 1.75, 33, 44, 55);
2196     ASSERT (strcmp (result, "+1.75 33") == 0);
2197     ASSERT (retval == strlen (result));
2198   }
2199 
2200   { /* FLAG_SPACE.  */
2201     int retval =
2202       my_snprintf (result, sizeof (result), "% g %d", 1.75, 33, 44, 55);
2203     ASSERT (strcmp (result, " 1.75 33") == 0);
2204     ASSERT (retval == strlen (result));
2205   }
2206 
2207   { /* FLAG_ALT.  */
2208     int retval =
2209       my_snprintf (result, sizeof (result), "%#g %d", 1.75, 33, 44, 55);
2210     ASSERT (strcmp (result, "1.75000 33") == 0);
2211     ASSERT (retval == strlen (result));
2212   }
2213 
2214   { /* FLAG_ALT.  */
2215     int retval =
2216       my_snprintf (result, sizeof (result), "%#.g %d", 1.75, 33, 44, 55);
2217     ASSERT (strcmp (result, "2. 33") == 0);
2218     ASSERT (retval == strlen (result));
2219   }
2220 
2221   { /* FLAG_ALT.  */
2222     int retval =
2223       my_snprintf (result, sizeof (result), "%#.g %d", 9.75, 33, 44, 55);
2224     ASSERT (strcmp (result, "1.e+01 33") == 0
2225             || strcmp (result, "1.e+001 33") == 0);
2226     ASSERT (retval == strlen (result));
2227   }
2228 
2229   { /* FLAG_ZERO with finite number.  */
2230     int retval =
2231       my_snprintf (result, sizeof (result), "%010g %d", 1234.0, 33, 44, 55);
2232     ASSERT (strcmp (result, "0000001234 33") == 0);
2233     ASSERT (retval == strlen (result));
2234   }
2235 
2236   { /* FLAG_ZERO with infinite number.  */
2237     int retval =
2238       my_snprintf (result, sizeof (result), "%015g %d", - Infinityd (), 33, 44, 55);
2239     ASSERT (strcmp (result, "           -inf 33") == 0
2240             || strcmp (result, "      -infinity 33") == 0);
2241     ASSERT (retval == strlen (result));
2242   }
2243 
2244   { /* FLAG_ZERO with NaN.  */
2245     int retval =
2246       my_snprintf (result, sizeof (result), "%050g %d", NaNd (), 33, 44, 55);
2247     ASSERT (strlen (result) == 50 + 3
2248             && strisnan (result, strspn (result, " "), strlen (result) - 3, 0)
2249             && strcmp (result + strlen (result) - 3, " 33") == 0);
2250     ASSERT (retval == strlen (result));
2251   }
2252 
2253   { /* Precision.  */
2254     int retval =
2255       my_snprintf (result, sizeof (result), "%.g %d", 1234.0, 33, 44, 55);
2256     ASSERT (strcmp (result, "1e+03 33") == 0
2257             || strcmp (result, "1e+003 33") == 0);
2258     ASSERT (retval == strlen (result));
2259   }
2260 
2261   { /* Precision with no rounding.  */
2262     int retval =
2263       my_snprintf (result, sizeof (result), "%.5g %d", 999.951, 33, 44, 55);
2264     ASSERT (strcmp (result, "999.95 33") == 0);
2265     ASSERT (retval == strlen (result));
2266   }
2267 
2268   { /* Precision with rounding.  */
2269     int retval =
2270       my_snprintf (result, sizeof (result), "%.5g %d", 999.996, 33, 44, 55);
2271     ASSERT (strcmp (result, "1000 33") == 0);
2272     ASSERT (retval == strlen (result));
2273   }
2274 
2275   { /* A positive number.  */
2276     int retval =
2277       my_snprintf (result, sizeof (result), "%Lg %d", 12.75L, 33, 44, 55);
2278     ASSERT (strcmp (result, "12.75 33") == 0);
2279     ASSERT (retval == strlen (result));
2280   }
2281 
2282   { /* A larger positive number.  */
2283     int retval =
2284       my_snprintf (result, sizeof (result), "%Lg %d", 1234567.0L, 33, 44, 55);
2285     ASSERT (strcmp (result, "1.23457e+06 33") == 0
2286             || strcmp (result, "1.23457e+006 33") == 0);
2287     ASSERT (retval == strlen (result));
2288   }
2289 
2290   { /* Small and large positive numbers.  */
2291     static struct { long double value; const char *string; } data[] =
2292       {
2293         { 1.234321234321234e-37L, "1.23432e-37" },
2294         { 1.234321234321234e-36L, "1.23432e-36" },
2295         { 1.234321234321234e-35L, "1.23432e-35" },
2296         { 1.234321234321234e-34L, "1.23432e-34" },
2297         { 1.234321234321234e-33L, "1.23432e-33" },
2298         { 1.234321234321234e-32L, "1.23432e-32" },
2299         { 1.234321234321234e-31L, "1.23432e-31" },
2300         { 1.234321234321234e-30L, "1.23432e-30" },
2301         { 1.234321234321234e-29L, "1.23432e-29" },
2302         { 1.234321234321234e-28L, "1.23432e-28" },
2303         { 1.234321234321234e-27L, "1.23432e-27" },
2304         { 1.234321234321234e-26L, "1.23432e-26" },
2305         { 1.234321234321234e-25L, "1.23432e-25" },
2306         { 1.234321234321234e-24L, "1.23432e-24" },
2307         { 1.234321234321234e-23L, "1.23432e-23" },
2308         { 1.234321234321234e-22L, "1.23432e-22" },
2309         { 1.234321234321234e-21L, "1.23432e-21" },
2310         { 1.234321234321234e-20L, "1.23432e-20" },
2311         { 1.234321234321234e-19L, "1.23432e-19" },
2312         { 1.234321234321234e-18L, "1.23432e-18" },
2313         { 1.234321234321234e-17L, "1.23432e-17" },
2314         { 1.234321234321234e-16L, "1.23432e-16" },
2315         { 1.234321234321234e-15L, "1.23432e-15" },
2316         { 1.234321234321234e-14L, "1.23432e-14" },
2317         { 1.234321234321234e-13L, "1.23432e-13" },
2318         { 1.234321234321234e-12L, "1.23432e-12" },
2319         { 1.234321234321234e-11L, "1.23432e-11" },
2320         { 1.234321234321234e-10L, "1.23432e-10" },
2321         { 1.234321234321234e-9L, "1.23432e-09" },
2322         { 1.234321234321234e-8L, "1.23432e-08" },
2323         { 1.234321234321234e-7L, "1.23432e-07" },
2324         { 1.234321234321234e-6L, "1.23432e-06" },
2325         { 1.234321234321234e-5L, "1.23432e-05" },
2326         { 1.234321234321234e-4L, "0.000123432" },
2327         { 1.234321234321234e-3L, "0.00123432" },
2328         { 1.234321234321234e-2L, "0.0123432" },
2329         { 1.234321234321234e-1L, "0.123432" },
2330         { 1.234321234321234L, "1.23432" },
2331         { 1.234321234321234e1L, "12.3432" },
2332         { 1.234321234321234e2L, "123.432" },
2333         { 1.234321234321234e3L, "1234.32" },
2334         { 1.234321234321234e4L, "12343.2" },
2335         { 1.234321234321234e5L, "123432" },
2336         { 1.234321234321234e6L, "1.23432e+06" },
2337         { 1.234321234321234e7L, "1.23432e+07" },
2338         { 1.234321234321234e8L, "1.23432e+08" },
2339         { 1.234321234321234e9L, "1.23432e+09" },
2340         { 1.234321234321234e10L, "1.23432e+10" },
2341         { 1.234321234321234e11L, "1.23432e+11" },
2342         { 1.234321234321234e12L, "1.23432e+12" },
2343         { 1.234321234321234e13L, "1.23432e+13" },
2344         { 1.234321234321234e14L, "1.23432e+14" },
2345         { 1.234321234321234e15L, "1.23432e+15" },
2346         { 1.234321234321234e16L, "1.23432e+16" },
2347         { 1.234321234321234e17L, "1.23432e+17" },
2348         { 1.234321234321234e18L, "1.23432e+18" },
2349         { 1.234321234321234e19L, "1.23432e+19" },
2350         { 1.234321234321234e20L, "1.23432e+20" },
2351         { 1.234321234321234e21L, "1.23432e+21" },
2352         { 1.234321234321234e22L, "1.23432e+22" },
2353         { 1.234321234321234e23L, "1.23432e+23" },
2354         { 1.234321234321234e24L, "1.23432e+24" },
2355         { 1.234321234321234e25L, "1.23432e+25" },
2356         { 1.234321234321234e26L, "1.23432e+26" },
2357         { 1.234321234321234e27L, "1.23432e+27" },
2358         { 1.234321234321234e28L, "1.23432e+28" },
2359         { 1.234321234321234e29L, "1.23432e+29" },
2360         { 1.234321234321234e30L, "1.23432e+30" },
2361         { 1.234321234321234e31L, "1.23432e+31" },
2362         { 1.234321234321234e32L, "1.23432e+32" },
2363         { 1.234321234321234e33L, "1.23432e+33" },
2364         { 1.234321234321234e34L, "1.23432e+34" },
2365         { 1.234321234321234e35L, "1.23432e+35" },
2366         { 1.234321234321234e36L, "1.23432e+36" }
2367       };
2368     size_t k;
2369     for (k = 0; k < SIZEOF (data); k++)
2370       {
2371         int retval =
2372           my_snprintf (result, sizeof (result), "%Lg", data[k].value);
2373         const char *expected = data[k].string;
2374         ASSERT (strcmp (result, expected) == 0
2375                 /* Some implementations produce exponents with 3 digits.  */
2376                 || (expected[strlen (expected) - 4] == 'e'
2377                     && strlen (result) == strlen (expected) + 1
2378                     && memcmp (result, expected, strlen (expected) - 2) == 0
2379                     && result[strlen (expected) - 2] == '0'
2380                     && strcmp (result + strlen (expected) - 1,
2381                                expected + strlen (expected) - 2)
2382                        == 0));
2383         ASSERT (retval == strlen (result));
2384       }
2385   }
2386 
2387   { /* A negative number.  */
2388     int retval =
2389       my_snprintf (result, sizeof (result), "%Lg %d", -0.03125L, 33, 44, 55);
2390     ASSERT (strcmp (result, "-0.03125 33") == 0);
2391     ASSERT (retval == strlen (result));
2392   }
2393 
2394   { /* Positive zero.  */
2395     int retval =
2396       my_snprintf (result, sizeof (result), "%Lg %d", 0.0L, 33, 44, 55);
2397     ASSERT (strcmp (result, "0 33") == 0);
2398     ASSERT (retval == strlen (result));
2399   }
2400 
2401   { /* Negative zero.  */
2402     int retval =
2403       my_snprintf (result, sizeof (result), "%Lg %d", minus_zerol, 33, 44, 55);
2404     if (have_minus_zero ())
2405       ASSERT (strcmp (result, "-0 33") == 0);
2406     ASSERT (retval == strlen (result));
2407   }
2408 
2409   { /* Positive infinity.  */
2410     int retval =
2411       my_snprintf (result, sizeof (result), "%Lg %d", Infinityl (), 33, 44, 55);
2412     ASSERT (strcmp (result, "inf 33") == 0
2413             || strcmp (result, "infinity 33") == 0);
2414     ASSERT (retval == strlen (result));
2415   }
2416 
2417   { /* Negative infinity.  */
2418     int retval =
2419       my_snprintf (result, sizeof (result), "%Lg %d", - Infinityl (), 33, 44, 55);
2420     ASSERT (strcmp (result, "-inf 33") == 0
2421             || strcmp (result, "-infinity 33") == 0);
2422     ASSERT (retval == strlen (result));
2423   }
2424 
2425   { /* NaN.  */
2426     int retval =
2427       my_snprintf (result, sizeof (result), "%Lg %d", NaNl (), 33, 44, 55);
2428     ASSERT (strlen (result) >= 3 + 3
2429             && strisnan (result, 0, strlen (result) - 3, 0)
2430             && strcmp (result + strlen (result) - 3, " 33") == 0);
2431     ASSERT (retval == strlen (result));
2432   }
2433 #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
2434   { /* Quiet NaN.  */
2435     static union { unsigned int word[4]; long double value; } x =
2436       { LDBL80_WORDS (0xFFFF, 0xC3333333, 0x00000000) };
2437     int retval =
2438       my_snprintf (result, sizeof (result), "%Lg %d", x.value, 33, 44, 55);
2439     ASSERT (strlen (result) >= 3 + 3
2440             && strisnan (result, 0, strlen (result) - 3, 0)
2441             && strcmp (result + strlen (result) - 3, " 33") == 0);
2442     ASSERT (retval == strlen (result));
2443   }
2444   {
2445     /* Signalling NaN.  */
2446     static union { unsigned int word[4]; long double value; } x =
2447       { LDBL80_WORDS (0xFFFF, 0x83333333, 0x00000000) };
2448     int retval =
2449       my_snprintf (result, sizeof (result), "%Lg %d", x.value, 33, 44, 55);
2450     ASSERT (strlen (result) >= 3 + 3
2451             && strisnan (result, 0, strlen (result) - 3, 0)
2452             && strcmp (result + strlen (result) - 3, " 33") == 0);
2453     ASSERT (retval == strlen (result));
2454   }
2455   /* snprintf should print something for noncanonical values.  */
2456   { /* Pseudo-NaN.  */
2457     static union { unsigned int word[4]; long double value; } x =
2458       { LDBL80_WORDS (0xFFFF, 0x40000001, 0x00000000) };
2459     int retval =
2460       my_snprintf (result, sizeof (result), "%Lg %d", x.value, 33, 44, 55);
2461     ASSERT (retval == strlen (result));
2462     ASSERT (3 < retval && strcmp (result + retval - 3, " 33") == 0);
2463   }
2464   { /* Pseudo-Infinity.  */
2465     static union { unsigned int word[4]; long double value; } x =
2466       { LDBL80_WORDS (0xFFFF, 0x00000000, 0x00000000) };
2467     int retval =
2468       my_snprintf (result, sizeof (result), "%Lg %d", x.value, 33, 44, 55);
2469     ASSERT (retval == strlen (result));
2470     ASSERT (3 < retval && strcmp (result + retval - 3, " 33") == 0);
2471   }
2472   { /* Pseudo-Zero.  */
2473     static union { unsigned int word[4]; long double value; } x =
2474       { LDBL80_WORDS (0x4004, 0x00000000, 0x00000000) };
2475     int retval =
2476       my_snprintf (result, sizeof (result), "%Lg %d", x.value, 33, 44, 55);
2477     ASSERT (retval == strlen (result));
2478     ASSERT (3 < retval && strcmp (result + retval - 3, " 33") == 0);
2479   }
2480   { /* Unnormalized number.  */
2481     static union { unsigned int word[4]; long double value; } x =
2482       { LDBL80_WORDS (0x4000, 0x63333333, 0x00000000) };
2483     int retval =
2484       my_snprintf (result, sizeof (result), "%Lg %d", x.value, 33, 44, 55);
2485     ASSERT (retval == strlen (result));
2486     ASSERT (3 < retval && strcmp (result + retval - 3, " 33") == 0);
2487   }
2488   { /* Pseudo-Denormal.  */
2489     static union { unsigned int word[4]; long double value; } x =
2490       { LDBL80_WORDS (0x0000, 0x83333333, 0x00000000) };
2491     int retval =
2492       my_snprintf (result, sizeof (result), "%Lg %d", x.value, 33, 44, 55);
2493     ASSERT (retval == strlen (result));
2494     ASSERT (3 < retval && strcmp (result + retval - 3, " 33") == 0);
2495   }
2496 #endif
2497 
2498   { /* Width.  */
2499     int retval =
2500       my_snprintf (result, sizeof (result), "%10Lg %d", 1.75L, 33, 44, 55);
2501     ASSERT (strcmp (result, "      1.75 33") == 0);
2502     ASSERT (retval == strlen (result));
2503   }
2504 
2505   { /* FLAG_LEFT.  */
2506     int retval =
2507       my_snprintf (result, sizeof (result), "%-10Lg %d", 1.75L, 33, 44, 55);
2508     ASSERT (strcmp (result, "1.75       33") == 0);
2509     ASSERT (retval == strlen (result));
2510   }
2511 
2512   { /* FLAG_SHOWSIGN.  */
2513     int retval =
2514       my_snprintf (result, sizeof (result), "%+Lg %d", 1.75L, 33, 44, 55);
2515     ASSERT (strcmp (result, "+1.75 33") == 0);
2516     ASSERT (retval == strlen (result));
2517   }
2518 
2519   { /* FLAG_SPACE.  */
2520     int retval =
2521       my_snprintf (result, sizeof (result), "% Lg %d", 1.75L, 33, 44, 55);
2522     ASSERT (strcmp (result, " 1.75 33") == 0);
2523     ASSERT (retval == strlen (result));
2524   }
2525 
2526   { /* FLAG_ALT.  */
2527     int retval =
2528       my_snprintf (result, sizeof (result), "%#Lg %d", 1.75L, 33, 44, 55);
2529     ASSERT (strcmp (result, "1.75000 33") == 0);
2530     ASSERT (retval == strlen (result));
2531   }
2532 
2533   { /* FLAG_ALT.  */
2534     int retval =
2535       my_snprintf (result, sizeof (result), "%#.Lg %d", 1.75L, 33, 44, 55);
2536     ASSERT (strcmp (result, "2. 33") == 0);
2537     ASSERT (retval == strlen (result));
2538   }
2539 
2540   { /* FLAG_ALT.  */
2541     int retval =
2542       my_snprintf (result, sizeof (result), "%#.Lg %d", 9.75L, 33, 44, 55);
2543     ASSERT (strcmp (result, "1.e+01 33") == 0
2544             || strcmp (result, "1.e+001 33") == 0);
2545     ASSERT (retval == strlen (result));
2546   }
2547 
2548   { /* FLAG_ZERO with finite number.  */
2549     int retval =
2550       my_snprintf (result, sizeof (result), "%010Lg %d", 1234.0L, 33, 44, 55);
2551     ASSERT (strcmp (result, "0000001234 33") == 0);
2552     ASSERT (retval == strlen (result));
2553   }
2554 
2555   { /* FLAG_ZERO with infinite number.  */
2556     int retval =
2557       my_snprintf (result, sizeof (result), "%015Lg %d", - Infinityl (), 33, 44, 55);
2558     ASSERT (strcmp (result, "           -inf 33") == 0
2559             || strcmp (result, "      -infinity 33") == 0);
2560     ASSERT (retval == strlen (result));
2561   }
2562 
2563   { /* FLAG_ZERO with NaN.  */
2564     int retval =
2565       my_snprintf (result, sizeof (result), "%050Lg %d", NaNl (), 33, 44, 55);
2566     ASSERT (strlen (result) == 50 + 3
2567             && strisnan (result, strspn (result, " "), strlen (result) - 3, 0)
2568             && strcmp (result + strlen (result) - 3, " 33") == 0);
2569     ASSERT (retval == strlen (result));
2570   }
2571 
2572   { /* Precision.  */
2573     int retval =
2574       my_snprintf (result, sizeof (result), "%.Lg %d", 1234.0L, 33, 44, 55);
2575     ASSERT (strcmp (result, "1e+03 33") == 0
2576             || strcmp (result, "1e+003 33") == 0);
2577     ASSERT (retval == strlen (result));
2578   }
2579 
2580   { /* Precision with no rounding.  */
2581     int retval =
2582       my_snprintf (result, sizeof (result), "%.5Lg %d", 999.951L, 33, 44, 55);
2583     ASSERT (strcmp (result, "999.95 33") == 0);
2584     ASSERT (retval == strlen (result));
2585   }
2586 
2587   { /* Precision with rounding.  */
2588     int retval =
2589       my_snprintf (result, sizeof (result), "%.5Lg %d", 999.996L, 33, 44, 55);
2590     ASSERT (strcmp (result, "1000 33") == 0);
2591     ASSERT (retval == strlen (result));
2592   }
2593 
2594   /* Test the support of the %n format directive.  */
2595 
2596   {
2597     int count = -1;
2598     int retval =
2599       my_snprintf (result, sizeof (result), "%d %n", 123, &count, 33, 44, 55);
2600     ASSERT (strcmp (result, "123 ") == 0);
2601     ASSERT (retval == strlen (result));
2602     ASSERT (count == 4);
2603   }
2604 
2605   /* Test the support of the POSIX/XSI format strings with positions.  */
2606 
2607   {
2608     int retval =
2609       my_snprintf (result, sizeof (result), "%2$d %1$d", 33, 55);
2610     ASSERT (strcmp (result, "55 33") == 0);
2611     ASSERT (retval == strlen (result));
2612   }
2613 
2614   /* Test the support of the grouping flag.  */
2615 
2616   {
2617     int retval =
2618       my_snprintf (result, sizeof (result), "%'d %d", 1234567, 99);
2619     ASSERT (result[strlen (result) - 1] == '9');
2620     ASSERT (retval == strlen (result));
2621   }
2622 
2623   /* Test the support of the left-adjust flag.  */
2624 
2625   {
2626     int retval =
2627       my_snprintf (result, sizeof (result), "a%*sc", -3, "b");
2628     ASSERT (strcmp (result, "ab  c") == 0);
2629     ASSERT (retval == strlen (result));
2630   }
2631 
2632   {
2633     int retval =
2634       my_snprintf (result, sizeof (result), "a%-*sc", 3, "b");
2635     ASSERT (strcmp (result, "ab  c") == 0);
2636     ASSERT (retval == strlen (result));
2637   }
2638 
2639   {
2640     int retval =
2641       my_snprintf (result, sizeof (result), "a%-*sc", -3, "b");
2642     ASSERT (strcmp (result, "ab  c") == 0);
2643     ASSERT (retval == strlen (result));
2644   }
2645 
2646   /* Test the support of large precision.  */
2647 
2648   {
2649     int retval =
2650       my_snprintf (result, sizeof (result), "%.4000d %d", 1234567, 99);
2651     size_t i;
2652     for (i = 0; i < 4000 - 7; i++)
2653       ASSERT (result[i] == '0');
2654     ASSERT (strcmp (result + 4000 - 7, "1234567 99") == 0);
2655     ASSERT (retval == strlen (result));
2656   }
2657 
2658   {
2659     int retval =
2660       my_snprintf (result, sizeof (result), "%.*d %d", 4000, 1234567, 99);
2661     size_t i;
2662     for (i = 0; i < 4000 - 7; i++)
2663       ASSERT (result[i] == '0');
2664     ASSERT (strcmp (result + 4000 - 7, "1234567 99") == 0);
2665     ASSERT (retval == strlen (result));
2666   }
2667 
2668   {
2669     int retval =
2670       my_snprintf (result, sizeof (result), "%.4000d %d", -1234567, 99);
2671     size_t i;
2672     ASSERT (result[0] == '-');
2673     for (i = 0; i < 4000 - 7; i++)
2674       ASSERT (result[1 + i] == '0');
2675     ASSERT (strcmp (result + 1 + 4000 - 7, "1234567 99") == 0);
2676     ASSERT (retval == strlen (result));
2677   }
2678 
2679   {
2680     int retval =
2681       my_snprintf (result, sizeof (result), "%.4000u %d", 1234567, 99);
2682     size_t i;
2683     for (i = 0; i < 4000 - 7; i++)
2684       ASSERT (result[i] == '0');
2685     ASSERT (strcmp (result + 4000 - 7, "1234567 99") == 0);
2686     ASSERT (retval == strlen (result));
2687   }
2688 
2689   {
2690     int retval =
2691       my_snprintf (result, sizeof (result), "%.4000o %d", 1234567, 99);
2692     size_t i;
2693     for (i = 0; i < 4000 - 7; i++)
2694       ASSERT (result[i] == '0');
2695     ASSERT (strcmp (result + 4000 - 7, "4553207 99") == 0);
2696     ASSERT (retval == strlen (result));
2697   }
2698 
2699   {
2700     int retval =
2701       my_snprintf (result, sizeof (result), "%.4000x %d", 1234567, 99);
2702     size_t i;
2703     for (i = 0; i < 4000 - 6; i++)
2704       ASSERT (result[i] == '0');
2705     ASSERT (strcmp (result + 4000 - 6, "12d687 99") == 0);
2706     ASSERT (retval == strlen (result));
2707   }
2708 
2709   {
2710     int retval =
2711       my_snprintf (result, sizeof (result), "%#.4000x %d", 1234567, 99);
2712     size_t i;
2713     ASSERT (result[0] == '0');
2714     ASSERT (result[1] == 'x');
2715     for (i = 0; i < 4000 - 6; i++)
2716       ASSERT (result[2 + i] == '0');
2717     ASSERT (strcmp (result + 2 + 4000 - 6, "12d687 99") == 0);
2718     ASSERT (retval == strlen (result));
2719   }
2720 
2721   {
2722     int retval =
2723       my_snprintf (result, sizeof (result), "%.4000f %d", 1.0, 99);
2724     size_t i;
2725     ASSERT (result[0] == '1');
2726     ASSERT (result[1] == '.');
2727     for (i = 0; i < 4000; i++)
2728       ASSERT (result[2 + i] == '0');
2729     ASSERT (strcmp (result + 2 + 4000, " 99") == 0);
2730     ASSERT (retval == strlen (result));
2731   }
2732 
2733   {
2734     int retval =
2735       my_snprintf (result, sizeof (result), "%.511f %d", 1.0, 99);
2736     size_t i;
2737     ASSERT (result[0] == '1');
2738     ASSERT (result[1] == '.');
2739     for (i = 0; i < 511; i++)
2740       ASSERT (result[2 + i] == '0');
2741     ASSERT (strcmp (result + 2 + 511, " 99") == 0);
2742     ASSERT (retval == strlen (result));
2743   }
2744 
2745   {
2746     char input[5000];
2747     int retval;
2748     size_t i;
2749 
2750     for (i = 0; i < sizeof (input) - 1; i++)
2751       input[i] = 'a' + ((1000000 / (i + 1)) % 26);
2752     input[i] = '\0';
2753     retval = my_snprintf (result, sizeof (result), "%.4000s %d", input, 99);
2754     ASSERT (memcmp (result, input, 4000) == 0);
2755     ASSERT (strcmp (result + 4000, " 99") == 0);
2756     ASSERT (retval == strlen (result));
2757   }
2758 
2759   /* Test the support of the %s format directive.  */
2760 
2761   /* To verify that these tests succeed, it is necessary to run them under
2762      a tool that checks against invalid memory accesses, such as ElectricFence
2763      or "valgrind --tool=memcheck".  */
2764   {
2765     size_t i;
2766 
2767     for (i = 1; i <= 8; i++)
2768       {
2769         char *block;
2770         int retval;
2771 
2772         block = (char *) malloc (i);
2773         memcpy (block, "abcdefgh", i);
2774         retval = my_snprintf (result, sizeof (result), "%.*s", (int) i, block);
2775         ASSERT (memcmp (result, block, i) == 0);
2776         ASSERT (result[i] == '\0');
2777         ASSERT (retval == strlen (result));
2778         free (block);
2779       }
2780   }
2781 #if HAVE_WCHAR_T
2782   {
2783     size_t i;
2784 
2785     for (i = 1; i <= 8; i++)
2786       {
2787         wchar_t *block;
2788         size_t j;
2789         int retval;
2790 
2791         block = (wchar_t *) malloc (i * sizeof (wchar_t));
2792         for (j = 0; j < i; j++)
2793           block[j] = "abcdefgh"[j];
2794         retval = my_snprintf (result, sizeof (result), "%.*ls", (int) i, block);
2795         ASSERT (memcmp (result, "abcdefgh", i) == 0);
2796         ASSERT (result[i] == '\0');
2797         ASSERT (retval == strlen (result));
2798         free (block);
2799       }
2800   }
2801 #endif
2802 }

/* [previous][next][first][last][top][bottom][index][help] */