annotate tests/test-snprintf-posix.h @ 40196:e63f5d3edab5

relocatable-prog: Update documentation. * doc/relocatable-maint.texi (Supporting Relocation): Update to match the recent changes.
author Bruno Haible <bruno@clisp.org>
date Sun, 24 Feb 2019 01:49:15 +0100
parents b06060465f09
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8364
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1 /* Test of POSIX compatible vsnprintf() and snprintf() functions.
40057
b06060465f09 maint: Run 'make update-copyright'
Paul Eggert <eggert@cs.ucla.edu>
parents: 19484
diff changeset
2 Copyright (C) 2007-2019 Free Software Foundation, Inc.
8364
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3
9309
bbbbbf4cd1c5 Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 8919
diff changeset
4 This program is free software: you can redistribute it and/or modify
8364
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
5 it under the terms of the GNU General Public License as published by
9309
bbbbbf4cd1c5 Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 8919
diff changeset
6 the Free Software Foundation; either version 3 of the License, or
bbbbbf4cd1c5 Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 8919
diff changeset
7 (at your option) any later version.
8364
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
8
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
9 This program is distributed in the hope that it will be useful,
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
12 GNU General Public License for more details.
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
13
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
14 You should have received a copy of the GNU General Public License
19190
9759915b2aca all: prefer https: URLs
Paul Eggert <eggert@cs.ucla.edu>
parents: 18626
diff changeset
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
8364
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
16
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
17 /* Written by Bruno Haible <bruno@clisp.org>, 2007. */
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
18
13834
108bbfd6f03b frexp, tests: work around ICC bug with -zero
Eric Blake <eblake@redhat.com>
parents: 12559
diff changeset
19 #include "minus-zero.h"
15595
328819af1c02 Support for MSVC compiler: Avoid division by a literal 0.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
20 #include "infinity.h"
9854
baba3b346ab2 Use macros NaNf, NaNd, NaNl instead of NAN.
Bruno Haible <bruno@clisp.org>
parents: 9850
diff changeset
21 #include "nan.h"
8543
e1fdf02d5cdc Work around a DEC C compiler bug.
Bruno Haible <bruno@clisp.org>
parents: 8364
diff changeset
22
8852
df0b5e8ea770 Avoid test failures on platforms where -0.0 and 0.0 are identical.
Bruno Haible <bruno@clisp.org>
parents: 8850
diff changeset
23 /* The SGI MIPS floating-point format does not distinguish 0.0 and -0.0. */
df0b5e8ea770 Avoid test failures on platforms where -0.0 and 0.0 are identical.
Bruno Haible <bruno@clisp.org>
parents: 8850
diff changeset
24 static int
df0b5e8ea770 Avoid test failures on platforms where -0.0 and 0.0 are identical.
Bruno Haible <bruno@clisp.org>
parents: 8850
diff changeset
25 have_minus_zero ()
df0b5e8ea770 Avoid test failures on platforms where -0.0 and 0.0 are identical.
Bruno Haible <bruno@clisp.org>
parents: 8850
diff changeset
26 {
df0b5e8ea770 Avoid test failures on platforms where -0.0 and 0.0 are identical.
Bruno Haible <bruno@clisp.org>
parents: 8850
diff changeset
27 static double plus_zero = 0.0;
13834
108bbfd6f03b frexp, tests: work around ICC bug with -zero
Eric Blake <eblake@redhat.com>
parents: 12559
diff changeset
28 double minus_zero = minus_zerod;
8852
df0b5e8ea770 Avoid test failures on platforms where -0.0 and 0.0 are identical.
Bruno Haible <bruno@clisp.org>
parents: 8850
diff changeset
29 return memcmp (&plus_zero, &minus_zero, sizeof (double)) != 0;
df0b5e8ea770 Avoid test failures on platforms where -0.0 and 0.0 are identical.
Bruno Haible <bruno@clisp.org>
parents: 8850
diff changeset
30 }
df0b5e8ea770 Avoid test failures on platforms where -0.0 and 0.0 are identical.
Bruno Haible <bruno@clisp.org>
parents: 8850
diff changeset
31
8919
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8870
diff changeset
32 /* Representation of an 80-bit 'long double' as an initializer for a sequence
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8870
diff changeset
33 of 'unsigned int' words. */
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8870
diff changeset
34 #ifdef WORDS_BIGENDIAN
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8870
diff changeset
35 # define LDBL80_WORDS(exponent,manthi,mantlo) \
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8870
diff changeset
36 { ((unsigned int) (exponent) << 16) | ((unsigned int) (manthi) >> 16), \
17815
b9d8153a9ca9 Fix LDBL80_WORDS macro on big endian platforms.
Bruno Haible <bruno@clisp.org>
parents: 17576
diff changeset
37 ((unsigned int) (manthi) << 16) | ((unsigned int) (mantlo) >> 16), \
8919
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8870
diff changeset
38 (unsigned int) (mantlo) << 16 \
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8870
diff changeset
39 }
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8870
diff changeset
40 #else
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8870
diff changeset
41 # define LDBL80_WORDS(exponent,manthi,mantlo) \
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8870
diff changeset
42 { mantlo, manthi, exponent }
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8870
diff changeset
43 #endif
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8870
diff changeset
44
8834
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
45 static int
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
46 strmatch (const char *pattern, const char *string)
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
47 {
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
48 if (strlen (pattern) != strlen (string))
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
49 return 0;
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
50 for (; *pattern != '\0'; pattern++, string++)
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
51 if (*pattern != '*' && *string != *pattern)
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
52 return 0;
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
53 return 1;
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
54 }
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
55
8865
9e203d8ade65 Stricter check for printf result for NaN arguments.
Bruno Haible <bruno@clisp.org>
parents: 8857
diff changeset
56 /* Test whether string[start_index..end_index-1] is a valid textual
9e203d8ade65 Stricter check for printf result for NaN arguments.
Bruno Haible <bruno@clisp.org>
parents: 8857
diff changeset
57 representation of NaN. */
9e203d8ade65 Stricter check for printf result for NaN arguments.
Bruno Haible <bruno@clisp.org>
parents: 8857
diff changeset
58 static int
9e203d8ade65 Stricter check for printf result for NaN arguments.
Bruno Haible <bruno@clisp.org>
parents: 8857
diff changeset
59 strisnan (const char *string, size_t start_index, size_t end_index, int uppercase)
9e203d8ade65 Stricter check for printf result for NaN arguments.
Bruno Haible <bruno@clisp.org>
parents: 8857
diff changeset
60 {
9e203d8ade65 Stricter check for printf result for NaN arguments.
Bruno Haible <bruno@clisp.org>
parents: 8857
diff changeset
61 if (start_index < end_index)
9e203d8ade65 Stricter check for printf result for NaN arguments.
Bruno Haible <bruno@clisp.org>
parents: 8857
diff changeset
62 {
9e203d8ade65 Stricter check for printf result for NaN arguments.
Bruno Haible <bruno@clisp.org>
parents: 8857
diff changeset
63 if (string[start_index] == '-')
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
64 start_index++;
8865
9e203d8ade65 Stricter check for printf result for NaN arguments.
Bruno Haible <bruno@clisp.org>
parents: 8857
diff changeset
65 if (start_index + 3 <= end_index
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
66 && memcmp (string + start_index, uppercase ? "NAN" : "nan", 3) == 0)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
67 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
68 start_index += 3;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
69 if (start_index == end_index
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
70 || (string[start_index] == '(' && string[end_index - 1] == ')'))
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
71 return 1;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
72 }
8865
9e203d8ade65 Stricter check for printf result for NaN arguments.
Bruno Haible <bruno@clisp.org>
parents: 8857
diff changeset
73 }
9e203d8ade65 Stricter check for printf result for NaN arguments.
Bruno Haible <bruno@clisp.org>
parents: 8857
diff changeset
74 return 0;
9e203d8ade65 Stricter check for printf result for NaN arguments.
Bruno Haible <bruno@clisp.org>
parents: 8857
diff changeset
75 }
9850
7f3ed6b093be Guarantee a definition of NAN.
Eric Blake <ebb9@byu.net>
parents: 9674
diff changeset
76
8364
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
77 static void
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
78 test_function (int (*my_snprintf) (char *, size_t, const char *, ...))
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
79 {
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
80 char buf[8];
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
81 int size;
17927
b941bb9e9efb printf, isinf, etc.: noncanonical != NaN
Paul Eggert <eggert@cs.ucla.edu>
parents: 17848
diff changeset
82 char result[5000];
8364
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
83
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
84 /* Test return value convention. */
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
85
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
86 for (size = 0; size <= 8; size++)
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
87 {
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
88 int retval;
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
89
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
90 memcpy (buf, "DEADBEEF", 8);
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
91 retval = my_snprintf (buf, size, "%d", 12345);
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
92 ASSERT (retval == 5);
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
93 if (size < 6)
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
94 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
95 if (size > 0)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
96 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
97 ASSERT (memcmp (buf, "12345", size - 1) == 0);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
98 ASSERT (buf[size - 1] == '\0');
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
99 }
17406
3e765e2f4c46 parse-datetime, tests: don't use "string" + int
Paul Eggert <eggert@cs.ucla.edu>
parents: 17249
diff changeset
100 ASSERT (memcmp (buf + size, &"DEADBEEF"[size], 8 - size) == 0);
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
101 }
8364
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
102 else
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
103 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
104 ASSERT (memcmp (buf, "12345\0EF", 8) == 0);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
105 }
8364
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
106 }
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
107
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
108 /* Test support of size specifiers as in C99. */
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
109
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
110 {
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
111 int retval =
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
112 my_snprintf (result, sizeof (result), "%ju %d", (uintmax_t) 12345671, 33, 44, 55);
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
113 ASSERT (strcmp (result, "12345671 33") == 0);
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
114 ASSERT (retval == strlen (result));
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
115 }
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
116
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
117 {
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
118 int retval =
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
119 my_snprintf (result, sizeof (result), "%zu %d", (size_t) 12345672, 33, 44, 55);
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
120 ASSERT (strcmp (result, "12345672 33") == 0);
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
121 ASSERT (retval == strlen (result));
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
122 }
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
123
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
124 {
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
125 int retval =
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
126 my_snprintf (result, sizeof (result), "%tu %d", (ptrdiff_t) 12345673, 33, 44, 55);
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
127 ASSERT (strcmp (result, "12345673 33") == 0);
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
128 ASSERT (retval == strlen (result));
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
129 }
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
130
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
131 {
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
132 int retval =
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
133 my_snprintf (result, sizeof (result), "%Lg %d", (long double) 1.5, 33, 44, 55);
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
134 ASSERT (strcmp (result, "1.5 33") == 0);
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
135 ASSERT (retval == strlen (result));
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
136 }
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
137
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
138 /* Test the support of the 'a' and 'A' conversion specifier for hexadecimal
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
139 output of floating-point numbers. */
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
140
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
141 { /* A positive number. */
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
142 int retval =
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
143 my_snprintf (result, sizeof (result), "%a %d", 3.1416015625, 33, 44, 55);
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
144 ASSERT (strcmp (result, "0x1.922p+1 33") == 0
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
145 || strcmp (result, "0x3.244p+0 33") == 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
146 || strcmp (result, "0x6.488p-1 33") == 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
147 || strcmp (result, "0xc.91p-2 33") == 0);
8364
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
148 ASSERT (retval == strlen (result));
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
149 }
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
150
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
151 { /* A negative number. */
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
152 int retval =
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
153 my_snprintf (result, sizeof (result), "%A %d", -3.1416015625, 33, 44, 55);
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
154 ASSERT (strcmp (result, "-0X1.922P+1 33") == 0
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
155 || strcmp (result, "-0X3.244P+0 33") == 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
156 || strcmp (result, "-0X6.488P-1 33") == 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
157 || strcmp (result, "-0XC.91P-2 33") == 0);
8364
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
158 ASSERT (retval == strlen (result));
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
159 }
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
160
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
161 { /* Positive zero. */
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
162 int retval =
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
163 my_snprintf (result, sizeof (result), "%a %d", 0.0, 33, 44, 55);
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
164 ASSERT (strcmp (result, "0x0p+0 33") == 0);
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
165 ASSERT (retval == strlen (result));
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
166 }
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
167
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
168 { /* Negative zero. */
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
169 int retval =
13834
108bbfd6f03b frexp, tests: work around ICC bug with -zero
Eric Blake <eblake@redhat.com>
parents: 12559
diff changeset
170 my_snprintf (result, sizeof (result), "%a %d", minus_zerod, 33, 44, 55);
8852
df0b5e8ea770 Avoid test failures on platforms where -0.0 and 0.0 are identical.
Bruno Haible <bruno@clisp.org>
parents: 8850
diff changeset
171 if (have_minus_zero ())
df0b5e8ea770 Avoid test failures on platforms where -0.0 and 0.0 are identical.
Bruno Haible <bruno@clisp.org>
parents: 8850
diff changeset
172 ASSERT (strcmp (result, "-0x0p+0 33") == 0);
8364
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
173 ASSERT (retval == strlen (result));
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
174 }
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
175
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
176 { /* Positive infinity. */
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
177 int retval =
15595
328819af1c02 Support for MSVC compiler: Avoid division by a literal 0.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
178 my_snprintf (result, sizeof (result), "%a %d", Infinityd (), 33, 44, 55);
8364
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
179 ASSERT (strcmp (result, "inf 33") == 0);
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
180 ASSERT (retval == strlen (result));
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
181 }
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
182
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
183 { /* Negative infinity. */
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
184 int retval =
15595
328819af1c02 Support for MSVC compiler: Avoid division by a literal 0.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
185 my_snprintf (result, sizeof (result), "%a %d", - Infinityd (), 33, 44, 55);
8364
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
186 ASSERT (strcmp (result, "-inf 33") == 0);
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
187 ASSERT (retval == strlen (result));
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
188 }
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
189
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
190 { /* NaN. */
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
191 int retval =
9854
baba3b346ab2 Use macros NaNf, NaNd, NaNl instead of NAN.
Bruno Haible <bruno@clisp.org>
parents: 9850
diff changeset
192 my_snprintf (result, sizeof (result), "%a %d", NaNd (), 33, 44, 55);
8850
d1fe16dfbfee Avoid test failures on IRIX 6.5.
Bruno Haible <bruno@clisp.org>
parents: 8839
diff changeset
193 ASSERT (strlen (result) >= 3 + 3
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
194 && strisnan (result, 0, strlen (result) - 3, 0)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
195 && strcmp (result + strlen (result) - 3, " 33") == 0);
8364
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
196 ASSERT (retval == strlen (result));
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
197 }
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
198
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
199 { /* Rounding near the decimal point. */
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
200 int retval =
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
201 my_snprintf (result, sizeof (result), "%.0a %d", 1.5, 33, 44, 55);
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
202 ASSERT (strcmp (result, "0x2p+0 33") == 0
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
203 || strcmp (result, "0x3p-1 33") == 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
204 || strcmp (result, "0x6p-2 33") == 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
205 || strcmp (result, "0xcp-3 33") == 0);
8364
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
206 ASSERT (retval == strlen (result));
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
207 }
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
208
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
209 { /* Rounding with precision 0. */
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
210 int retval =
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
211 my_snprintf (result, sizeof (result), "%.0a %d", 1.51, 33, 44, 55);
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
212 ASSERT (strcmp (result, "0x2p+0 33") == 0
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
213 || strcmp (result, "0x3p-1 33") == 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
214 || strcmp (result, "0x6p-2 33") == 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
215 || strcmp (result, "0xcp-3 33") == 0);
8364
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
216 ASSERT (retval == strlen (result));
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
217 }
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
218
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
219 { /* Rounding with precision 1. */
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
220 int retval =
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
221 my_snprintf (result, sizeof (result), "%.1a %d", 1.51, 33, 44, 55);
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
222 ASSERT (strcmp (result, "0x1.8p+0 33") == 0
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
223 || strcmp (result, "0x3.0p-1 33") == 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
224 || strcmp (result, "0x6.1p-2 33") == 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
225 || strcmp (result, "0xc.1p-3 33") == 0);
8364
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
226 ASSERT (retval == strlen (result));
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
227 }
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
228
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
229 { /* Rounding with precision 2. */
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
230 int retval =
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
231 my_snprintf (result, sizeof (result), "%.2a %d", 1.51, 33, 44, 55);
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
232 ASSERT (strcmp (result, "0x1.83p+0 33") == 0
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
233 || strcmp (result, "0x3.05p-1 33") == 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
234 || strcmp (result, "0x6.0ap-2 33") == 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
235 || strcmp (result, "0xc.14p-3 33") == 0);
8364
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
236 ASSERT (retval == strlen (result));
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
237 }
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
238
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
239 { /* Rounding with precision 3. */
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
240 int retval =
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
241 my_snprintf (result, sizeof (result), "%.3a %d", 1.51, 33, 44, 55);
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
242 ASSERT (strcmp (result, "0x1.829p+0 33") == 0
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
243 || strcmp (result, "0x3.052p-1 33") == 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
244 || strcmp (result, "0x6.0a4p-2 33") == 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
245 || strcmp (result, "0xc.148p-3 33") == 0);
8364
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
246 ASSERT (retval == strlen (result));
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
247 }
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
248
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
249 { /* Rounding can turn a ...FFF into a ...000. */
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
250 int retval =
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
251 my_snprintf (result, sizeof (result), "%.3a %d", 1.49999, 33, 44, 55);
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
252 ASSERT (strcmp (result, "0x1.800p+0 33") == 0
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
253 || strcmp (result, "0x3.000p-1 33") == 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
254 || strcmp (result, "0x6.000p-2 33") == 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
255 || strcmp (result, "0xc.000p-3 33") == 0);
8364
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
256 ASSERT (retval == strlen (result));
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
257 }
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
258
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
259 { /* Rounding can turn a ...FFF into a ...000.
16935
498a2211d839 Write "Mac OS X" instead of "MacOS X".
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
260 This shows a Mac OS X 10.3.9 (Darwin 7.9) bug. */
8364
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
261 int retval =
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
262 my_snprintf (result, sizeof (result), "%.1a %d", 1.999, 33, 44, 55);
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
263 ASSERT (strcmp (result, "0x1.0p+1 33") == 0
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
264 || strcmp (result, "0x2.0p+0 33") == 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
265 || strcmp (result, "0x4.0p-1 33") == 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
266 || strcmp (result, "0x8.0p-2 33") == 0);
8364
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
267 ASSERT (retval == strlen (result));
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
268 }
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
269
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
270 { /* Width. */
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
271 int retval =
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
272 my_snprintf (result, sizeof (result), "%10a %d", 1.75, 33, 44, 55);
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
273 ASSERT (strcmp (result, " 0x1.cp+0 33") == 0
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
274 || strcmp (result, " 0x3.8p-1 33") == 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
275 || strcmp (result, " 0x7p-2 33") == 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
276 || strcmp (result, " 0xep-3 33") == 0);
8364
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
277 ASSERT (retval == strlen (result));
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
278 }
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
279
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
280 { /* Small precision. */
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
281 int retval =
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
282 my_snprintf (result, sizeof (result), "%.10a %d", 1.75, 33, 44, 55);
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
283 ASSERT (strcmp (result, "0x1.c000000000p+0 33") == 0
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
284 || strcmp (result, "0x3.8000000000p-1 33") == 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
285 || strcmp (result, "0x7.0000000000p-2 33") == 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
286 || strcmp (result, "0xe.0000000000p-3 33") == 0);
8364
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
287 ASSERT (retval == strlen (result));
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
288 }
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
289
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
290 { /* Large precision. */
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
291 int retval =
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
292 my_snprintf (result, sizeof (result), "%.50a %d", 1.75, 33, 44, 55);
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
293 ASSERT (strcmp (result, "0x1.c0000000000000000000000000000000000000000000000000p+0 33") == 0
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
294 || strcmp (result, "0x3.80000000000000000000000000000000000000000000000000p-1 33") == 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
295 || strcmp (result, "0x7.00000000000000000000000000000000000000000000000000p-2 33") == 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
296 || strcmp (result, "0xe.00000000000000000000000000000000000000000000000000p-3 33") == 0);
8364
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
297 ASSERT (retval == strlen (result));
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
298 }
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
299
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
300 { /* FLAG_LEFT. */
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
301 int retval =
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
302 my_snprintf (result, sizeof (result), "%-10a %d", 1.75, 33, 44, 55);
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
303 ASSERT (strcmp (result, "0x1.cp+0 33") == 0
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
304 || strcmp (result, "0x3.8p-1 33") == 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
305 || strcmp (result, "0x7p-2 33") == 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
306 || strcmp (result, "0xep-3 33") == 0);
8364
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
307 ASSERT (retval == strlen (result));
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
308 }
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
309
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
310 { /* FLAG_SHOWSIGN. */
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
311 int retval =
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
312 my_snprintf (result, sizeof (result), "%+a %d", 1.75, 33, 44, 55);
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
313 ASSERT (strcmp (result, "+0x1.cp+0 33") == 0
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
314 || strcmp (result, "+0x3.8p-1 33") == 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
315 || strcmp (result, "+0x7p-2 33") == 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
316 || strcmp (result, "+0xep-3 33") == 0);
8364
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
317 ASSERT (retval == strlen (result));
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
318 }
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
319
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
320 { /* FLAG_SPACE. */
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
321 int retval =
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
322 my_snprintf (result, sizeof (result), "% a %d", 1.75, 33, 44, 55);
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
323 ASSERT (strcmp (result, " 0x1.cp+0 33") == 0
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
324 || strcmp (result, " 0x3.8p-1 33") == 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
325 || strcmp (result, " 0x7p-2 33") == 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
326 || strcmp (result, " 0xep-3 33") == 0);
8364
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
327 ASSERT (retval == strlen (result));
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
328 }
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
329
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
330 { /* FLAG_ALT. */
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
331 int retval =
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
332 my_snprintf (result, sizeof (result), "%#a %d", 1.75, 33, 44, 55);
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
333 ASSERT (strcmp (result, "0x1.cp+0 33") == 0
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
334 || strcmp (result, "0x3.8p-1 33") == 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
335 || strcmp (result, "0x7.p-2 33") == 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
336 || strcmp (result, "0xe.p-3 33") == 0);
8364
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
337 ASSERT (retval == strlen (result));
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
338 }
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
339
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
340 { /* FLAG_ALT. */
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
341 int retval =
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
342 my_snprintf (result, sizeof (result), "%#a %d", 1.0, 33, 44, 55);
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
343 ASSERT (strcmp (result, "0x1.p+0 33") == 0
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
344 || strcmp (result, "0x2.p-1 33") == 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
345 || strcmp (result, "0x4.p-2 33") == 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
346 || strcmp (result, "0x8.p-3 33") == 0);
8364
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
347 ASSERT (retval == strlen (result));
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
348 }
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
349
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
350 { /* FLAG_ZERO with finite number. */
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
351 int retval =
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
352 my_snprintf (result, sizeof (result), "%010a %d", 1.75, 33, 44, 55);
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
353 ASSERT (strcmp (result, "0x001.cp+0 33") == 0
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
354 || strcmp (result, "0x003.8p-1 33") == 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
355 || strcmp (result, "0x00007p-2 33") == 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
356 || strcmp (result, "0x0000ep-3 33") == 0);
8364
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
357 ASSERT (retval == strlen (result));
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
358 }
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
359
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
360 { /* FLAG_ZERO with infinite number. */
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
361 int retval =
15595
328819af1c02 Support for MSVC compiler: Avoid division by a literal 0.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
362 my_snprintf (result, sizeof (result), "%010a %d", Infinityd (), 33, 44, 55);
8662
023aa5c883a7 Guard against FreeBSD 6.1 bug.
Bruno Haible <bruno@clisp.org>
parents: 8648
diff changeset
363 /* "0000000inf 33" is not a valid result; see
19439
8bfc20b57265 maint: shorten https://lists.gnu.org/archive/html/... links
Jim Meyering <meyering@fb.com>
parents: 19192
diff changeset
364 <https://lists.gnu.org/r/bug-gnulib/2007-04/msg00107.html> */
8662
023aa5c883a7 Guard against FreeBSD 6.1 bug.
Bruno Haible <bruno@clisp.org>
parents: 8648
diff changeset
365 ASSERT (strcmp (result, " inf 33") == 0);
8364
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
366 ASSERT (retval == strlen (result));
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
367 }
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
368
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
369 { /* FLAG_ZERO with NaN. */
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
370 int retval =
9854
baba3b346ab2 Use macros NaNf, NaNd, NaNl instead of NAN.
Bruno Haible <bruno@clisp.org>
parents: 9850
diff changeset
371 my_snprintf (result, sizeof (result), "%050a %d", NaNd (), 33, 44, 55);
8662
023aa5c883a7 Guard against FreeBSD 6.1 bug.
Bruno Haible <bruno@clisp.org>
parents: 8648
diff changeset
372 /* "0000000nan 33" is not a valid result; see
19439
8bfc20b57265 maint: shorten https://lists.gnu.org/archive/html/... links
Jim Meyering <meyering@fb.com>
parents: 19192
diff changeset
373 <https://lists.gnu.org/r/bug-gnulib/2007-04/msg00107.html> */
8870
4e1f2ea486b4 Allow for a longer printed representation of NaN.
Bruno Haible <bruno@clisp.org>
parents: 8865
diff changeset
374 ASSERT (strlen (result) == 50 + 3
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
375 && strisnan (result, strspn (result, " "), strlen (result) - 3, 0)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
376 && strcmp (result + strlen (result) - 3, " 33") == 0);
8364
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
377 ASSERT (retval == strlen (result));
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
378 }
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
379
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
380 { /* A positive number. */
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
381 int retval =
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
382 my_snprintf (result, sizeof (result), "%La %d", 3.1416015625L, 33, 44, 55);
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
383 ASSERT (strcmp (result, "0x1.922p+1 33") == 0
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
384 || strcmp (result, "0x3.244p+0 33") == 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
385 || strcmp (result, "0x6.488p-1 33") == 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
386 || strcmp (result, "0xc.91p-2 33") == 0);
8364
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
387 ASSERT (retval == strlen (result));
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
388 }
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
389
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
390 { /* A negative number. */
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
391 int retval =
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
392 my_snprintf (result, sizeof (result), "%LA %d", -3.1416015625L, 33, 44, 55);
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
393 ASSERT (strcmp (result, "-0X1.922P+1 33") == 0
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
394 || strcmp (result, "-0X3.244P+0 33") == 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
395 || strcmp (result, "-0X6.488P-1 33") == 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
396 || strcmp (result, "-0XC.91P-2 33") == 0);
8364
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
397 ASSERT (retval == strlen (result));
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
398 }
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
399
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
400 { /* Positive zero. */
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
401 int retval =
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
402 my_snprintf (result, sizeof (result), "%La %d", 0.0L, 33, 44, 55);
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
403 ASSERT (strcmp (result, "0x0p+0 33") == 0);
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
404 ASSERT (retval == strlen (result));
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
405 }
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
406
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
407 { /* Negative zero. */
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
408 int retval =
10601
ca053fa79cd3 Use a more portable replacement expression for -0.0L.
Bruno Haible <bruno@clisp.org>
parents: 10458
diff changeset
409 my_snprintf (result, sizeof (result), "%La %d", minus_zerol, 33, 44, 55);
8852
df0b5e8ea770 Avoid test failures on platforms where -0.0 and 0.0 are identical.
Bruno Haible <bruno@clisp.org>
parents: 8850
diff changeset
410 if (have_minus_zero ())
df0b5e8ea770 Avoid test failures on platforms where -0.0 and 0.0 are identical.
Bruno Haible <bruno@clisp.org>
parents: 8850
diff changeset
411 ASSERT (strcmp (result, "-0x0p+0 33") == 0);
8364
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
412 ASSERT (retval == strlen (result));
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
413 }
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
414
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
415 { /* Positive infinity. */
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
416 int retval =
15595
328819af1c02 Support for MSVC compiler: Avoid division by a literal 0.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
417 my_snprintf (result, sizeof (result), "%La %d", Infinityl (), 33, 44, 55);
8364
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
418 ASSERT (strcmp (result, "inf 33") == 0);
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
419 ASSERT (retval == strlen (result));
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
420 }
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
421
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
422 { /* Negative infinity. */
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
423 int retval =
15595
328819af1c02 Support for MSVC compiler: Avoid division by a literal 0.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
424 my_snprintf (result, sizeof (result), "%La %d", - Infinityl (), 33, 44, 55);
8364
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
425 ASSERT (strcmp (result, "-inf 33") == 0);
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
426 ASSERT (retval == strlen (result));
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
427 }
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
428
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
429 { /* NaN. */
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
430 int retval =
9854
baba3b346ab2 Use macros NaNf, NaNd, NaNl instead of NAN.
Bruno Haible <bruno@clisp.org>
parents: 9850
diff changeset
431 my_snprintf (result, sizeof (result), "%La %d", NaNl (), 33, 44, 55);
8850
d1fe16dfbfee Avoid test failures on IRIX 6.5.
Bruno Haible <bruno@clisp.org>
parents: 8839
diff changeset
432 ASSERT (strlen (result) >= 3 + 3
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
433 && strisnan (result, 0, strlen (result) - 3, 0)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
434 && strcmp (result + strlen (result) - 3, " 33") == 0);
8364
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
435 ASSERT (retval == strlen (result));
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
436 }
15906
400649d35651 *printf-posix tests: Fix for platforms where 'long double' == 'double'.
Bruno Haible <bruno@clisp.org>
parents: 15595
diff changeset
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
8919
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8870
diff changeset
438 { /* Quiet NaN. */
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8870
diff changeset
439 static union { unsigned int word[4]; long double value; } x =
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8870
diff changeset
440 { LDBL80_WORDS (0xFFFF, 0xC3333333, 0x00000000) };
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8870
diff changeset
441 int retval =
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8870
diff changeset
442 my_snprintf (result, sizeof (result), "%La %d", x.value, 33, 44, 55);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8870
diff changeset
443 ASSERT (strlen (result) >= 3 + 3
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
444 && strisnan (result, 0, strlen (result) - 3, 0)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
445 && strcmp (result + strlen (result) - 3, " 33") == 0);
8919
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8870
diff changeset
446 ASSERT (retval == strlen (result));
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8870
diff changeset
447 }
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8870
diff changeset
448 {
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8870
diff changeset
449 /* Signalling NaN. */
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8870
diff changeset
450 static union { unsigned int word[4]; long double value; } x =
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8870
diff changeset
451 { LDBL80_WORDS (0xFFFF, 0x83333333, 0x00000000) };
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8870
diff changeset
452 int retval =
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8870
diff changeset
453 my_snprintf (result, sizeof (result), "%La %d", x.value, 33, 44, 55);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8870
diff changeset
454 ASSERT (strlen (result) >= 3 + 3
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
455 && strisnan (result, 0, strlen (result) - 3, 0)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
456 && strcmp (result + strlen (result) - 3, " 33") == 0);
8919
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8870
diff changeset
457 ASSERT (retval == strlen (result));
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8870
diff changeset
458 }
17927
b941bb9e9efb printf, isinf, etc.: noncanonical != NaN
Paul Eggert <eggert@cs.ucla.edu>
parents: 17848
diff changeset
459 /* snprintf should print something for noncanonical values. */
b941bb9e9efb printf, isinf, etc.: noncanonical != NaN
Paul Eggert <eggert@cs.ucla.edu>
parents: 17848
diff changeset
460 { /* Pseudo-NaN. */
b941bb9e9efb printf, isinf, etc.: noncanonical != NaN
Paul Eggert <eggert@cs.ucla.edu>
parents: 17848
diff changeset
461 static union { unsigned int word[4]; long double value; } x =
b941bb9e9efb printf, isinf, etc.: noncanonical != NaN
Paul Eggert <eggert@cs.ucla.edu>
parents: 17848
diff changeset
462 { LDBL80_WORDS (0xFFFF, 0x40000001, 0x00000000) };
b941bb9e9efb printf, isinf, etc.: noncanonical != NaN
Paul Eggert <eggert@cs.ucla.edu>
parents: 17848
diff changeset
463 int retval =
b941bb9e9efb printf, isinf, etc.: noncanonical != NaN
Paul Eggert <eggert@cs.ucla.edu>
parents: 17848
diff changeset
464 my_snprintf (result, sizeof (result), "%La %d", x.value, 33, 44, 55);
b941bb9e9efb printf, isinf, etc.: noncanonical != NaN
Paul Eggert <eggert@cs.ucla.edu>
parents: 17848
diff changeset
465 ASSERT (retval == strlen (result));
b941bb9e9efb printf, isinf, etc.: noncanonical != NaN
Paul Eggert <eggert@cs.ucla.edu>
parents: 17848
diff changeset
466 ASSERT (3 < retval && strcmp (result + retval - 3, " 33") == 0);
b941bb9e9efb printf, isinf, etc.: noncanonical != NaN
Paul Eggert <eggert@cs.ucla.edu>
parents: 17848
diff changeset
467 }
b941bb9e9efb printf, isinf, etc.: noncanonical != NaN
Paul Eggert <eggert@cs.ucla.edu>
parents: 17848
diff changeset
468 { /* Pseudo-Infinity. */
b941bb9e9efb printf, isinf, etc.: noncanonical != NaN
Paul Eggert <eggert@cs.ucla.edu>
parents: 17848
diff changeset
469 static union { unsigned int word[4]; long double value; } x =
b941bb9e9efb printf, isinf, etc.: noncanonical != NaN
Paul Eggert <eggert@cs.ucla.edu>
parents: 17848
diff changeset
470 { LDBL80_WORDS (0xFFFF, 0x00000000, 0x00000000) };
b941bb9e9efb printf, isinf, etc.: noncanonical != NaN
Paul Eggert <eggert@cs.ucla.edu>
parents: 17848
diff changeset
471 int retval =
b941bb9e9efb printf, isinf, etc.: noncanonical != NaN
Paul Eggert <eggert@cs.ucla.edu>
parents: 17848
diff changeset
472 my_snprintf (result, sizeof (result), "%La %d", x.value, 33, 44, 55);
b941bb9e9efb printf, isinf, etc.: noncanonical != NaN
Paul Eggert <eggert@cs.ucla.edu>
parents: 17848
diff changeset
473 ASSERT (retval == strlen (result));
b941bb9e9efb printf, isinf, etc.: noncanonical != NaN
Paul Eggert <eggert@cs.ucla.edu>
parents: 17848
diff changeset
474 ASSERT (3 < retval && strcmp (result + retval - 3, " 33") == 0);
b941bb9e9efb printf, isinf, etc.: noncanonical != NaN
Paul Eggert <eggert@cs.ucla.edu>
parents: 17848
diff changeset
475 }
8919
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8870
diff changeset
476 { /* Pseudo-Zero. */
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8870
diff changeset
477 static union { unsigned int word[4]; long double value; } x =
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8870
diff changeset
478 { LDBL80_WORDS (0x4004, 0x00000000, 0x00000000) };
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8870
diff changeset
479 int retval =
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8870
diff changeset
480 my_snprintf (result, sizeof (result), "%La %d", x.value, 33, 44, 55);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8870
diff changeset
481 ASSERT (retval == strlen (result));
17927
b941bb9e9efb printf, isinf, etc.: noncanonical != NaN
Paul Eggert <eggert@cs.ucla.edu>
parents: 17848
diff changeset
482 ASSERT (3 < retval && strcmp (result + retval - 3, " 33") == 0);
8919
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8870
diff changeset
483 }
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8870
diff changeset
484 { /* Unnormalized number. */
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8870
diff changeset
485 static union { unsigned int word[4]; long double value; } x =
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8870
diff changeset
486 { LDBL80_WORDS (0x4000, 0x63333333, 0x00000000) };
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8870
diff changeset
487 int retval =
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8870
diff changeset
488 my_snprintf (result, sizeof (result), "%La %d", x.value, 33, 44, 55);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8870
diff changeset
489 ASSERT (retval == strlen (result));
17927
b941bb9e9efb printf, isinf, etc.: noncanonical != NaN
Paul Eggert <eggert@cs.ucla.edu>
parents: 17848
diff changeset
490 ASSERT (3 < retval && strcmp (result + retval - 3, " 33") == 0);
8919
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8870
diff changeset
491 }
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8870
diff changeset
492 { /* Pseudo-Denormal. */
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8870
diff changeset
493 static union { unsigned int word[4]; long double value; } x =
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8870
diff changeset
494 { LDBL80_WORDS (0x0000, 0x83333333, 0x00000000) };
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8870
diff changeset
495 int retval =
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8870
diff changeset
496 my_snprintf (result, sizeof (result), "%La %d", x.value, 33, 44, 55);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8870
diff changeset
497 ASSERT (retval == strlen (result));
17927
b941bb9e9efb printf, isinf, etc.: noncanonical != NaN
Paul Eggert <eggert@cs.ucla.edu>
parents: 17848
diff changeset
498 ASSERT (3 < retval && strcmp (result + retval - 3, " 33") == 0);
8919
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8870
diff changeset
499 }
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8870
diff changeset
500 #endif
8364
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
501
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
502 { /* Rounding near the decimal point. */
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
503 int retval =
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
504 my_snprintf (result, sizeof (result), "%.0La %d", 1.5L, 33, 44, 55);
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
505 ASSERT (strcmp (result, "0x2p+0 33") == 0
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
506 || strcmp (result, "0x3p-1 33") == 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
507 || strcmp (result, "0x6p-2 33") == 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
508 || strcmp (result, "0xcp-3 33") == 0);
8364
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
509 ASSERT (retval == strlen (result));
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
510 }
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
511
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
512 { /* Rounding with precision 0. */
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
513 int retval =
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
514 my_snprintf (result, sizeof (result), "%.0La %d", 1.51L, 33, 44, 55);
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
515 ASSERT (strcmp (result, "0x2p+0 33") == 0
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
516 || strcmp (result, "0x3p-1 33") == 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
517 || strcmp (result, "0x6p-2 33") == 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
518 || strcmp (result, "0xcp-3 33") == 0);
8364
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
519 ASSERT (retval == strlen (result));
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
520 }
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
521
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
522 { /* Rounding with precision 1. */
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
523 int retval =
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
524 my_snprintf (result, sizeof (result), "%.1La %d", 1.51L, 33, 44, 55);
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
525 ASSERT (strcmp (result, "0x1.8p+0 33") == 0
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
526 || strcmp (result, "0x3.0p-1 33") == 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
527 || strcmp (result, "0x6.1p-2 33") == 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
528 || strcmp (result, "0xc.1p-3 33") == 0);
8364
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
529 ASSERT (retval == strlen (result));
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
530 }
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
531
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
532 { /* Rounding with precision 2. */
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
533 int retval =
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
534 my_snprintf (result, sizeof (result), "%.2La %d", 1.51L, 33, 44, 55);
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
535 ASSERT (strcmp (result, "0x1.83p+0 33") == 0
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
536 || strcmp (result, "0x3.05p-1 33") == 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
537 || strcmp (result, "0x6.0ap-2 33") == 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
538 || strcmp (result, "0xc.14p-3 33") == 0);
8364
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
539 ASSERT (retval == strlen (result));
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
540 }
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
541
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
542 { /* Rounding with precision 3. */
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
543 int retval =
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
544 my_snprintf (result, sizeof (result), "%.3La %d", 1.51L, 33, 44, 55);
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
545 ASSERT (strcmp (result, "0x1.829p+0 33") == 0
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
546 || strcmp (result, "0x3.052p-1 33") == 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
547 || strcmp (result, "0x6.0a4p-2 33") == 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
548 || strcmp (result, "0xc.148p-3 33") == 0);
8364
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
549 ASSERT (retval == strlen (result));
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
550 }
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
551
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
552 { /* Rounding can turn a ...FFF into a ...000. */
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
553 int retval =
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
554 my_snprintf (result, sizeof (result), "%.3La %d", 1.49999L, 33, 44, 55);
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
555 ASSERT (strcmp (result, "0x1.800p+0 33") == 0
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
556 || strcmp (result, "0x3.000p-1 33") == 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
557 || strcmp (result, "0x6.000p-2 33") == 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
558 || strcmp (result, "0xc.000p-3 33") == 0);
8364
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
559 ASSERT (retval == strlen (result));
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
560 }
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
561
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
562 { /* Rounding can turn a ...FFF into a ...000.
16935
498a2211d839 Write "Mac OS X" instead of "MacOS X".
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
563 This shows a Mac OS X 10.3.9 (Darwin 7.9) bug and a
19192
d86e08b1f555 all: Replace many more http URLs by https URLs. Update stale URLs.
Bruno Haible <bruno@clisp.org>
parents: 19190
diff changeset
564 glibc 2.4 bug <https://sourceware.org/bugzilla/show_bug.cgi?id=2908>. */
8364
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
565 int retval =
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
566 my_snprintf (result, sizeof (result), "%.1La %d", 1.999L, 33, 44, 55);
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
567 ASSERT (strcmp (result, "0x1.0p+1 33") == 0
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
568 || strcmp (result, "0x2.0p+0 33") == 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
569 || strcmp (result, "0x4.0p-1 33") == 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
570 || strcmp (result, "0x8.0p-2 33") == 0);
8364
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
571 ASSERT (retval == strlen (result));
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
572 }
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
573
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
574 { /* Width. */
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
575 int retval =
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
576 my_snprintf (result, sizeof (result), "%10La %d", 1.75L, 33, 44, 55);
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
577 ASSERT (strcmp (result, " 0x1.cp+0 33") == 0
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
578 || strcmp (result, " 0x3.8p-1 33") == 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
579 || strcmp (result, " 0x7p-2 33") == 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
580 || strcmp (result, " 0xep-3 33") == 0);
8364
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
581 ASSERT (retval == strlen (result));
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
582 }
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
583
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
584 { /* Small precision. */
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
585 int retval =
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
586 my_snprintf (result, sizeof (result), "%.10La %d", 1.75L, 33, 44, 55);
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
587 ASSERT (strcmp (result, "0x1.c000000000p+0 33") == 0
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
588 || strcmp (result, "0x3.8000000000p-1 33") == 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
589 || strcmp (result, "0x7.0000000000p-2 33") == 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
590 || strcmp (result, "0xe.0000000000p-3 33") == 0);
8364
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
591 ASSERT (retval == strlen (result));
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
592 }
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
593
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
594 { /* Large precision. */
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
595 int retval =
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
596 my_snprintf (result, sizeof (result), "%.50La %d", 1.75L, 33, 44, 55);
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
597 ASSERT (strcmp (result, "0x1.c0000000000000000000000000000000000000000000000000p+0 33") == 0
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
598 || strcmp (result, "0x3.80000000000000000000000000000000000000000000000000p-1 33") == 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
599 || strcmp (result, "0x7.00000000000000000000000000000000000000000000000000p-2 33") == 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
600 || strcmp (result, "0xe.00000000000000000000000000000000000000000000000000p-3 33") == 0);
8364
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
601 ASSERT (retval == strlen (result));
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
602 }
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
603
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
604 { /* FLAG_LEFT. */
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
605 int retval =
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
606 my_snprintf (result, sizeof (result), "%-10La %d", 1.75L, 33, 44, 55);
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
607 ASSERT (strcmp (result, "0x1.cp+0 33") == 0
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
608 || strcmp (result, "0x3.8p-1 33") == 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
609 || strcmp (result, "0x7p-2 33") == 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
610 || strcmp (result, "0xep-3 33") == 0);
8364
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
611 ASSERT (retval == strlen (result));
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
612 }
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
613
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
614 { /* FLAG_SHOWSIGN. */
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
615 int retval =
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
616 my_snprintf (result, sizeof (result), "%+La %d", 1.75L, 33, 44, 55);
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
617 ASSERT (strcmp (result, "+0x1.cp+0 33") == 0
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
618 || strcmp (result, "+0x3.8p-1 33") == 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
619 || strcmp (result, "+0x7p-2 33") == 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
620 || strcmp (result, "+0xep-3 33") == 0);
8364
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
621 ASSERT (retval == strlen (result));
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
622 }
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
623
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
624 { /* FLAG_SPACE. */
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
625 int retval =
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
626 my_snprintf (result, sizeof (result), "% La %d", 1.75L, 33, 44, 55);
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
627 ASSERT (strcmp (result, " 0x1.cp+0 33") == 0
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
628 || strcmp (result, " 0x3.8p-1 33") == 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
629 || strcmp (result, " 0x7p-2 33") == 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
630 || strcmp (result, " 0xep-3 33") == 0);
8364
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
631 ASSERT (retval == strlen (result));
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
632 }
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
633
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
634 { /* FLAG_ALT. */
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
635 int retval =
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
636 my_snprintf (result, sizeof (result), "%#La %d", 1.75L, 33, 44, 55);
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
637 ASSERT (strcmp (result, "0x1.cp+0 33") == 0
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
638 || strcmp (result, "0x3.8p-1 33") == 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
639 || strcmp (result, "0x7.p-2 33") == 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
640 || strcmp (result, "0xe.p-3 33") == 0);
8364
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
641 ASSERT (retval == strlen (result));
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
642 }
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
643
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
644 { /* FLAG_ALT. */
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
645 int retval =
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
646 my_snprintf (result, sizeof (result), "%#La %d", 1.0L, 33, 44, 55);
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
647 ASSERT (strcmp (result, "0x1.p+0 33") == 0
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
648 || strcmp (result, "0x2.p-1 33") == 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
649 || strcmp (result, "0x4.p-2 33") == 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
650 || strcmp (result, "0x8.p-3 33") == 0);
8364
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
651 ASSERT (retval == strlen (result));
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
652 }
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
653
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
654 { /* FLAG_ZERO with finite number. */
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
655 int retval =
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
656 my_snprintf (result, sizeof (result), "%010La %d", 1.75L, 33, 44, 55);
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
657 ASSERT (strcmp (result, "0x001.cp+0 33") == 0
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
658 || strcmp (result, "0x003.8p-1 33") == 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
659 || strcmp (result, "0x00007p-2 33") == 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
660 || strcmp (result, "0x0000ep-3 33") == 0);
8364
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
661 ASSERT (retval == strlen (result));
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
662 }
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
663
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
664 { /* FLAG_ZERO with infinite number. */
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
665 int retval =
15595
328819af1c02 Support for MSVC compiler: Avoid division by a literal 0.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
666 my_snprintf (result, sizeof (result), "%010La %d", Infinityl (), 33, 44, 55);
8662
023aa5c883a7 Guard against FreeBSD 6.1 bug.
Bruno Haible <bruno@clisp.org>
parents: 8648
diff changeset
667 /* "0000000inf 33" is not a valid result; see
19439
8bfc20b57265 maint: shorten https://lists.gnu.org/archive/html/... links
Jim Meyering <meyering@fb.com>
parents: 19192
diff changeset
668 <https://lists.gnu.org/r/bug-gnulib/2007-04/msg00107.html> */
8662
023aa5c883a7 Guard against FreeBSD 6.1 bug.
Bruno Haible <bruno@clisp.org>
parents: 8648
diff changeset
669 ASSERT (strcmp (result, " inf 33") == 0);
8364
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
670 ASSERT (retval == strlen (result));
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
671 }
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
672
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
673 { /* FLAG_ZERO with NaN. */
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
674 int retval =
9854
baba3b346ab2 Use macros NaNf, NaNd, NaNl instead of NAN.
Bruno Haible <bruno@clisp.org>
parents: 9850
diff changeset
675 my_snprintf (result, sizeof (result), "%050La %d", NaNl (), 33, 44, 55);
8662
023aa5c883a7 Guard against FreeBSD 6.1 bug.
Bruno Haible <bruno@clisp.org>
parents: 8648
diff changeset
676 /* "0000000nan 33" is not a valid result; see
19439
8bfc20b57265 maint: shorten https://lists.gnu.org/archive/html/... links
Jim Meyering <meyering@fb.com>
parents: 19192
diff changeset
677 <https://lists.gnu.org/r/bug-gnulib/2007-04/msg00107.html> */
8870
4e1f2ea486b4 Allow for a longer printed representation of NaN.
Bruno Haible <bruno@clisp.org>
parents: 8865
diff changeset
678 ASSERT (strlen (result) == 50 + 3
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
679 && strisnan (result, strspn (result, " "), strlen (result) - 3, 0)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
680 && strcmp (result + strlen (result) - 3, " 33") == 0);
8364
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
681 ASSERT (retval == strlen (result));
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
682 }
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
683
8684
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
684 /* Test the support of the %f format directive. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
685
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
686 { /* A positive number. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
687 int retval =
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
688 my_snprintf (result, sizeof (result), "%f %d", 12.75, 33, 44, 55);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
689 ASSERT (strcmp (result, "12.750000 33") == 0);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
690 ASSERT (retval == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
691 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
692
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
693 { /* A larger positive number. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
694 int retval =
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
695 my_snprintf (result, sizeof (result), "%f %d", 1234567.0, 33, 44, 55);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
696 ASSERT (strcmp (result, "1234567.000000 33") == 0);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
697 ASSERT (retval == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
698 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
699
8834
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
700 { /* Small and large positive numbers. */
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
701 static struct { double value; const char *string; } data[] =
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
702 {
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
703 { 1.234321234321234e-37, "0.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
704 { 1.234321234321234e-36, "0.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
705 { 1.234321234321234e-35, "0.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
706 { 1.234321234321234e-34, "0.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
707 { 1.234321234321234e-33, "0.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
708 { 1.234321234321234e-32, "0.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
709 { 1.234321234321234e-31, "0.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
710 { 1.234321234321234e-30, "0.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
711 { 1.234321234321234e-29, "0.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
712 { 1.234321234321234e-28, "0.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
713 { 1.234321234321234e-27, "0.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
714 { 1.234321234321234e-26, "0.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
715 { 1.234321234321234e-25, "0.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
716 { 1.234321234321234e-24, "0.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
717 { 1.234321234321234e-23, "0.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
718 { 1.234321234321234e-22, "0.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
719 { 1.234321234321234e-21, "0.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
720 { 1.234321234321234e-20, "0.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
721 { 1.234321234321234e-19, "0.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
722 { 1.234321234321234e-18, "0.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
723 { 1.234321234321234e-17, "0.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
724 { 1.234321234321234e-16, "0.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
725 { 1.234321234321234e-15, "0.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
726 { 1.234321234321234e-14, "0.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
727 { 1.234321234321234e-13, "0.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
728 { 1.234321234321234e-12, "0.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
729 { 1.234321234321234e-11, "0.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
730 { 1.234321234321234e-10, "0.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
731 { 1.234321234321234e-9, "0.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
732 { 1.234321234321234e-8, "0.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
733 { 1.234321234321234e-7, "0.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
734 { 1.234321234321234e-6, "0.000001" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
735 { 1.234321234321234e-5, "0.000012" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
736 { 1.234321234321234e-4, "0.000123" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
737 { 1.234321234321234e-3, "0.001234" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
738 { 1.234321234321234e-2, "0.012343" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
739 { 1.234321234321234e-1, "0.123432" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
740 { 1.234321234321234, "1.234321" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
741 { 1.234321234321234e1, "12.343212" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
742 { 1.234321234321234e2, "123.432123" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
743 { 1.234321234321234e3, "1234.321234" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
744 { 1.234321234321234e4, "12343.212343" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
745 { 1.234321234321234e5, "123432.123432" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
746 { 1.234321234321234e6, "1234321.234321" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
747 { 1.234321234321234e7, "12343212.343212" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
748 { 1.234321234321234e8, "123432123.432123" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
749 { 1.234321234321234e9, "1234321234.321234" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
750 { 1.234321234321234e10, "12343212343.2123**" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
751 { 1.234321234321234e11, "123432123432.123***" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
752 { 1.234321234321234e12, "1234321234321.23****" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
753 { 1.234321234321234e13, "12343212343212.3*****" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
754 { 1.234321234321234e14, "123432123432123.******" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
755 { 1.234321234321234e15, "1234321234321234.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
756 { 1.234321234321234e16, "123432123432123**.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
757 { 1.234321234321234e17, "123432123432123***.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
758 { 1.234321234321234e18, "123432123432123****.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
759 { 1.234321234321234e19, "123432123432123*****.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
760 { 1.234321234321234e20, "123432123432123******.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
761 { 1.234321234321234e21, "123432123432123*******.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
762 { 1.234321234321234e22, "123432123432123********.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
763 { 1.234321234321234e23, "123432123432123*********.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
764 { 1.234321234321234e24, "123432123432123**********.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
765 { 1.234321234321234e25, "123432123432123***********.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
766 { 1.234321234321234e26, "123432123432123************.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
767 { 1.234321234321234e27, "123432123432123*************.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
768 { 1.234321234321234e28, "123432123432123**************.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
769 { 1.234321234321234e29, "123432123432123***************.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
770 { 1.234321234321234e30, "123432123432123****************.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
771 { 1.234321234321234e31, "123432123432123*****************.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
772 { 1.234321234321234e32, "123432123432123******************.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
773 { 1.234321234321234e33, "123432123432123*******************.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
774 { 1.234321234321234e34, "123432123432123********************.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
775 { 1.234321234321234e35, "123432123432123*********************.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
776 { 1.234321234321234e36, "123432123432123**********************.000000" }
8834
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
777 };
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
778 size_t k;
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
779 for (k = 0; k < SIZEOF (data); k++)
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
780 {
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
781 int retval =
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
782 my_snprintf (result, sizeof (result), "%f", data[k].value);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
783 ASSERT (strmatch (data[k].string, result));
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
784 ASSERT (retval == strlen (result));
8834
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
785 }
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
786 }
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
787
8684
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
788 { /* A negative number. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
789 int retval =
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
790 my_snprintf (result, sizeof (result), "%f %d", -0.03125, 33, 44, 55);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
791 ASSERT (strcmp (result, "-0.031250 33") == 0);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
792 ASSERT (retval == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
793 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
794
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
795 { /* Positive zero. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
796 int retval =
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
797 my_snprintf (result, sizeof (result), "%f %d", 0.0, 33, 44, 55);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
798 ASSERT (strcmp (result, "0.000000 33") == 0);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
799 ASSERT (retval == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
800 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
801
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
802 { /* Negative zero. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
803 int retval =
13834
108bbfd6f03b frexp, tests: work around ICC bug with -zero
Eric Blake <eblake@redhat.com>
parents: 12559
diff changeset
804 my_snprintf (result, sizeof (result), "%f %d", minus_zerod, 33, 44, 55);
8852
df0b5e8ea770 Avoid test failures on platforms where -0.0 and 0.0 are identical.
Bruno Haible <bruno@clisp.org>
parents: 8850
diff changeset
805 if (have_minus_zero ())
df0b5e8ea770 Avoid test failures on platforms where -0.0 and 0.0 are identical.
Bruno Haible <bruno@clisp.org>
parents: 8850
diff changeset
806 ASSERT (strcmp (result, "-0.000000 33") == 0);
8684
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
807 ASSERT (retval == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
808 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
809
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
810 { /* Positive infinity. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
811 int retval =
15595
328819af1c02 Support for MSVC compiler: Avoid division by a literal 0.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
812 my_snprintf (result, sizeof (result), "%f %d", Infinityd (), 33, 44, 55);
8684
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
813 ASSERT (strcmp (result, "inf 33") == 0
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
814 || strcmp (result, "infinity 33") == 0);
8684
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
815 ASSERT (retval == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
816 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
817
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
818 { /* Negative infinity. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
819 int retval =
15595
328819af1c02 Support for MSVC compiler: Avoid division by a literal 0.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
820 my_snprintf (result, sizeof (result), "%f %d", - Infinityd (), 33, 44, 55);
8684
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
821 ASSERT (strcmp (result, "-inf 33") == 0
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
822 || strcmp (result, "-infinity 33") == 0);
8684
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
823 ASSERT (retval == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
824 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
825
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
826 { /* NaN. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
827 int retval =
9854
baba3b346ab2 Use macros NaNf, NaNd, NaNl instead of NAN.
Bruno Haible <bruno@clisp.org>
parents: 9850
diff changeset
828 my_snprintf (result, sizeof (result), "%f %d", NaNd (), 33, 44, 55);
8850
d1fe16dfbfee Avoid test failures on IRIX 6.5.
Bruno Haible <bruno@clisp.org>
parents: 8839
diff changeset
829 ASSERT (strlen (result) >= 3 + 3
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
830 && strisnan (result, 0, strlen (result) - 3, 0)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
831 && strcmp (result + strlen (result) - 3, " 33") == 0);
8684
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
832 ASSERT (retval == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
833 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
834
8804
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
835 { /* Width. */
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
836 int retval =
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
837 my_snprintf (result, sizeof (result), "%10f %d", 1.75, 33, 44, 55);
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
838 ASSERT (strcmp (result, " 1.750000 33") == 0);
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
839 ASSERT (retval == strlen (result));
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
840 }
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
841
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
842 { /* FLAG_LEFT. */
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
843 int retval =
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
844 my_snprintf (result, sizeof (result), "%-10f %d", 1.75, 33, 44, 55);
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
845 ASSERT (strcmp (result, "1.750000 33") == 0);
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
846 ASSERT (retval == strlen (result));
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
847 }
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
848
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
849 { /* FLAG_SHOWSIGN. */
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
850 int retval =
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
851 my_snprintf (result, sizeof (result), "%+f %d", 1.75, 33, 44, 55);
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
852 ASSERT (strcmp (result, "+1.750000 33") == 0);
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
853 ASSERT (retval == strlen (result));
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
854 }
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
855
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
856 { /* FLAG_SPACE. */
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
857 int retval =
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
858 my_snprintf (result, sizeof (result), "% f %d", 1.75, 33, 44, 55);
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
859 ASSERT (strcmp (result, " 1.750000 33") == 0);
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
860 ASSERT (retval == strlen (result));
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
861 }
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
862
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
863 { /* FLAG_ALT. */
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
864 int retval =
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
865 my_snprintf (result, sizeof (result), "%#f %d", 1.75, 33, 44, 55);
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
866 ASSERT (strcmp (result, "1.750000 33") == 0);
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
867 ASSERT (retval == strlen (result));
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
868 }
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
869
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
870 { /* FLAG_ALT. */
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
871 int retval =
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
872 my_snprintf (result, sizeof (result), "%#.f %d", 1.75, 33, 44, 55);
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
873 ASSERT (strcmp (result, "2. 33") == 0);
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
874 ASSERT (retval == strlen (result));
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
875 }
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
876
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
877 { /* FLAG_ZERO with finite number. */
8684
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
878 int retval =
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
879 my_snprintf (result, sizeof (result), "%015f %d", 1234.0, 33, 44, 55);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
880 ASSERT (strcmp (result, "00001234.000000 33") == 0);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
881 ASSERT (retval == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
882 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
883
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
884 { /* FLAG_ZERO with infinite number. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
885 int retval =
15595
328819af1c02 Support for MSVC compiler: Avoid division by a literal 0.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
886 my_snprintf (result, sizeof (result), "%015f %d", - Infinityd (), 33, 44, 55);
8684
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
887 ASSERT (strcmp (result, " -inf 33") == 0
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
888 || strcmp (result, " -infinity 33") == 0);
8684
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
889 ASSERT (retval == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
890 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
891
8804
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
892 { /* FLAG_ZERO with NaN. */
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
893 int retval =
9854
baba3b346ab2 Use macros NaNf, NaNd, NaNl instead of NAN.
Bruno Haible <bruno@clisp.org>
parents: 9850
diff changeset
894 my_snprintf (result, sizeof (result), "%050f %d", NaNd (), 33, 44, 55);
8870
4e1f2ea486b4 Allow for a longer printed representation of NaN.
Bruno Haible <bruno@clisp.org>
parents: 8865
diff changeset
895 ASSERT (strlen (result) == 50 + 3
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
896 && strisnan (result, strspn (result, " "), strlen (result) - 3, 0)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
897 && strcmp (result + strlen (result) - 3, " 33") == 0);
8804
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
898 ASSERT (retval == strlen (result));
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
899 }
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
900
8684
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
901 { /* Precision. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
902 int retval =
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
903 my_snprintf (result, sizeof (result), "%.f %d", 1234.0, 33, 44, 55);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
904 ASSERT (strcmp (result, "1234 33") == 0);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
905 ASSERT (retval == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
906 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
907
9938
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9854
diff changeset
908 { /* Precision with no rounding. */
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9854
diff changeset
909 int retval =
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9854
diff changeset
910 my_snprintf (result, sizeof (result), "%.2f %d", 999.951, 33, 44, 55);
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9854
diff changeset
911 ASSERT (strcmp (result, "999.95 33") == 0);
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9854
diff changeset
912 ASSERT (retval == strlen (result));
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9854
diff changeset
913 }
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9854
diff changeset
914
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9854
diff changeset
915 { /* Precision with rounding. */
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9854
diff changeset
916 int retval =
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9854
diff changeset
917 my_snprintf (result, sizeof (result), "%.2f %d", 999.996, 33, 44, 55);
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9854
diff changeset
918 ASSERT (strcmp (result, "1000.00 33") == 0);
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9854
diff changeset
919 ASSERT (retval == strlen (result));
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9854
diff changeset
920 }
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9854
diff changeset
921
8684
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
922 { /* A positive number. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
923 int retval =
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
924 my_snprintf (result, sizeof (result), "%Lf %d", 12.75L, 33, 44, 55);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
925 ASSERT (strcmp (result, "12.750000 33") == 0);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
926 ASSERT (retval == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
927 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
928
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
929 { /* A larger positive number. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
930 int retval =
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
931 my_snprintf (result, sizeof (result), "%Lf %d", 1234567.0L, 33, 44, 55);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
932 ASSERT (strcmp (result, "1234567.000000 33") == 0);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
933 ASSERT (retval == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
934 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
935
8834
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
936 { /* Small and large positive numbers. */
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
937 static struct { long double value; const char *string; } data[] =
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
938 {
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
939 { 1.234321234321234e-37L, "0.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
940 { 1.234321234321234e-36L, "0.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
941 { 1.234321234321234e-35L, "0.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
942 { 1.234321234321234e-34L, "0.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
943 { 1.234321234321234e-33L, "0.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
944 { 1.234321234321234e-32L, "0.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
945 { 1.234321234321234e-31L, "0.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
946 { 1.234321234321234e-30L, "0.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
947 { 1.234321234321234e-29L, "0.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
948 { 1.234321234321234e-28L, "0.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
949 { 1.234321234321234e-27L, "0.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
950 { 1.234321234321234e-26L, "0.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
951 { 1.234321234321234e-25L, "0.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
952 { 1.234321234321234e-24L, "0.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
953 { 1.234321234321234e-23L, "0.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
954 { 1.234321234321234e-22L, "0.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
955 { 1.234321234321234e-21L, "0.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
956 { 1.234321234321234e-20L, "0.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
957 { 1.234321234321234e-19L, "0.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
958 { 1.234321234321234e-18L, "0.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
959 { 1.234321234321234e-17L, "0.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
960 { 1.234321234321234e-16L, "0.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
961 { 1.234321234321234e-15L, "0.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
962 { 1.234321234321234e-14L, "0.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
963 { 1.234321234321234e-13L, "0.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
964 { 1.234321234321234e-12L, "0.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
965 { 1.234321234321234e-11L, "0.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
966 { 1.234321234321234e-10L, "0.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
967 { 1.234321234321234e-9L, "0.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
968 { 1.234321234321234e-8L, "0.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
969 { 1.234321234321234e-7L, "0.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
970 { 1.234321234321234e-6L, "0.000001" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
971 { 1.234321234321234e-5L, "0.000012" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
972 { 1.234321234321234e-4L, "0.000123" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
973 { 1.234321234321234e-3L, "0.001234" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
974 { 1.234321234321234e-2L, "0.012343" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
975 { 1.234321234321234e-1L, "0.123432" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
976 { 1.234321234321234L, "1.234321" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
977 { 1.234321234321234e1L, "12.343212" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
978 { 1.234321234321234e2L, "123.432123" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
979 { 1.234321234321234e3L, "1234.321234" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
980 { 1.234321234321234e4L, "12343.212343" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
981 { 1.234321234321234e5L, "123432.123432" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
982 { 1.234321234321234e6L, "1234321.234321" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
983 { 1.234321234321234e7L, "12343212.343212" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
984 { 1.234321234321234e8L, "123432123.432123" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
985 { 1.234321234321234e9L, "1234321234.321234" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
986 { 1.234321234321234e10L, "12343212343.2123**" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
987 { 1.234321234321234e11L, "123432123432.123***" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
988 { 1.234321234321234e12L, "1234321234321.23****" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
989 { 1.234321234321234e13L, "12343212343212.3*****" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
990 { 1.234321234321234e14L, "123432123432123.******" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
991 { 1.234321234321234e15L, "1234321234321234.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
992 { 1.234321234321234e16L, "123432123432123**.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
993 { 1.234321234321234e17L, "123432123432123***.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
994 { 1.234321234321234e18L, "123432123432123****.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
995 { 1.234321234321234e19L, "123432123432123*****.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
996 { 1.234321234321234e20L, "123432123432123******.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
997 { 1.234321234321234e21L, "123432123432123*******.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
998 { 1.234321234321234e22L, "123432123432123********.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
999 { 1.234321234321234e23L, "123432123432123*********.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1000 { 1.234321234321234e24L, "123432123432123**********.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1001 { 1.234321234321234e25L, "123432123432123***********.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1002 { 1.234321234321234e26L, "123432123432123************.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1003 { 1.234321234321234e27L, "123432123432123*************.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1004 { 1.234321234321234e28L, "123432123432123**************.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1005 { 1.234321234321234e29L, "123432123432123***************.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1006 { 1.234321234321234e30L, "123432123432123****************.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1007 { 1.234321234321234e31L, "123432123432123*****************.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1008 { 1.234321234321234e32L, "123432123432123******************.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1009 { 1.234321234321234e33L, "123432123432123*******************.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1010 { 1.234321234321234e34L, "123432123432123********************.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1011 { 1.234321234321234e35L, "123432123432123*********************.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1012 { 1.234321234321234e36L, "123432123432123**********************.000000" }
8834
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1013 };
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1014 size_t k;
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1015 for (k = 0; k < SIZEOF (data); k++)
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1016 {
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1017 int retval =
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1018 my_snprintf (result, sizeof (result), "%Lf", data[k].value);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1019 ASSERT (strmatch (data[k].string, result));
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1020 ASSERT (retval == strlen (result));
8834
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1021 }
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1022 }
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1023
8684
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1024 { /* A negative number. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1025 int retval =
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1026 my_snprintf (result, sizeof (result), "%Lf %d", -0.03125L, 33, 44, 55);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1027 ASSERT (strcmp (result, "-0.031250 33") == 0);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1028 ASSERT (retval == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1029 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1030
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1031 { /* Positive zero. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1032 int retval =
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1033 my_snprintf (result, sizeof (result), "%Lf %d", 0.0L, 33, 44, 55);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1034 ASSERT (strcmp (result, "0.000000 33") == 0);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1035 ASSERT (retval == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1036 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1037
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1038 { /* Negative zero. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1039 int retval =
10601
ca053fa79cd3 Use a more portable replacement expression for -0.0L.
Bruno Haible <bruno@clisp.org>
parents: 10458
diff changeset
1040 my_snprintf (result, sizeof (result), "%Lf %d", minus_zerol, 33, 44, 55);
8852
df0b5e8ea770 Avoid test failures on platforms where -0.0 and 0.0 are identical.
Bruno Haible <bruno@clisp.org>
parents: 8850
diff changeset
1041 if (have_minus_zero ())
df0b5e8ea770 Avoid test failures on platforms where -0.0 and 0.0 are identical.
Bruno Haible <bruno@clisp.org>
parents: 8850
diff changeset
1042 ASSERT (strcmp (result, "-0.000000 33") == 0);
8684
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1043 ASSERT (retval == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1044 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1045
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1046 { /* Positive infinity. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1047 int retval =
15595
328819af1c02 Support for MSVC compiler: Avoid division by a literal 0.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
1048 my_snprintf (result, sizeof (result), "%Lf %d", Infinityl (), 33, 44, 55);
8684
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1049 ASSERT (strcmp (result, "inf 33") == 0
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1050 || strcmp (result, "infinity 33") == 0);
8684
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1051 ASSERT (retval == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1052 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1053
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1054 { /* Negative infinity. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1055 int retval =
15595
328819af1c02 Support for MSVC compiler: Avoid division by a literal 0.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
1056 my_snprintf (result, sizeof (result), "%Lf %d", - Infinityl (), 33, 44, 55);
8684
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1057 ASSERT (strcmp (result, "-inf 33") == 0
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1058 || strcmp (result, "-infinity 33") == 0);
8684
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1059 ASSERT (retval == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1060 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1061
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1062 { /* NaN. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1063 int retval =
9854
baba3b346ab2 Use macros NaNf, NaNd, NaNl instead of NAN.
Bruno Haible <bruno@clisp.org>
parents: 9850
diff changeset
1064 my_snprintf (result, sizeof (result), "%Lf %d", NaNl (), 33, 44, 55);
8850
d1fe16dfbfee Avoid test failures on IRIX 6.5.
Bruno Haible <bruno@clisp.org>
parents: 8839
diff changeset
1065 ASSERT (strlen (result) >= 3 + 3
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1066 && strisnan (result, 0, strlen (result) - 3, 0)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1067 && strcmp (result + strlen (result) - 3, " 33") == 0);
8684
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1068 ASSERT (retval == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1069 }
15906
400649d35651 *printf-posix tests: Fix for platforms where 'long double' == 'double'.
Bruno Haible <bruno@clisp.org>
parents: 15595
diff changeset
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
8919
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8870
diff changeset
1071 { /* Quiet NaN. */
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8870
diff changeset
1072 static union { unsigned int word[4]; long double value; } x =
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8870
diff changeset
1073 { LDBL80_WORDS (0xFFFF, 0xC3333333, 0x00000000) };
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8870
diff changeset
1074 int retval =
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8870
diff changeset
1075 my_snprintf (result, sizeof (result), "%Lf %d", x.value, 33, 44, 55);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8870
diff changeset
1076 ASSERT (strlen (result) >= 3 + 3
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1077 && strisnan (result, 0, strlen (result) - 3, 0)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1078 && strcmp (result + strlen (result) - 3, " 33") == 0);
8919
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8870
diff changeset
1079 ASSERT (retval == strlen (result));
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8870
diff changeset
1080 }
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8870
diff changeset
1081 {
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8870
diff changeset
1082 /* Signalling NaN. */
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8870
diff changeset
1083 static union { unsigned int word[4]; long double value; } x =
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8870
diff changeset
1084 { LDBL80_WORDS (0xFFFF, 0x83333333, 0x00000000) };
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8870
diff changeset
1085 int retval =
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8870
diff changeset
1086 my_snprintf (result, sizeof (result), "%Lf %d", x.value, 33, 44, 55);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8870
diff changeset
1087 ASSERT (strlen (result) >= 3 + 3
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1088 && strisnan (result, 0, strlen (result) - 3, 0)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1089 && strcmp (result + strlen (result) - 3, " 33") == 0);
8919
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8870
diff changeset
1090 ASSERT (retval == strlen (result));
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8870
diff changeset
1091 }
17927
b941bb9e9efb printf, isinf, etc.: noncanonical != NaN
Paul Eggert <eggert@cs.ucla.edu>
parents: 17848
diff changeset
1092 /* snprintf should print something for noncanonical values. */
b941bb9e9efb printf, isinf, etc.: noncanonical != NaN
Paul Eggert <eggert@cs.ucla.edu>
parents: 17848
diff changeset
1093 { /* Pseudo-NaN. */
b941bb9e9efb printf, isinf, etc.: noncanonical != NaN
Paul Eggert <eggert@cs.ucla.edu>
parents: 17848
diff changeset
1094 static union { unsigned int word[4]; long double value; } x =
b941bb9e9efb printf, isinf, etc.: noncanonical != NaN
Paul Eggert <eggert@cs.ucla.edu>
parents: 17848
diff changeset
1095 { LDBL80_WORDS (0xFFFF, 0x40000001, 0x00000000) };
b941bb9e9efb printf, isinf, etc.: noncanonical != NaN
Paul Eggert <eggert@cs.ucla.edu>
parents: 17848
diff changeset
1096 int retval =
b941bb9e9efb printf, isinf, etc.: noncanonical != NaN
Paul Eggert <eggert@cs.ucla.edu>
parents: 17848
diff changeset
1097 my_snprintf (result, sizeof (result), "%Lf %d", x.value, 33, 44, 55);
b941bb9e9efb printf, isinf, etc.: noncanonical != NaN
Paul Eggert <eggert@cs.ucla.edu>
parents: 17848
diff changeset
1098 ASSERT (retval == strlen (result));
b941bb9e9efb printf, isinf, etc.: noncanonical != NaN
Paul Eggert <eggert@cs.ucla.edu>
parents: 17848
diff changeset
1099 ASSERT (3 < retval && strcmp (result + retval - 3, " 33") == 0);
b941bb9e9efb printf, isinf, etc.: noncanonical != NaN
Paul Eggert <eggert@cs.ucla.edu>
parents: 17848
diff changeset
1100 }
b941bb9e9efb printf, isinf, etc.: noncanonical != NaN
Paul Eggert <eggert@cs.ucla.edu>
parents: 17848
diff changeset
1101 { /* Pseudo-Infinity. */
b941bb9e9efb printf, isinf, etc.: noncanonical != NaN
Paul Eggert <eggert@cs.ucla.edu>
parents: 17848
diff changeset
1102 static union { unsigned int word[4]; long double value; } x =
b941bb9e9efb printf, isinf, etc.: noncanonical != NaN
Paul Eggert <eggert@cs.ucla.edu>
parents: 17848
diff changeset
1103 { LDBL80_WORDS (0xFFFF, 0x00000000, 0x00000000) };
b941bb9e9efb printf, isinf, etc.: noncanonical != NaN
Paul Eggert <eggert@cs.ucla.edu>
parents: 17848
diff changeset
1104 int retval =
b941bb9e9efb printf, isinf, etc.: noncanonical != NaN
Paul Eggert <eggert@cs.ucla.edu>
parents: 17848
diff changeset
1105 my_snprintf (result, sizeof (result), "%Lf %d", x.value, 33, 44, 55);
b941bb9e9efb printf, isinf, etc.: noncanonical != NaN
Paul Eggert <eggert@cs.ucla.edu>
parents: 17848
diff changeset
1106 ASSERT (retval == strlen (result));
b941bb9e9efb printf, isinf, etc.: noncanonical != NaN
Paul Eggert <eggert@cs.ucla.edu>
parents: 17848
diff changeset
1107 ASSERT (3 < retval && strcmp (result + retval - 3, " 33") == 0);
b941bb9e9efb printf, isinf, etc.: noncanonical != NaN
Paul Eggert <eggert@cs.ucla.edu>
parents: 17848
diff changeset
1108 }
b941bb9e9efb printf, isinf, etc.: noncanonical != NaN
Paul Eggert <eggert@cs.ucla.edu>
parents: 17848
diff changeset
1109 { /* Pseudo-Zero. */
b941bb9e9efb printf, isinf, etc.: noncanonical != NaN
Paul Eggert <eggert@cs.ucla.edu>
parents: 17848
diff changeset
1110 static union { unsigned int word[4]; long double value; } x =
b941bb9e9efb printf, isinf, etc.: noncanonical != NaN
Paul Eggert <eggert@cs.ucla.edu>
parents: 17848
diff changeset
1111 { LDBL80_WORDS (0x4004, 0x00000000, 0x00000000) };
b941bb9e9efb printf, isinf, etc.: noncanonical != NaN
Paul Eggert <eggert@cs.ucla.edu>
parents: 17848
diff changeset
1112 int retval =
b941bb9e9efb printf, isinf, etc.: noncanonical != NaN
Paul Eggert <eggert@cs.ucla.edu>
parents: 17848
diff changeset
1113 my_snprintf (result, sizeof (result), "%Lf %d", x.value, 33, 44, 55);
b941bb9e9efb printf, isinf, etc.: noncanonical != NaN
Paul Eggert <eggert@cs.ucla.edu>
parents: 17848
diff changeset
1114 ASSERT (retval == strlen (result));
b941bb9e9efb printf, isinf, etc.: noncanonical != NaN
Paul Eggert <eggert@cs.ucla.edu>
parents: 17848
diff changeset
1115 ASSERT (3 < retval && strcmp (result + retval - 3, " 33") == 0);
b941bb9e9efb printf, isinf, etc.: noncanonical != NaN
Paul Eggert <eggert@cs.ucla.edu>
parents: 17848
diff changeset
1116 }
b941bb9e9efb printf, isinf, etc.: noncanonical != NaN
Paul Eggert <eggert@cs.ucla.edu>
parents: 17848
diff changeset
1117 { /* Unnormalized number. */
b941bb9e9efb printf, isinf, etc.: noncanonical != NaN
Paul Eggert <eggert@cs.ucla.edu>
parents: 17848
diff changeset
1118 static union { unsigned int word[4]; long double value; } x =
b941bb9e9efb printf, isinf, etc.: noncanonical != NaN
Paul Eggert <eggert@cs.ucla.edu>
parents: 17848
diff changeset
1119 { LDBL80_WORDS (0x4000, 0x63333333, 0x00000000) };
b941bb9e9efb printf, isinf, etc.: noncanonical != NaN
Paul Eggert <eggert@cs.ucla.edu>
parents: 17848
diff changeset
1120 int retval =
b941bb9e9efb printf, isinf, etc.: noncanonical != NaN
Paul Eggert <eggert@cs.ucla.edu>
parents: 17848
diff changeset
1121 my_snprintf (result, sizeof (result), "%Lf %d", x.value, 33, 44, 55);
b941bb9e9efb printf, isinf, etc.: noncanonical != NaN
Paul Eggert <eggert@cs.ucla.edu>
parents: 17848
diff changeset
1122 ASSERT (retval == strlen (result));
b941bb9e9efb printf, isinf, etc.: noncanonical != NaN
Paul Eggert <eggert@cs.ucla.edu>
parents: 17848
diff changeset
1123 ASSERT (3 < retval && strcmp (result + retval - 3, " 33") == 0);
b941bb9e9efb printf, isinf, etc.: noncanonical != NaN
Paul Eggert <eggert@cs.ucla.edu>
parents: 17848
diff changeset
1124 }
8919
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8870
diff changeset
1125 { /* Pseudo-Denormal. */
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8870
diff changeset
1126 static union { unsigned int word[4]; long double value; } x =
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8870
diff changeset
1127 { LDBL80_WORDS (0x0000, 0x83333333, 0x00000000) };
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8870
diff changeset
1128 int retval =
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8870
diff changeset
1129 my_snprintf (result, sizeof (result), "%Lf %d", x.value, 33, 44, 55);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8870
diff changeset
1130 ASSERT (retval == strlen (result));
17927
b941bb9e9efb printf, isinf, etc.: noncanonical != NaN
Paul Eggert <eggert@cs.ucla.edu>
parents: 17848
diff changeset
1131 ASSERT (3 < retval && strcmp (result + retval - 3, " 33") == 0);
8919
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8870
diff changeset
1132 }
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8870
diff changeset
1133 #endif
8684
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1134
8804
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1135 { /* Width. */
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1136 int retval =
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1137 my_snprintf (result, sizeof (result), "%10Lf %d", 1.75L, 33, 44, 55);
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1138 ASSERT (strcmp (result, " 1.750000 33") == 0);
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1139 ASSERT (retval == strlen (result));
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1140 }
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1141
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1142 { /* FLAG_LEFT. */
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1143 int retval =
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1144 my_snprintf (result, sizeof (result), "%-10Lf %d", 1.75L, 33, 44, 55);
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1145 ASSERT (strcmp (result, "1.750000 33") == 0);
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1146 ASSERT (retval == strlen (result));
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1147 }
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1148
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1149 { /* FLAG_SHOWSIGN. */
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1150 int retval =
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1151 my_snprintf (result, sizeof (result), "%+Lf %d", 1.75L, 33, 44, 55);
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1152 ASSERT (strcmp (result, "+1.750000 33") == 0);
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1153 ASSERT (retval == strlen (result));
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1154 }
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1155
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1156 { /* FLAG_SPACE. */
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1157 int retval =
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1158 my_snprintf (result, sizeof (result), "% Lf %d", 1.75L, 33, 44, 55);
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1159 ASSERT (strcmp (result, " 1.750000 33") == 0);
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1160 ASSERT (retval == strlen (result));
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1161 }
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1162
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1163 { /* FLAG_ALT. */
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1164 int retval =
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1165 my_snprintf (result, sizeof (result), "%#Lf %d", 1.75L, 33, 44, 55);
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1166 ASSERT (strcmp (result, "1.750000 33") == 0);
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1167 ASSERT (retval == strlen (result));
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1168 }
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1169
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1170 { /* FLAG_ALT. */
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1171 int retval =
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1172 my_snprintf (result, sizeof (result), "%#.Lf %d", 1.75L, 33, 44, 55);
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1173 ASSERT (strcmp (result, "2. 33") == 0);
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1174 ASSERT (retval == strlen (result));
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1175 }
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1176
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1177 { /* FLAG_ZERO with finite number. */
8684
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1178 int retval =
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1179 my_snprintf (result, sizeof (result), "%015Lf %d", 1234.0L, 33, 44, 55);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1180 ASSERT (strcmp (result, "00001234.000000 33") == 0);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1181 ASSERT (retval == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1182 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1183
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1184 { /* FLAG_ZERO with infinite number. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1185 int retval =
15595
328819af1c02 Support for MSVC compiler: Avoid division by a literal 0.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
1186 my_snprintf (result, sizeof (result), "%015Lf %d", - Infinityl (), 33, 44, 55);
8684
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1187 ASSERT (strcmp (result, " -inf 33") == 0
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1188 || strcmp (result, " -infinity 33") == 0);
8684
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1189 ASSERT (retval == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1190 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1191
8804
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1192 { /* FLAG_ZERO with NaN. */
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1193 int retval =
9854
baba3b346ab2 Use macros NaNf, NaNd, NaNl instead of NAN.
Bruno Haible <bruno@clisp.org>
parents: 9850
diff changeset
1194 my_snprintf (result, sizeof (result), "%050Lf %d", NaNl (), 33, 44, 55);
8870
4e1f2ea486b4 Allow for a longer printed representation of NaN.
Bruno Haible <bruno@clisp.org>
parents: 8865
diff changeset
1195 ASSERT (strlen (result) == 50 + 3
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1196 && strisnan (result, strspn (result, " "), strlen (result) - 3, 0)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1197 && strcmp (result + strlen (result) - 3, " 33") == 0);
8804
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1198 ASSERT (retval == strlen (result));
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1199 }
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1200
8684
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1201 { /* Precision. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1202 int retval =
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1203 my_snprintf (result, sizeof (result), "%.Lf %d", 1234.0L, 33, 44, 55);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1204 ASSERT (strcmp (result, "1234 33") == 0);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1205 ASSERT (retval == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1206 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1207
9938
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9854
diff changeset
1208 { /* Precision with no rounding. */
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9854
diff changeset
1209 int retval =
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9854
diff changeset
1210 my_snprintf (result, sizeof (result), "%.2Lf %d", 999.951L, 33, 44, 55);
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9854
diff changeset
1211 ASSERT (strcmp (result, "999.95 33") == 0);
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9854
diff changeset
1212 ASSERT (retval == strlen (result));
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9854
diff changeset
1213 }
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9854
diff changeset
1214
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9854
diff changeset
1215 { /* Precision with rounding. */
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9854
diff changeset
1216 int retval =
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9854
diff changeset
1217 my_snprintf (result, sizeof (result), "%.2Lf %d", 999.996L, 33, 44, 55);
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9854
diff changeset
1218 ASSERT (strcmp (result, "1000.00 33") == 0);
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9854
diff changeset
1219 ASSERT (retval == strlen (result));
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9854
diff changeset
1220 }
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9854
diff changeset
1221
8684
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1222 /* Test the support of the %F format directive. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1223
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1224 { /* A positive number. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1225 int retval =
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1226 my_snprintf (result, sizeof (result), "%F %d", 12.75, 33, 44, 55);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1227 ASSERT (strcmp (result, "12.750000 33") == 0);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1228 ASSERT (retval == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1229 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1230
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1231 { /* A larger positive number. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1232 int retval =
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1233 my_snprintf (result, sizeof (result), "%F %d", 1234567.0, 33, 44, 55);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1234 ASSERT (strcmp (result, "1234567.000000 33") == 0);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1235 ASSERT (retval == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1236 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1237
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1238 { /* A negative number. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1239 int retval =
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1240 my_snprintf (result, sizeof (result), "%F %d", -0.03125, 33, 44, 55);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1241 ASSERT (strcmp (result, "-0.031250 33") == 0);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1242 ASSERT (retval == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1243 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1244
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1245 { /* Positive zero. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1246 int retval =
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1247 my_snprintf (result, sizeof (result), "%F %d", 0.0, 33, 44, 55);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1248 ASSERT (strcmp (result, "0.000000 33") == 0);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1249 ASSERT (retval == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1250 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1251
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1252 { /* Negative zero. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1253 int retval =
13834
108bbfd6f03b frexp, tests: work around ICC bug with -zero
Eric Blake <eblake@redhat.com>
parents: 12559
diff changeset
1254 my_snprintf (result, sizeof (result), "%F %d", minus_zerod, 33, 44, 55);
8852
df0b5e8ea770 Avoid test failures on platforms where -0.0 and 0.0 are identical.
Bruno Haible <bruno@clisp.org>
parents: 8850
diff changeset
1255 if (have_minus_zero ())
df0b5e8ea770 Avoid test failures on platforms where -0.0 and 0.0 are identical.
Bruno Haible <bruno@clisp.org>
parents: 8850
diff changeset
1256 ASSERT (strcmp (result, "-0.000000 33") == 0);
8684
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1257 ASSERT (retval == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1258 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1259
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1260 { /* Positive infinity. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1261 int retval =
15595
328819af1c02 Support for MSVC compiler: Avoid division by a literal 0.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
1262 my_snprintf (result, sizeof (result), "%F %d", Infinityd (), 33, 44, 55);
8684
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1263 ASSERT (strcmp (result, "INF 33") == 0
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1264 || strcmp (result, "INFINITY 33") == 0);
8684
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1265 ASSERT (retval == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1266 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1267
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1268 { /* Negative infinity. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1269 int retval =
15595
328819af1c02 Support for MSVC compiler: Avoid division by a literal 0.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
1270 my_snprintf (result, sizeof (result), "%F %d", - Infinityd (), 33, 44, 55);
8684
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1271 ASSERT (strcmp (result, "-INF 33") == 0
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1272 || strcmp (result, "-INFINITY 33") == 0);
8684
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1273 ASSERT (retval == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1274 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1275
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1276 { /* NaN. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1277 int retval =
9854
baba3b346ab2 Use macros NaNf, NaNd, NaNl instead of NAN.
Bruno Haible <bruno@clisp.org>
parents: 9850
diff changeset
1278 my_snprintf (result, sizeof (result), "%F %d", NaNd (), 33, 44, 55);
8850
d1fe16dfbfee Avoid test failures on IRIX 6.5.
Bruno Haible <bruno@clisp.org>
parents: 8839
diff changeset
1279 ASSERT (strlen (result) >= 3 + 3
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1280 && strisnan (result, 0, strlen (result) - 3, 1)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1281 && strcmp (result + strlen (result) - 3, " 33") == 0);
8684
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1282 ASSERT (retval == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1283 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1284
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1285 { /* FLAG_ZERO. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1286 int retval =
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1287 my_snprintf (result, sizeof (result), "%015F %d", 1234.0, 33, 44, 55);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1288 ASSERT (strcmp (result, "00001234.000000 33") == 0);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1289 ASSERT (retval == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1290 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1291
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1292 { /* FLAG_ZERO with infinite number. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1293 int retval =
15595
328819af1c02 Support for MSVC compiler: Avoid division by a literal 0.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
1294 my_snprintf (result, sizeof (result), "%015F %d", - Infinityd (), 33, 44, 55);
8684
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1295 ASSERT (strcmp (result, " -INF 33") == 0
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1296 || strcmp (result, " -INFINITY 33") == 0);
8684
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1297 ASSERT (retval == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1298 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1299
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1300 { /* Precision. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1301 int retval =
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1302 my_snprintf (result, sizeof (result), "%.F %d", 1234.0, 33, 44, 55);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1303 ASSERT (strcmp (result, "1234 33") == 0);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1304 ASSERT (retval == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1305 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1306
9938
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9854
diff changeset
1307 { /* Precision with no rounding. */
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9854
diff changeset
1308 int retval =
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9854
diff changeset
1309 my_snprintf (result, sizeof (result), "%.2F %d", 999.951, 33, 44, 55);
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9854
diff changeset
1310 ASSERT (strcmp (result, "999.95 33") == 0);
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9854
diff changeset
1311 ASSERT (retval == strlen (result));
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9854
diff changeset
1312 }
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9854
diff changeset
1313
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9854
diff changeset
1314 { /* Precision with rounding. */
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9854
diff changeset
1315 int retval =
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9854
diff changeset
1316 my_snprintf (result, sizeof (result), "%.2F %d", 999.996, 33, 44, 55);
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9854
diff changeset
1317 ASSERT (strcmp (result, "1000.00 33") == 0);
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9854
diff changeset
1318 ASSERT (retval == strlen (result));
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9854
diff changeset
1319 }
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9854
diff changeset
1320
8684
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1321 { /* A positive number. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1322 int retval =
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1323 my_snprintf (result, sizeof (result), "%LF %d", 12.75L, 33, 44, 55);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1324 ASSERT (strcmp (result, "12.750000 33") == 0);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1325 ASSERT (retval == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1326 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1327
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1328 { /* A larger positive number. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1329 int retval =
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1330 my_snprintf (result, sizeof (result), "%LF %d", 1234567.0L, 33, 44, 55);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1331 ASSERT (strcmp (result, "1234567.000000 33") == 0);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1332 ASSERT (retval == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1333 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1334
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1335 { /* A negative number. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1336 int retval =
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1337 my_snprintf (result, sizeof (result), "%LF %d", -0.03125L, 33, 44, 55);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1338 ASSERT (strcmp (result, "-0.031250 33") == 0);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1339 ASSERT (retval == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1340 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1341
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1342 { /* Positive zero. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1343 int retval =
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1344 my_snprintf (result, sizeof (result), "%LF %d", 0.0L, 33, 44, 55);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1345 ASSERT (strcmp (result, "0.000000 33") == 0);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1346 ASSERT (retval == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1347 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1348
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1349 { /* Negative zero. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1350 int retval =
10601
ca053fa79cd3 Use a more portable replacement expression for -0.0L.
Bruno Haible <bruno@clisp.org>
parents: 10458
diff changeset
1351 my_snprintf (result, sizeof (result), "%LF %d", minus_zerol, 33, 44, 55);
8852
df0b5e8ea770 Avoid test failures on platforms where -0.0 and 0.0 are identical.
Bruno Haible <bruno@clisp.org>
parents: 8850
diff changeset
1352 if (have_minus_zero ())
df0b5e8ea770 Avoid test failures on platforms where -0.0 and 0.0 are identical.
Bruno Haible <bruno@clisp.org>
parents: 8850
diff changeset
1353 ASSERT (strcmp (result, "-0.000000 33") == 0);
8684
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1354 ASSERT (retval == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1355 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1356
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1357 { /* Positive infinity. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1358 int retval =
15595
328819af1c02 Support for MSVC compiler: Avoid division by a literal 0.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
1359 my_snprintf (result, sizeof (result), "%LF %d", Infinityl (), 33, 44, 55);
8684
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1360 ASSERT (strcmp (result, "INF 33") == 0
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1361 || strcmp (result, "INFINITY 33") == 0);
8684
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1362 ASSERT (retval == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1363 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1364
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1365 { /* Negative infinity. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1366 int retval =
15595
328819af1c02 Support for MSVC compiler: Avoid division by a literal 0.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
1367 my_snprintf (result, sizeof (result), "%LF %d", - Infinityl (), 33, 44, 55);
8684
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1368 ASSERT (strcmp (result, "-INF 33") == 0
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1369 || strcmp (result, "-INFINITY 33") == 0);
8684
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1370 ASSERT (retval == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1371 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1372
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1373 { /* NaN. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1374 int retval =
9854
baba3b346ab2 Use macros NaNf, NaNd, NaNl instead of NAN.
Bruno Haible <bruno@clisp.org>
parents: 9850
diff changeset
1375 my_snprintf (result, sizeof (result), "%LF %d", NaNl (), 33, 44, 55);
8850
d1fe16dfbfee Avoid test failures on IRIX 6.5.
Bruno Haible <bruno@clisp.org>
parents: 8839
diff changeset
1376 ASSERT (strlen (result) >= 3 + 3
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1377 && strisnan (result, 0, strlen (result) - 3, 1)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1378 && strcmp (result + strlen (result) - 3, " 33") == 0);
8684
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1379 ASSERT (retval == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1380 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1381
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1382 { /* FLAG_ZERO. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1383 int retval =
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1384 my_snprintf (result, sizeof (result), "%015LF %d", 1234.0L, 33, 44, 55);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1385 ASSERT (strcmp (result, "00001234.000000 33") == 0);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1386 ASSERT (retval == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1387 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1388
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1389 { /* FLAG_ZERO with infinite number. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1390 int retval =
15595
328819af1c02 Support for MSVC compiler: Avoid division by a literal 0.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
1391 my_snprintf (result, sizeof (result), "%015LF %d", - Infinityl (), 33, 44, 55);
8684
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1392 ASSERT (strcmp (result, " -INF 33") == 0
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1393 || strcmp (result, " -INFINITY 33") == 0);
8684
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1394 ASSERT (retval == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1395 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1396
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1397 { /* Precision. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1398 int retval =
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1399 my_snprintf (result, sizeof (result), "%.LF %d", 1234.0L, 33, 44, 55);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1400 ASSERT (strcmp (result, "1234 33") == 0);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1401 ASSERT (retval == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1402 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1403
9938
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9854
diff changeset
1404 { /* Precision with no rounding. */
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9854
diff changeset
1405 int retval =
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9854
diff changeset
1406 my_snprintf (result, sizeof (result), "%.2LF %d", 999.951L, 33, 44, 55);
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9854
diff changeset
1407 ASSERT (strcmp (result, "999.95 33") == 0);
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9854
diff changeset
1408 ASSERT (retval == strlen (result));
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9854
diff changeset
1409 }
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9854
diff changeset
1410
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9854
diff changeset
1411 { /* Precision with rounding. */
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9854
diff changeset
1412 int retval =
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9854
diff changeset
1413 my_snprintf (result, sizeof (result), "%.2LF %d", 999.996L, 33, 44, 55);
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9854
diff changeset
1414 ASSERT (strcmp (result, "1000.00 33") == 0);
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9854
diff changeset
1415 ASSERT (retval == strlen (result));
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9854
diff changeset
1416 }
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9854
diff changeset
1417
8836
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1418 /* Test the support of the %e format directive. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1419
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1420 { /* A positive number. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1421 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1422 my_snprintf (result, sizeof (result), "%e %d", 12.75, 33, 44, 55);
8839
5efc1d668039 Accomodate for implementations that produce 3 exponent digits in %e and %g.
Bruno Haible <bruno@clisp.org>
parents: 8836
diff changeset
1423 ASSERT (strcmp (result, "1.275000e+01 33") == 0
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1424 || strcmp (result, "1.275000e+001 33") == 0);
8836
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1425 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1426 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1427
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1428 { /* A larger positive number. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1429 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1430 my_snprintf (result, sizeof (result), "%e %d", 1234567.0, 33, 44, 55);
8839
5efc1d668039 Accomodate for implementations that produce 3 exponent digits in %e and %g.
Bruno Haible <bruno@clisp.org>
parents: 8836
diff changeset
1431 ASSERT (strcmp (result, "1.234567e+06 33") == 0
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1432 || strcmp (result, "1.234567e+006 33") == 0);
8836
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1433 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1434 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1435
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1436 { /* Small and large positive numbers. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1437 static struct { double value; const char *string; } data[] =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1438 {
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1439 { 1.234321234321234e-37, "1.234321e-37" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1440 { 1.234321234321234e-36, "1.234321e-36" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1441 { 1.234321234321234e-35, "1.234321e-35" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1442 { 1.234321234321234e-34, "1.234321e-34" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1443 { 1.234321234321234e-33, "1.234321e-33" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1444 { 1.234321234321234e-32, "1.234321e-32" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1445 { 1.234321234321234e-31, "1.234321e-31" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1446 { 1.234321234321234e-30, "1.234321e-30" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1447 { 1.234321234321234e-29, "1.234321e-29" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1448 { 1.234321234321234e-28, "1.234321e-28" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1449 { 1.234321234321234e-27, "1.234321e-27" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1450 { 1.234321234321234e-26, "1.234321e-26" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1451 { 1.234321234321234e-25, "1.234321e-25" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1452 { 1.234321234321234e-24, "1.234321e-24" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1453 { 1.234321234321234e-23, "1.234321e-23" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1454 { 1.234321234321234e-22, "1.234321e-22" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1455 { 1.234321234321234e-21, "1.234321e-21" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1456 { 1.234321234321234e-20, "1.234321e-20" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1457 { 1.234321234321234e-19, "1.234321e-19" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1458 { 1.234321234321234e-18, "1.234321e-18" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1459 { 1.234321234321234e-17, "1.234321e-17" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1460 { 1.234321234321234e-16, "1.234321e-16" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1461 { 1.234321234321234e-15, "1.234321e-15" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1462 { 1.234321234321234e-14, "1.234321e-14" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1463 { 1.234321234321234e-13, "1.234321e-13" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1464 { 1.234321234321234e-12, "1.234321e-12" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1465 { 1.234321234321234e-11, "1.234321e-11" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1466 { 1.234321234321234e-10, "1.234321e-10" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1467 { 1.234321234321234e-9, "1.234321e-09" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1468 { 1.234321234321234e-8, "1.234321e-08" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1469 { 1.234321234321234e-7, "1.234321e-07" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1470 { 1.234321234321234e-6, "1.234321e-06" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1471 { 1.234321234321234e-5, "1.234321e-05" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1472 { 1.234321234321234e-4, "1.234321e-04" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1473 { 1.234321234321234e-3, "1.234321e-03" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1474 { 1.234321234321234e-2, "1.234321e-02" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1475 { 1.234321234321234e-1, "1.234321e-01" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1476 { 1.234321234321234, "1.234321e+00" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1477 { 1.234321234321234e1, "1.234321e+01" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1478 { 1.234321234321234e2, "1.234321e+02" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1479 { 1.234321234321234e3, "1.234321e+03" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1480 { 1.234321234321234e4, "1.234321e+04" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1481 { 1.234321234321234e5, "1.234321e+05" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1482 { 1.234321234321234e6, "1.234321e+06" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1483 { 1.234321234321234e7, "1.234321e+07" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1484 { 1.234321234321234e8, "1.234321e+08" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1485 { 1.234321234321234e9, "1.234321e+09" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1486 { 1.234321234321234e10, "1.234321e+10" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1487 { 1.234321234321234e11, "1.234321e+11" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1488 { 1.234321234321234e12, "1.234321e+12" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1489 { 1.234321234321234e13, "1.234321e+13" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1490 { 1.234321234321234e14, "1.234321e+14" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1491 { 1.234321234321234e15, "1.234321e+15" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1492 { 1.234321234321234e16, "1.234321e+16" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1493 { 1.234321234321234e17, "1.234321e+17" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1494 { 1.234321234321234e18, "1.234321e+18" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1495 { 1.234321234321234e19, "1.234321e+19" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1496 { 1.234321234321234e20, "1.234321e+20" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1497 { 1.234321234321234e21, "1.234321e+21" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1498 { 1.234321234321234e22, "1.234321e+22" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1499 { 1.234321234321234e23, "1.234321e+23" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1500 { 1.234321234321234e24, "1.234321e+24" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1501 { 1.234321234321234e25, "1.234321e+25" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1502 { 1.234321234321234e26, "1.234321e+26" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1503 { 1.234321234321234e27, "1.234321e+27" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1504 { 1.234321234321234e28, "1.234321e+28" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1505 { 1.234321234321234e29, "1.234321e+29" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1506 { 1.234321234321234e30, "1.234321e+30" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1507 { 1.234321234321234e31, "1.234321e+31" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1508 { 1.234321234321234e32, "1.234321e+32" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1509 { 1.234321234321234e33, "1.234321e+33" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1510 { 1.234321234321234e34, "1.234321e+34" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1511 { 1.234321234321234e35, "1.234321e+35" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1512 { 1.234321234321234e36, "1.234321e+36" }
8836
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1513 };
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1514 size_t k;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1515 for (k = 0; k < SIZEOF (data); k++)
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1516 {
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1517 int retval =
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1518 my_snprintf (result, sizeof (result), "%e", data[k].value);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1519 const char *expected = data[k].string;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1520 ASSERT (strcmp (result, expected) == 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1521 /* Some implementations produce exponents with 3 digits. */
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1522 || (strlen (result) == strlen (expected) + 1
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1523 && memcmp (result, expected, strlen (expected) - 2) == 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1524 && result[strlen (expected) - 2] == '0'
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1525 && strcmp (result + strlen (expected) - 1,
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1526 expected + strlen (expected) - 2)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1527 == 0));
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1528 ASSERT (retval == strlen (result));
8836
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1529 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1530 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1531
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1532 { /* A negative number. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1533 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1534 my_snprintf (result, sizeof (result), "%e %d", -0.03125, 33, 44, 55);
8839
5efc1d668039 Accomodate for implementations that produce 3 exponent digits in %e and %g.
Bruno Haible <bruno@clisp.org>
parents: 8836
diff changeset
1535 ASSERT (strcmp (result, "-3.125000e-02 33") == 0
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1536 || strcmp (result, "-3.125000e-002 33") == 0);
8836
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1537 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1538 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1539
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1540 { /* Positive zero. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1541 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1542 my_snprintf (result, sizeof (result), "%e %d", 0.0, 33, 44, 55);
8839
5efc1d668039 Accomodate for implementations that produce 3 exponent digits in %e and %g.
Bruno Haible <bruno@clisp.org>
parents: 8836
diff changeset
1543 ASSERT (strcmp (result, "0.000000e+00 33") == 0
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1544 || strcmp (result, "0.000000e+000 33") == 0);
8836
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1545 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1546 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1547
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1548 { /* Negative zero. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1549 int retval =
13834
108bbfd6f03b frexp, tests: work around ICC bug with -zero
Eric Blake <eblake@redhat.com>
parents: 12559
diff changeset
1550 my_snprintf (result, sizeof (result), "%e %d", minus_zerod, 33, 44, 55);
8852
df0b5e8ea770 Avoid test failures on platforms where -0.0 and 0.0 are identical.
Bruno Haible <bruno@clisp.org>
parents: 8850
diff changeset
1551 if (have_minus_zero ())
df0b5e8ea770 Avoid test failures on platforms where -0.0 and 0.0 are identical.
Bruno Haible <bruno@clisp.org>
parents: 8850
diff changeset
1552 ASSERT (strcmp (result, "-0.000000e+00 33") == 0
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1553 || strcmp (result, "-0.000000e+000 33") == 0);
8836
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1554 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1555 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1556
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1557 { /* Positive infinity. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1558 int retval =
15595
328819af1c02 Support for MSVC compiler: Avoid division by a literal 0.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
1559 my_snprintf (result, sizeof (result), "%e %d", Infinityd (), 33, 44, 55);
8836
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1560 ASSERT (strcmp (result, "inf 33") == 0
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1561 || strcmp (result, "infinity 33") == 0);
8836
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1562 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1563 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1564
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1565 { /* Negative infinity. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1566 int retval =
15595
328819af1c02 Support for MSVC compiler: Avoid division by a literal 0.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
1567 my_snprintf (result, sizeof (result), "%e %d", - Infinityd (), 33, 44, 55);
8836
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1568 ASSERT (strcmp (result, "-inf 33") == 0
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1569 || strcmp (result, "-infinity 33") == 0);
8836
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1570 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1571 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1572
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1573 { /* NaN. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1574 int retval =
9854
baba3b346ab2 Use macros NaNf, NaNd, NaNl instead of NAN.
Bruno Haible <bruno@clisp.org>
parents: 9850
diff changeset
1575 my_snprintf (result, sizeof (result), "%e %d", NaNd (), 33, 44, 55);
8850
d1fe16dfbfee Avoid test failures on IRIX 6.5.
Bruno Haible <bruno@clisp.org>
parents: 8839
diff changeset
1576 ASSERT (strlen (result) >= 3 + 3
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1577 && strisnan (result, 0, strlen (result) - 3, 0)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1578 && strcmp (result + strlen (result) - 3, " 33") == 0);
8836
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1579 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1580 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1581
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1582 { /* Width. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1583 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1584 my_snprintf (result, sizeof (result), "%15e %d", 1.75, 33, 44, 55);
8839
5efc1d668039 Accomodate for implementations that produce 3 exponent digits in %e and %g.
Bruno Haible <bruno@clisp.org>
parents: 8836
diff changeset
1585 ASSERT (strcmp (result, " 1.750000e+00 33") == 0
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1586 || strcmp (result, " 1.750000e+000 33") == 0);
8836
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1587 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1588 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1589
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1590 { /* FLAG_LEFT. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1591 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1592 my_snprintf (result, sizeof (result), "%-15e %d", 1.75, 33, 44, 55);
8839
5efc1d668039 Accomodate for implementations that produce 3 exponent digits in %e and %g.
Bruno Haible <bruno@clisp.org>
parents: 8836
diff changeset
1593 ASSERT (strcmp (result, "1.750000e+00 33") == 0
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1594 || strcmp (result, "1.750000e+000 33") == 0);
8836
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1595 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1596 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1597
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1598 { /* FLAG_SHOWSIGN. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1599 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1600 my_snprintf (result, sizeof (result), "%+e %d", 1.75, 33, 44, 55);
8839
5efc1d668039 Accomodate for implementations that produce 3 exponent digits in %e and %g.
Bruno Haible <bruno@clisp.org>
parents: 8836
diff changeset
1601 ASSERT (strcmp (result, "+1.750000e+00 33") == 0
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1602 || strcmp (result, "+1.750000e+000 33") == 0);
8836
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1603 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1604 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1605
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1606 { /* FLAG_SPACE. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1607 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1608 my_snprintf (result, sizeof (result), "% e %d", 1.75, 33, 44, 55);
8839
5efc1d668039 Accomodate for implementations that produce 3 exponent digits in %e and %g.
Bruno Haible <bruno@clisp.org>
parents: 8836
diff changeset
1609 ASSERT (strcmp (result, " 1.750000e+00 33") == 0
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1610 || strcmp (result, " 1.750000e+000 33") == 0);
8836
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1611 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1612 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1613
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1614 { /* FLAG_ALT. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1615 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1616 my_snprintf (result, sizeof (result), "%#e %d", 1.75, 33, 44, 55);
8839
5efc1d668039 Accomodate for implementations that produce 3 exponent digits in %e and %g.
Bruno Haible <bruno@clisp.org>
parents: 8836
diff changeset
1617 ASSERT (strcmp (result, "1.750000e+00 33") == 0
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1618 || strcmp (result, "1.750000e+000 33") == 0);
8836
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1619 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1620 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1621
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1622 { /* FLAG_ALT. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1623 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1624 my_snprintf (result, sizeof (result), "%#.e %d", 1.75, 33, 44, 55);
8839
5efc1d668039 Accomodate for implementations that produce 3 exponent digits in %e and %g.
Bruno Haible <bruno@clisp.org>
parents: 8836
diff changeset
1625 ASSERT (strcmp (result, "2.e+00 33") == 0
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1626 || strcmp (result, "2.e+000 33") == 0);
8836
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1627 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1628 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1629
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1630 { /* FLAG_ALT. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1631 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1632 my_snprintf (result, sizeof (result), "%#.e %d", 9.75, 33, 44, 55);
8839
5efc1d668039 Accomodate for implementations that produce 3 exponent digits in %e and %g.
Bruno Haible <bruno@clisp.org>
parents: 8836
diff changeset
1633 ASSERT (strcmp (result, "1.e+01 33") == 0
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1634 || strcmp (result, "1.e+001 33") == 0);
8836
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1635 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1636 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1637
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1638 { /* FLAG_ZERO with finite number. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1639 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1640 my_snprintf (result, sizeof (result), "%015e %d", 1234.0, 33, 44, 55);
8839
5efc1d668039 Accomodate for implementations that produce 3 exponent digits in %e and %g.
Bruno Haible <bruno@clisp.org>
parents: 8836
diff changeset
1641 ASSERT (strcmp (result, "0001.234000e+03 33") == 0
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1642 || strcmp (result, "001.234000e+003 33") == 0);
8836
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1643 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1644 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1645
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1646 { /* FLAG_ZERO with infinite number. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1647 int retval =
15595
328819af1c02 Support for MSVC compiler: Avoid division by a literal 0.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
1648 my_snprintf (result, sizeof (result), "%015e %d", - Infinityd (), 33, 44, 55);
8836
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1649 ASSERT (strcmp (result, " -inf 33") == 0
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1650 || strcmp (result, " -infinity 33") == 0);
8836
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1651 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1652 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1653
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1654 { /* FLAG_ZERO with NaN. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1655 int retval =
9854
baba3b346ab2 Use macros NaNf, NaNd, NaNl instead of NAN.
Bruno Haible <bruno@clisp.org>
parents: 9850
diff changeset
1656 my_snprintf (result, sizeof (result), "%050e %d", NaNd (), 33, 44, 55);
8870
4e1f2ea486b4 Allow for a longer printed representation of NaN.
Bruno Haible <bruno@clisp.org>
parents: 8865
diff changeset
1657 ASSERT (strlen (result) == 50 + 3
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1658 && strisnan (result, strspn (result, " "), strlen (result) - 3, 0)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1659 && strcmp (result + strlen (result) - 3, " 33") == 0);
8836
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1660 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1661 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1662
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1663 { /* Precision. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1664 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1665 my_snprintf (result, sizeof (result), "%.e %d", 1234.0, 33, 44, 55);
8839
5efc1d668039 Accomodate for implementations that produce 3 exponent digits in %e and %g.
Bruno Haible <bruno@clisp.org>
parents: 8836
diff changeset
1666 ASSERT (strcmp (result, "1e+03 33") == 0
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1667 || strcmp (result, "1e+003 33") == 0);
8836
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1668 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1669 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1670
9938
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9854
diff changeset
1671 { /* Precision with no rounding. */
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9854
diff changeset
1672 int retval =
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9854
diff changeset
1673 my_snprintf (result, sizeof (result), "%.4e %d", 999.951, 33, 44, 55);
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9854
diff changeset
1674 ASSERT (strcmp (result, "9.9995e+02 33") == 0
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1675 || strcmp (result, "9.9995e+002 33") == 0);
9938
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9854
diff changeset
1676 ASSERT (retval == strlen (result));
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9854
diff changeset
1677 }
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9854
diff changeset
1678
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9854
diff changeset
1679 { /* Precision with rounding. */
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9854
diff changeset
1680 int retval =
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9854
diff changeset
1681 my_snprintf (result, sizeof (result), "%.4e %d", 999.996, 33, 44, 55);
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9854
diff changeset
1682 ASSERT (strcmp (result, "1.0000e+03 33") == 0
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1683 || strcmp (result, "1.0000e+003 33") == 0);
9938
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9854
diff changeset
1684 ASSERT (retval == strlen (result));
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9854
diff changeset
1685 }
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9854
diff changeset
1686
8836
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1687 { /* A positive number. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1688 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1689 my_snprintf (result, sizeof (result), "%Le %d", 12.75L, 33, 44, 55);
10458
1cc9cffb9615 Allow 3-digit exponents in %e and %g results on 'long double'.
Bruno Haible <bruno@clisp.org>
parents: 10457
diff changeset
1690 ASSERT (strcmp (result, "1.275000e+01 33") == 0
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1691 || strcmp (result, "1.275000e+001 33") == 0);
8836
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1692 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1693 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1694
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1695 { /* A larger positive number. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1696 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1697 my_snprintf (result, sizeof (result), "%Le %d", 1234567.0L, 33, 44, 55);
10458
1cc9cffb9615 Allow 3-digit exponents in %e and %g results on 'long double'.
Bruno Haible <bruno@clisp.org>
parents: 10457
diff changeset
1698 ASSERT (strcmp (result, "1.234567e+06 33") == 0
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1699 || strcmp (result, "1.234567e+006 33") == 0);
8836
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1700 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1701 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1702
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1703 { /* Small and large positive numbers. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1704 static struct { long double value; const char *string; } data[] =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1705 {
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1706 { 1.234321234321234e-37L, "1.234321e-37" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1707 { 1.234321234321234e-36L, "1.234321e-36" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1708 { 1.234321234321234e-35L, "1.234321e-35" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1709 { 1.234321234321234e-34L, "1.234321e-34" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1710 { 1.234321234321234e-33L, "1.234321e-33" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1711 { 1.234321234321234e-32L, "1.234321e-32" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1712 { 1.234321234321234e-31L, "1.234321e-31" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1713 { 1.234321234321234e-30L, "1.234321e-30" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1714 { 1.234321234321234e-29L, "1.234321e-29" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1715 { 1.234321234321234e-28L, "1.234321e-28" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1716 { 1.234321234321234e-27L, "1.234321e-27" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1717 { 1.234321234321234e-26L, "1.234321e-26" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1718 { 1.234321234321234e-25L, "1.234321e-25" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1719 { 1.234321234321234e-24L, "1.234321e-24" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1720 { 1.234321234321234e-23L, "1.234321e-23" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1721 { 1.234321234321234e-22L, "1.234321e-22" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1722 { 1.234321234321234e-21L, "1.234321e-21" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1723 { 1.234321234321234e-20L, "1.234321e-20" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1724 { 1.234321234321234e-19L, "1.234321e-19" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1725 { 1.234321234321234e-18L, "1.234321e-18" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1726 { 1.234321234321234e-17L, "1.234321e-17" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1727 { 1.234321234321234e-16L, "1.234321e-16" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1728 { 1.234321234321234e-15L, "1.234321e-15" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1729 { 1.234321234321234e-14L, "1.234321e-14" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1730 { 1.234321234321234e-13L, "1.234321e-13" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1731 { 1.234321234321234e-12L, "1.234321e-12" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1732 { 1.234321234321234e-11L, "1.234321e-11" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1733 { 1.234321234321234e-10L, "1.234321e-10" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1734 { 1.234321234321234e-9L, "1.234321e-09" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1735 { 1.234321234321234e-8L, "1.234321e-08" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1736 { 1.234321234321234e-7L, "1.234321e-07" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1737 { 1.234321234321234e-6L, "1.234321e-06" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1738 { 1.234321234321234e-5L, "1.234321e-05" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1739 { 1.234321234321234e-4L, "1.234321e-04" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1740 { 1.234321234321234e-3L, "1.234321e-03" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1741 { 1.234321234321234e-2L, "1.234321e-02" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1742 { 1.234321234321234e-1L, "1.234321e-01" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1743 { 1.234321234321234L, "1.234321e+00" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1744 { 1.234321234321234e1L, "1.234321e+01" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1745 { 1.234321234321234e2L, "1.234321e+02" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1746 { 1.234321234321234e3L, "1.234321e+03" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1747 { 1.234321234321234e4L, "1.234321e+04" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1748 { 1.234321234321234e5L, "1.234321e+05" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1749 { 1.234321234321234e6L, "1.234321e+06" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1750 { 1.234321234321234e7L, "1.234321e+07" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1751 { 1.234321234321234e8L, "1.234321e+08" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1752 { 1.234321234321234e9L, "1.234321e+09" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1753 { 1.234321234321234e10L, "1.234321e+10" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1754 { 1.234321234321234e11L, "1.234321e+11" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1755 { 1.234321234321234e12L, "1.234321e+12" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1756 { 1.234321234321234e13L, "1.234321e+13" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1757 { 1.234321234321234e14L, "1.234321e+14" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1758 { 1.234321234321234e15L, "1.234321e+15" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1759 { 1.234321234321234e16L, "1.234321e+16" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1760 { 1.234321234321234e17L, "1.234321e+17" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1761 { 1.234321234321234e18L, "1.234321e+18" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1762 { 1.234321234321234e19L, "1.234321e+19" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1763 { 1.234321234321234e20L, "1.234321e+20" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1764 { 1.234321234321234e21L, "1.234321e+21" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1765 { 1.234321234321234e22L, "1.234321e+22" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1766 { 1.234321234321234e23L, "1.234321e+23" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1767 { 1.234321234321234e24L, "1.234321e+24" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1768 { 1.234321234321234e25L, "1.234321e+25" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1769 { 1.234321234321234e26L, "1.234321e+26" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1770 { 1.234321234321234e27L, "1.234321e+27" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1771 { 1.234321234321234e28L, "1.234321e+28" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1772 { 1.234321234321234e29L, "1.234321e+29" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1773 { 1.234321234321234e30L, "1.234321e+30" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1774 { 1.234321234321234e31L, "1.234321e+31" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1775 { 1.234321234321234e32L, "1.234321e+32" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1776 { 1.234321234321234e33L, "1.234321e+33" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1777 { 1.234321234321234e34L, "1.234321e+34" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1778 { 1.234321234321234e35L, "1.234321e+35" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1779 { 1.234321234321234e36L, "1.234321e+36" }
8836
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1780 };
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1781 size_t k;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1782 for (k = 0; k < SIZEOF (data); k++)
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1783 {
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1784 int retval =
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1785 my_snprintf (result, sizeof (result), "%Le", data[k].value);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1786 const char *expected = data[k].string;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1787 ASSERT (strcmp (result, expected) == 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1788 /* Some implementations produce exponents with 3 digits. */
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1789 || (strlen (result) == strlen (expected) + 1
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1790 && memcmp (result, expected, strlen (expected) - 2) == 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1791 && result[strlen (expected) - 2] == '0'
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1792 && strcmp (result + strlen (expected) - 1,
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1793 expected + strlen (expected) - 2)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1794 == 0));
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1795 ASSERT (retval == strlen (result));
8836
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1796 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1797 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1798
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1799 { /* A negative number. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1800 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1801 my_snprintf (result, sizeof (result), "%Le %d", -0.03125L, 33, 44, 55);
10458
1cc9cffb9615 Allow 3-digit exponents in %e and %g results on 'long double'.
Bruno Haible <bruno@clisp.org>
parents: 10457
diff changeset
1802 ASSERT (strcmp (result, "-3.125000e-02 33") == 0
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1803 || strcmp (result, "-3.125000e-002 33") == 0);
8836
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1804 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1805 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1806
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1807 { /* Positive zero. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1808 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1809 my_snprintf (result, sizeof (result), "%Le %d", 0.0L, 33, 44, 55);
10458
1cc9cffb9615 Allow 3-digit exponents in %e and %g results on 'long double'.
Bruno Haible <bruno@clisp.org>
parents: 10457
diff changeset
1810 ASSERT (strcmp (result, "0.000000e+00 33") == 0
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1811 || strcmp (result, "0.000000e+000 33") == 0);
8836
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1812 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1813 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1814
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1815 { /* Negative zero. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1816 int retval =
10601
ca053fa79cd3 Use a more portable replacement expression for -0.0L.
Bruno Haible <bruno@clisp.org>
parents: 10458
diff changeset
1817 my_snprintf (result, sizeof (result), "%Le %d", minus_zerol, 33, 44, 55);
8852
df0b5e8ea770 Avoid test failures on platforms where -0.0 and 0.0 are identical.
Bruno Haible <bruno@clisp.org>
parents: 8850
diff changeset
1818 if (have_minus_zero ())
10458
1cc9cffb9615 Allow 3-digit exponents in %e and %g results on 'long double'.
Bruno Haible <bruno@clisp.org>
parents: 10457
diff changeset
1819 ASSERT (strcmp (result, "-0.000000e+00 33") == 0
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1820 || strcmp (result, "-0.000000e+000 33") == 0);
8836
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1821 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1822 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1823
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1824 { /* Positive infinity. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1825 int retval =
15595
328819af1c02 Support for MSVC compiler: Avoid division by a literal 0.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
1826 my_snprintf (result, sizeof (result), "%Le %d", Infinityl (), 33, 44, 55);
8836
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1827 ASSERT (strcmp (result, "inf 33") == 0
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1828 || strcmp (result, "infinity 33") == 0);
8836
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1829 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1830 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1831
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1832 { /* Negative infinity. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1833 int retval =
15595
328819af1c02 Support for MSVC compiler: Avoid division by a literal 0.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
1834 my_snprintf (result, sizeof (result), "%Le %d", - Infinityl (), 33, 44, 55);
8836
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1835 ASSERT (strcmp (result, "-inf 33") == 0
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1836 || strcmp (result, "-infinity 33") == 0);
8836
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1837 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1838 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1839
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1840 { /* NaN. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1841 int retval =
9854
baba3b346ab2 Use macros NaNf, NaNd, NaNl instead of NAN.
Bruno Haible <bruno@clisp.org>
parents: 9850
diff changeset
1842 my_snprintf (result, sizeof (result), "%Le %d", NaNl (), 33, 44, 55);
8850
d1fe16dfbfee Avoid test failures on IRIX 6.5.
Bruno Haible <bruno@clisp.org>
parents: 8839
diff changeset
1843 ASSERT (strlen (result) >= 3 + 3
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1844 && strisnan (result, 0, strlen (result) - 3, 0)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1845 && strcmp (result + strlen (result) - 3, " 33") == 0);
8836
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1846 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1847 }
15906
400649d35651 *printf-posix tests: Fix for platforms where 'long double' == 'double'.
Bruno Haible <bruno@clisp.org>
parents: 15595
diff changeset
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
8919
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8870
diff changeset
1849 { /* Quiet NaN. */
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8870
diff changeset
1850 static union { unsigned int word[4]; long double value; } x =
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8870
diff changeset
1851 { LDBL80_WORDS (0xFFFF, 0xC3333333, 0x00000000) };
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8870
diff changeset
1852 int retval =
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8870
diff changeset
1853 my_snprintf (result, sizeof (result), "%Le %d", x.value, 33, 44, 55);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8870
diff changeset
1854 ASSERT (strlen (result) >= 3 + 3
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1855 && strisnan (result, 0, strlen (result) - 3, 0)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1856 && strcmp (result + strlen (result) - 3, " 33") == 0);
8919
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8870
diff changeset
1857 ASSERT (retval == strlen (result));
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8870
diff changeset
1858 }
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8870
diff changeset
1859 {
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8870
diff changeset
1860 /* Signalling NaN. */
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8870
diff changeset
1861 static union { unsigned int word[4]; long double value; } x =
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8870
diff changeset
1862 { LDBL80_WORDS (0xFFFF, 0x83333333, 0x00000000) };
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8870
diff changeset
1863 int retval =
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8870
diff changeset
1864 my_snprintf (result, sizeof (result), "%Le %d", x.value, 33, 44, 55);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8870
diff changeset
1865 ASSERT (strlen (result) >= 3 + 3
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1866 && strisnan (result, 0, strlen (result) - 3, 0)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1867 && strcmp (result + strlen (result) - 3, " 33") == 0);
8919
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8870
diff changeset
1868 ASSERT (retval == strlen (result));
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8870
diff changeset
1869 }
17927
b941bb9e9efb printf, isinf, etc.: noncanonical != NaN
Paul Eggert <eggert@cs.ucla.edu>
parents: 17848
diff changeset
1870 /* snprintf should print something for noncanonical values. */
b941bb9e9efb printf, isinf, etc.: noncanonical != NaN
Paul Eggert <eggert@cs.ucla.edu>
parents: 17848
diff changeset
1871 { /* Pseudo-NaN. */
b941bb9e9efb printf, isinf, etc.: noncanonical != NaN
Paul Eggert <eggert@cs.ucla.edu>
parents: 17848
diff changeset
1872 static union { unsigned int word[4]; long double value; } x =
b941bb9e9efb printf, isinf, etc.: noncanonical != NaN
Paul Eggert <eggert@cs.ucla.edu>
parents: 17848
diff changeset
1873 { LDBL80_WORDS (0xFFFF, 0x40000001, 0x00000000) };
b941bb9e9efb printf, isinf, etc.: noncanonical != NaN
Paul Eggert <eggert@cs.ucla.edu>
parents: 17848
diff changeset
1874 int retval =
b941bb9e9efb printf, isinf, etc.: noncanonical != NaN
Paul Eggert <eggert@cs.ucla.edu>
parents: 17848
diff changeset
1875 my_snprintf (result, sizeof (result), "%Le %d", x.value, 33, 44, 55);
b941bb9e9efb printf, isinf, etc.: noncanonical != NaN
Paul Eggert <eggert@cs.ucla.edu>
parents: 17848
diff changeset
1876 ASSERT (retval == strlen (result));
b941bb9e9efb printf, isinf, etc.: noncanonical != NaN
Paul Eggert <eggert@cs.ucla.edu>
parents: 17848
diff changeset
1877 ASSERT (3 < retval && strcmp (result + retval - 3, " 33") == 0);
b941bb9e9efb printf, isinf, etc.: noncanonical != NaN
Paul Eggert <eggert@cs.ucla.edu>
parents: 17848
diff changeset
1878 }
b941bb9e9efb printf, isinf, etc.: noncanonical != NaN
Paul Eggert <eggert@cs.ucla.edu>
parents: 17848
diff changeset
1879 { /* Pseudo-Infinity. */
b941bb9e9efb printf, isinf, etc.: noncanonical != NaN
Paul Eggert <eggert@cs.ucla.edu>
parents: 17848
diff changeset
1880 static union { unsigned int word[4]; long double value; } x =
b941bb9e9efb printf, isinf, etc.: noncanonical != NaN
Paul Eggert <eggert@cs.ucla.edu>
parents: 17848
diff changeset
1881 { LDBL80_WORDS (0xFFFF, 0x00000000, 0x00000000) };
b941bb9e9efb printf, isinf, etc.: noncanonical != NaN
Paul Eggert <eggert@cs.ucla.edu>
parents: 17848
diff changeset
1882 int retval =
b941bb9e9efb printf, isinf, etc.: noncanonical != NaN
Paul Eggert <eggert@cs.ucla.edu>
parents: 17848
diff changeset
1883 my_snprintf (result, sizeof (result), "%Le %d", x.value, 33, 44, 55);
b941bb9e9efb printf, isinf, etc.: noncanonical != NaN
Paul Eggert <eggert@cs.ucla.edu>
parents: 17848
diff changeset
1884 ASSERT (retval == strlen (result));
b941bb9e9efb printf, isinf, etc.: noncanonical != NaN
Paul Eggert <eggert@cs.ucla.edu>
parents: 17848
diff changeset
1885 ASSERT (3 < retval && strcmp (result + retval - 3, " 33") == 0);
b941bb9e9efb printf, isinf, etc.: noncanonical != NaN
Paul Eggert <eggert@cs.ucla.edu>
parents: 17848
diff changeset
1886 }
8919
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8870
diff changeset
1887 { /* Pseudo-Zero. */
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8870
diff changeset
1888 static union { unsigned int word[4]; long double value; } x =
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8870
diff changeset
1889 { LDBL80_WORDS (0x4004, 0x00000000, 0x00000000) };
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8870
diff changeset
1890 int retval =
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8870
diff changeset
1891 my_snprintf (result, sizeof (result), "%Le %d", x.value, 33, 44, 55);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8870
diff changeset
1892 ASSERT (retval == strlen (result));
17927
b941bb9e9efb printf, isinf, etc.: noncanonical != NaN
Paul Eggert <eggert@cs.ucla.edu>
parents: 17848
diff changeset
1893 ASSERT (3 < retval && strcmp (result + retval - 3, " 33") == 0);
8919
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8870
diff changeset
1894 }
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8870
diff changeset
1895 { /* Unnormalized number. */
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8870
diff changeset
1896 static union { unsigned int word[4]; long double value; } x =
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8870
diff changeset
1897 { LDBL80_WORDS (0x4000, 0x63333333, 0x00000000) };
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8870
diff changeset
1898 int retval =
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8870
diff changeset
1899 my_snprintf (result, sizeof (result), "%Le %d", x.value, 33, 44, 55);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8870
diff changeset
1900 ASSERT (retval == strlen (result));
17927
b941bb9e9efb printf, isinf, etc.: noncanonical != NaN
Paul Eggert <eggert@cs.ucla.edu>
parents: 17848
diff changeset
1901 ASSERT (3 < retval && strcmp (result + retval - 3, " 33") == 0);
8919
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8870
diff changeset
1902 }
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8870
diff changeset
1903 { /* Pseudo-Denormal. */
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8870
diff changeset
1904 static union { unsigned int word[4]; long double value; } x =
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8870
diff changeset
1905 { LDBL80_WORDS (0x0000, 0x83333333, 0x00000000) };
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8870
diff changeset
1906 int retval =
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8870
diff changeset
1907 my_snprintf (result, sizeof (result), "%Le %d", x.value, 33, 44, 55);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8870
diff changeset
1908 ASSERT (retval == strlen (result));
17927
b941bb9e9efb printf, isinf, etc.: noncanonical != NaN
Paul Eggert <eggert@cs.ucla.edu>
parents: 17848
diff changeset
1909 ASSERT (3 < retval && strcmp (result + retval - 3, " 33") == 0);
8919
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8870
diff changeset
1910 }
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8870
diff changeset
1911 #endif
8836
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1912
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1913 { /* Width. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1914 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1915 my_snprintf (result, sizeof (result), "%15Le %d", 1.75L, 33, 44, 55);
10458
1cc9cffb9615 Allow 3-digit exponents in %e and %g results on 'long double'.
Bruno Haible <bruno@clisp.org>
parents: 10457
diff changeset
1916 ASSERT (strcmp (result, " 1.750000e+00 33") == 0
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1917 || strcmp (result, " 1.750000e+000 33") == 0);
8836
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1918 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1919 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1920
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1921 { /* FLAG_LEFT. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1922 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1923 my_snprintf (result, sizeof (result), "%-15Le %d", 1.75L, 33, 44, 55);
10458
1cc9cffb9615 Allow 3-digit exponents in %e and %g results on 'long double'.
Bruno Haible <bruno@clisp.org>
parents: 10457
diff changeset
1924 ASSERT (strcmp (result, "1.750000e+00 33") == 0
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1925 || strcmp (result, "1.750000e+000 33") == 0);
8836
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1926 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1927 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1928
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1929 { /* FLAG_SHOWSIGN. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1930 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1931 my_snprintf (result, sizeof (result), "%+Le %d", 1.75L, 33, 44, 55);
10458
1cc9cffb9615 Allow 3-digit exponents in %e and %g results on 'long double'.
Bruno Haible <bruno@clisp.org>
parents: 10457
diff changeset
1932 ASSERT (strcmp (result, "+1.750000e+00 33") == 0
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1933 || strcmp (result, "+1.750000e+000 33") == 0);
8836
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1934 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1935 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1936
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1937 { /* FLAG_SPACE. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1938 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1939 my_snprintf (result, sizeof (result), "% Le %d", 1.75L, 33, 44, 55);
10458
1cc9cffb9615 Allow 3-digit exponents in %e and %g results on 'long double'.
Bruno Haible <bruno@clisp.org>
parents: 10457
diff changeset
1940 ASSERT (strcmp (result, " 1.750000e+00 33") == 0
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1941 || strcmp (result, " 1.750000e+000 33") == 0);
8836
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1942 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1943 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1944
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1945 { /* FLAG_ALT. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1946 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1947 my_snprintf (result, sizeof (result), "%#Le %d", 1.75L, 33, 44, 55);
10458
1cc9cffb9615 Allow 3-digit exponents in %e and %g results on 'long double'.
Bruno Haible <bruno@clisp.org>
parents: 10457
diff changeset
1948 ASSERT (strcmp (result, "1.750000e+00 33") == 0
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1949 || strcmp (result, "1.750000e+000 33") == 0);
8836
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1950 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1951 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1952
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1953 { /* FLAG_ALT. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1954 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1955 my_snprintf (result, sizeof (result), "%#.Le %d", 1.75L, 33, 44, 55);
10458
1cc9cffb9615 Allow 3-digit exponents in %e and %g results on 'long double'.
Bruno Haible <bruno@clisp.org>
parents: 10457
diff changeset
1956 ASSERT (strcmp (result, "2.e+00 33") == 0
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1957 || strcmp (result, "2.e+000 33") == 0);
8836
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1958 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1959 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1960
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1961 { /* FLAG_ALT. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1962 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1963 my_snprintf (result, sizeof (result), "%#.Le %d", 9.75L, 33, 44, 55);
10458
1cc9cffb9615 Allow 3-digit exponents in %e and %g results on 'long double'.
Bruno Haible <bruno@clisp.org>
parents: 10457
diff changeset
1964 ASSERT (strcmp (result, "1.e+01 33") == 0
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1965 || strcmp (result, "1.e+001 33") == 0);
8836
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1966 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1967 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1968
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1969 { /* FLAG_ZERO with finite number. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1970 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1971 my_snprintf (result, sizeof (result), "%015Le %d", 1234.0L, 33, 44, 55);
10458
1cc9cffb9615 Allow 3-digit exponents in %e and %g results on 'long double'.
Bruno Haible <bruno@clisp.org>
parents: 10457
diff changeset
1972 ASSERT (strcmp (result, "0001.234000e+03 33") == 0
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1973 || strcmp (result, "001.234000e+003 33") == 0);
8836
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1974 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1975 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1976
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1977 { /* FLAG_ZERO with infinite number. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1978 int retval =
15595
328819af1c02 Support for MSVC compiler: Avoid division by a literal 0.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
1979 my_snprintf (result, sizeof (result), "%015Le %d", - Infinityl (), 33, 44, 55);
8836
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1980 ASSERT (strcmp (result, " -inf 33") == 0
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1981 || strcmp (result, " -infinity 33") == 0);
8836
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1982 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1983 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1984
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1985 { /* FLAG_ZERO with NaN. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1986 int retval =
9854
baba3b346ab2 Use macros NaNf, NaNd, NaNl instead of NAN.
Bruno Haible <bruno@clisp.org>
parents: 9850
diff changeset
1987 my_snprintf (result, sizeof (result), "%050Le %d", NaNl (), 33, 44, 55);
8870
4e1f2ea486b4 Allow for a longer printed representation of NaN.
Bruno Haible <bruno@clisp.org>
parents: 8865
diff changeset
1988 ASSERT (strlen (result) == 50 + 3
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1989 && strisnan (result, strspn (result, " "), strlen (result) - 3, 0)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1990 && strcmp (result + strlen (result) - 3, " 33") == 0);
8836
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1991 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1992 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1993
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1994 { /* Precision. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1995 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1996 my_snprintf (result, sizeof (result), "%.Le %d", 1234.0L, 33, 44, 55);
10458
1cc9cffb9615 Allow 3-digit exponents in %e and %g results on 'long double'.
Bruno Haible <bruno@clisp.org>
parents: 10457
diff changeset
1997 ASSERT (strcmp (result, "1e+03 33") == 0
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1998 || strcmp (result, "1e+003 33") == 0);
8836
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1999 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2000 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2001
9938
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9854
diff changeset
2002 { /* Precision with no rounding. */
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9854
diff changeset
2003 int retval =
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9854
diff changeset
2004 my_snprintf (result, sizeof (result), "%.4Le %d", 999.951L, 33, 44, 55);
10458
1cc9cffb9615 Allow 3-digit exponents in %e and %g results on 'long double'.
Bruno Haible <bruno@clisp.org>
parents: 10457
diff changeset
2005 ASSERT (strcmp (result, "9.9995e+02 33") == 0
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2006 || strcmp (result, "9.9995e+002 33") == 0);
9938
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9854
diff changeset
2007 ASSERT (retval == strlen (result));
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9854
diff changeset
2008 }
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9854
diff changeset
2009
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9854
diff changeset
2010 { /* Precision with rounding. */
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9854
diff changeset
2011 int retval =
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9854
diff changeset
2012 my_snprintf (result, sizeof (result), "%.4Le %d", 999.996L, 33, 44, 55);
10458
1cc9cffb9615 Allow 3-digit exponents in %e and %g results on 'long double'.
Bruno Haible <bruno@clisp.org>
parents: 10457
diff changeset
2013 ASSERT (strcmp (result, "1.0000e+03 33") == 0
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2014 || strcmp (result, "1.0000e+003 33") == 0);
9938
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9854
diff changeset
2015 ASSERT (retval == strlen (result));
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9854
diff changeset
2016 }
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9854
diff changeset
2017
8836
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2018 /* Test the support of the %g format directive. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2019
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2020 { /* A positive number. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2021 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2022 my_snprintf (result, sizeof (result), "%g %d", 12.75, 33, 44, 55);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2023 ASSERT (strcmp (result, "12.75 33") == 0);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2024 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2025 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2026
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2027 { /* A larger positive number. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2028 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2029 my_snprintf (result, sizeof (result), "%g %d", 1234567.0, 33, 44, 55);
8839
5efc1d668039 Accomodate for implementations that produce 3 exponent digits in %e and %g.
Bruno Haible <bruno@clisp.org>
parents: 8836
diff changeset
2030 ASSERT (strcmp (result, "1.23457e+06 33") == 0
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2031 || strcmp (result, "1.23457e+006 33") == 0);
8836
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2032 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2033 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2034
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2035 { /* Small and large positive numbers. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2036 static struct { double value; const char *string; } data[] =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2037 {
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2038 { 1.234321234321234e-37, "1.23432e-37" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2039 { 1.234321234321234e-36, "1.23432e-36" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2040 { 1.234321234321234e-35, "1.23432e-35" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2041 { 1.234321234321234e-34, "1.23432e-34" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2042 { 1.234321234321234e-33, "1.23432e-33" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2043 { 1.234321234321234e-32, "1.23432e-32" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2044 { 1.234321234321234e-31, "1.23432e-31" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2045 { 1.234321234321234e-30, "1.23432e-30" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2046 { 1.234321234321234e-29, "1.23432e-29" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2047 { 1.234321234321234e-28, "1.23432e-28" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2048 { 1.234321234321234e-27, "1.23432e-27" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2049 { 1.234321234321234e-26, "1.23432e-26" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2050 { 1.234321234321234e-25, "1.23432e-25" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2051 { 1.234321234321234e-24, "1.23432e-24" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2052 { 1.234321234321234e-23, "1.23432e-23" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2053 { 1.234321234321234e-22, "1.23432e-22" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2054 { 1.234321234321234e-21, "1.23432e-21" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2055 { 1.234321234321234e-20, "1.23432e-20" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2056 { 1.234321234321234e-19, "1.23432e-19" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2057 { 1.234321234321234e-18, "1.23432e-18" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2058 { 1.234321234321234e-17, "1.23432e-17" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2059 { 1.234321234321234e-16, "1.23432e-16" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2060 { 1.234321234321234e-15, "1.23432e-15" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2061 { 1.234321234321234e-14, "1.23432e-14" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2062 { 1.234321234321234e-13, "1.23432e-13" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2063 { 1.234321234321234e-12, "1.23432e-12" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2064 { 1.234321234321234e-11, "1.23432e-11" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2065 { 1.234321234321234e-10, "1.23432e-10" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2066 { 1.234321234321234e-9, "1.23432e-09" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2067 { 1.234321234321234e-8, "1.23432e-08" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2068 { 1.234321234321234e-7, "1.23432e-07" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2069 { 1.234321234321234e-6, "1.23432e-06" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2070 { 1.234321234321234e-5, "1.23432e-05" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2071 { 1.234321234321234e-4, "0.000123432" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2072 { 1.234321234321234e-3, "0.00123432" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2073 { 1.234321234321234e-2, "0.0123432" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2074 { 1.234321234321234e-1, "0.123432" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2075 { 1.234321234321234, "1.23432" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2076 { 1.234321234321234e1, "12.3432" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2077 { 1.234321234321234e2, "123.432" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2078 { 1.234321234321234e3, "1234.32" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2079 { 1.234321234321234e4, "12343.2" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2080 { 1.234321234321234e5, "123432" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2081 { 1.234321234321234e6, "1.23432e+06" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2082 { 1.234321234321234e7, "1.23432e+07" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2083 { 1.234321234321234e8, "1.23432e+08" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2084 { 1.234321234321234e9, "1.23432e+09" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2085 { 1.234321234321234e10, "1.23432e+10" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2086 { 1.234321234321234e11, "1.23432e+11" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2087 { 1.234321234321234e12, "1.23432e+12" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2088 { 1.234321234321234e13, "1.23432e+13" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2089 { 1.234321234321234e14, "1.23432e+14" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2090 { 1.234321234321234e15, "1.23432e+15" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2091 { 1.234321234321234e16, "1.23432e+16" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2092 { 1.234321234321234e17, "1.23432e+17" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2093 { 1.234321234321234e18, "1.23432e+18" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2094 { 1.234321234321234e19, "1.23432e+19" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2095 { 1.234321234321234e20, "1.23432e+20" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2096 { 1.234321234321234e21, "1.23432e+21" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2097 { 1.234321234321234e22, "1.23432e+22" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2098 { 1.234321234321234e23, "1.23432e+23" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2099 { 1.234321234321234e24, "1.23432e+24" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2100 { 1.234321234321234e25, "1.23432e+25" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2101 { 1.234321234321234e26, "1.23432e+26" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2102 { 1.234321234321234e27, "1.23432e+27" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2103 { 1.234321234321234e28, "1.23432e+28" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2104 { 1.234321234321234e29, "1.23432e+29" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2105 { 1.234321234321234e30, "1.23432e+30" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2106 { 1.234321234321234e31, "1.23432e+31" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2107 { 1.234321234321234e32, "1.23432e+32" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2108 { 1.234321234321234e33, "1.23432e+33" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2109 { 1.234321234321234e34, "1.23432e+34" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2110 { 1.234321234321234e35, "1.23432e+35" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2111 { 1.234321234321234e36, "1.23432e+36" }
8836
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2112 };
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2113 size_t k;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2114 for (k = 0; k < SIZEOF (data); k++)
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2115 {
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2116 int retval =
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2117 my_snprintf (result, sizeof (result), "%g", data[k].value);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2118 const char *expected = data[k].string;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2119 ASSERT (strcmp (result, expected) == 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2120 /* Some implementations produce exponents with 3 digits. */
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2121 || (expected[strlen (expected) - 4] == 'e'
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2122 && strlen (result) == strlen (expected) + 1
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2123 && memcmp (result, expected, strlen (expected) - 2) == 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2124 && result[strlen (expected) - 2] == '0'
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2125 && strcmp (result + strlen (expected) - 1,
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2126 expected + strlen (expected) - 2)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2127 == 0));
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2128 ASSERT (retval == strlen (result));
8836
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2129 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2130 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2131
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2132 { /* A negative number. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2133 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2134 my_snprintf (result, sizeof (result), "%g %d", -0.03125, 33, 44, 55);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2135 ASSERT (strcmp (result, "-0.03125 33") == 0);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2136 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2137 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2138
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2139 { /* Positive zero. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2140 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2141 my_snprintf (result, sizeof (result), "%g %d", 0.0, 33, 44, 55);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2142 ASSERT (strcmp (result, "0 33") == 0);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2143 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2144 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2145
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2146 { /* Negative zero. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2147 int retval =
13834
108bbfd6f03b frexp, tests: work around ICC bug with -zero
Eric Blake <eblake@redhat.com>
parents: 12559
diff changeset
2148 my_snprintf (result, sizeof (result), "%g %d", minus_zerod, 33, 44, 55);
8852
df0b5e8ea770 Avoid test failures on platforms where -0.0 and 0.0 are identical.
Bruno Haible <bruno@clisp.org>
parents: 8850
diff changeset
2149 if (have_minus_zero ())
df0b5e8ea770 Avoid test failures on platforms where -0.0 and 0.0 are identical.
Bruno Haible <bruno@clisp.org>
parents: 8850
diff changeset
2150 ASSERT (strcmp (result, "-0 33") == 0);
8836
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2151 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2152 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2153
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2154 { /* Positive infinity. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2155 int retval =
15595
328819af1c02 Support for MSVC compiler: Avoid division by a literal 0.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
2156 my_snprintf (result, sizeof (result), "%g %d", Infinityd (), 33, 44, 55);
8836
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2157 ASSERT (strcmp (result, "inf 33") == 0
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2158 || strcmp (result, "infinity 33") == 0);
8836
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2159 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2160 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2161
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2162 { /* Negative infinity. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2163 int retval =
15595
328819af1c02 Support for MSVC compiler: Avoid division by a literal 0.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
2164 my_snprintf (result, sizeof (result), "%g %d", - Infinityd (), 33, 44, 55);
8836
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2165 ASSERT (strcmp (result, "-inf 33") == 0
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2166 || strcmp (result, "-infinity 33") == 0);
8836
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2167 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2168 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2169
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2170 { /* NaN. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2171 int retval =
9854
baba3b346ab2 Use macros NaNf, NaNd, NaNl instead of NAN.
Bruno Haible <bruno@clisp.org>
parents: 9850
diff changeset
2172 my_snprintf (result, sizeof (result), "%g %d", NaNd (), 33, 44, 55);
8850
d1fe16dfbfee Avoid test failures on IRIX 6.5.
Bruno Haible <bruno@clisp.org>
parents: 8839
diff changeset
2173 ASSERT (strlen (result) >= 3 + 3
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2174 && strisnan (result, 0, strlen (result) - 3, 0)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2175 && strcmp (result + strlen (result) - 3, " 33") == 0);
8836
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2176 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2177 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2178
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2179 { /* Width. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2180 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2181 my_snprintf (result, sizeof (result), "%10g %d", 1.75, 33, 44, 55);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2182 ASSERT (strcmp (result, " 1.75 33") == 0);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2183 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2184 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2185
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2186 { /* FLAG_LEFT. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2187 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2188 my_snprintf (result, sizeof (result), "%-10g %d", 1.75, 33, 44, 55);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2189 ASSERT (strcmp (result, "1.75 33") == 0);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2190 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2191 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2192
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2193 { /* FLAG_SHOWSIGN. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2194 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2195 my_snprintf (result, sizeof (result), "%+g %d", 1.75, 33, 44, 55);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2196 ASSERT (strcmp (result, "+1.75 33") == 0);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2197 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2198 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2199
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2200 { /* FLAG_SPACE. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2201 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2202 my_snprintf (result, sizeof (result), "% g %d", 1.75, 33, 44, 55);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2203 ASSERT (strcmp (result, " 1.75 33") == 0);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2204 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2205 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2206
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2207 { /* FLAG_ALT. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2208 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2209 my_snprintf (result, sizeof (result), "%#g %d", 1.75, 33, 44, 55);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2210 ASSERT (strcmp (result, "1.75000 33") == 0);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2211 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2212 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2213
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2214 { /* FLAG_ALT. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2215 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2216 my_snprintf (result, sizeof (result), "%#.g %d", 1.75, 33, 44, 55);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2217 ASSERT (strcmp (result, "2. 33") == 0);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2218 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2219 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2220
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2221 { /* FLAG_ALT. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2222 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2223 my_snprintf (result, sizeof (result), "%#.g %d", 9.75, 33, 44, 55);
8839
5efc1d668039 Accomodate for implementations that produce 3 exponent digits in %e and %g.
Bruno Haible <bruno@clisp.org>
parents: 8836
diff changeset
2224 ASSERT (strcmp (result, "1.e+01 33") == 0
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2225 || strcmp (result, "1.e+001 33") == 0);
8836
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2226 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2227 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2228
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2229 { /* FLAG_ZERO with finite number. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2230 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2231 my_snprintf (result, sizeof (result), "%010g %d", 1234.0, 33, 44, 55);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2232 ASSERT (strcmp (result, "0000001234 33") == 0);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2233 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2234 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2235
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2236 { /* FLAG_ZERO with infinite number. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2237 int retval =
15595
328819af1c02 Support for MSVC compiler: Avoid division by a literal 0.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
2238 my_snprintf (result, sizeof (result), "%015g %d", - Infinityd (), 33, 44, 55);
8836
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2239 ASSERT (strcmp (result, " -inf 33") == 0
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2240 || strcmp (result, " -infinity 33") == 0);
8836
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2241 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2242 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2243
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2244 { /* FLAG_ZERO with NaN. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2245 int retval =
9854
baba3b346ab2 Use macros NaNf, NaNd, NaNl instead of NAN.
Bruno Haible <bruno@clisp.org>
parents: 9850
diff changeset
2246 my_snprintf (result, sizeof (result), "%050g %d", NaNd (), 33, 44, 55);
8870
4e1f2ea486b4 Allow for a longer printed representation of NaN.
Bruno Haible <bruno@clisp.org>
parents: 8865
diff changeset
2247 ASSERT (strlen (result) == 50 + 3
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2248 && strisnan (result, strspn (result, " "), strlen (result) - 3, 0)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2249 && strcmp (result + strlen (result) - 3, " 33") == 0);
8836
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2250 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2251 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2252
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2253 { /* Precision. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2254 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2255 my_snprintf (result, sizeof (result), "%.g %d", 1234.0, 33, 44, 55);
8839
5efc1d668039 Accomodate for implementations that produce 3 exponent digits in %e and %g.
Bruno Haible <bruno@clisp.org>
parents: 8836
diff changeset
2256 ASSERT (strcmp (result, "1e+03 33") == 0
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2257 || strcmp (result, "1e+003 33") == 0);
8836
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2258 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2259 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2260
9938
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9854
diff changeset
2261 { /* Precision with no rounding. */
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9854
diff changeset
2262 int retval =
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9854
diff changeset
2263 my_snprintf (result, sizeof (result), "%.5g %d", 999.951, 33, 44, 55);
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9854
diff changeset
2264 ASSERT (strcmp (result, "999.95 33") == 0);
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9854
diff changeset
2265 ASSERT (retval == strlen (result));
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9854
diff changeset
2266 }
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9854
diff changeset
2267
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9854
diff changeset
2268 { /* Precision with rounding. */
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9854
diff changeset
2269 int retval =
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9854
diff changeset
2270 my_snprintf (result, sizeof (result), "%.5g %d", 999.996, 33, 44, 55);
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9854
diff changeset
2271 ASSERT (strcmp (result, "1000 33") == 0);
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9854
diff changeset
2272 ASSERT (retval == strlen (result));
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9854
diff changeset
2273 }
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9854
diff changeset
2274
8836
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2275 { /* A positive number. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2276 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2277 my_snprintf (result, sizeof (result), "%Lg %d", 12.75L, 33, 44, 55);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2278 ASSERT (strcmp (result, "12.75 33") == 0);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2279 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2280 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2281
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2282 { /* A larger positive number. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2283 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2284 my_snprintf (result, sizeof (result), "%Lg %d", 1234567.0L, 33, 44, 55);
10458
1cc9cffb9615 Allow 3-digit exponents in %e and %g results on 'long double'.
Bruno Haible <bruno@clisp.org>
parents: 10457
diff changeset
2285 ASSERT (strcmp (result, "1.23457e+06 33") == 0
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2286 || strcmp (result, "1.23457e+006 33") == 0);
8836
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2287 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2288 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2289
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2290 { /* Small and large positive numbers. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2291 static struct { long double value; const char *string; } data[] =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2292 {
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2293 { 1.234321234321234e-37L, "1.23432e-37" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2294 { 1.234321234321234e-36L, "1.23432e-36" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2295 { 1.234321234321234e-35L, "1.23432e-35" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2296 { 1.234321234321234e-34L, "1.23432e-34" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2297 { 1.234321234321234e-33L, "1.23432e-33" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2298 { 1.234321234321234e-32L, "1.23432e-32" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2299 { 1.234321234321234e-31L, "1.23432e-31" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2300 { 1.234321234321234e-30L, "1.23432e-30" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2301 { 1.234321234321234e-29L, "1.23432e-29" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2302 { 1.234321234321234e-28L, "1.23432e-28" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2303 { 1.234321234321234e-27L, "1.23432e-27" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2304 { 1.234321234321234e-26L, "1.23432e-26" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2305 { 1.234321234321234e-25L, "1.23432e-25" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2306 { 1.234321234321234e-24L, "1.23432e-24" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2307 { 1.234321234321234e-23L, "1.23432e-23" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2308 { 1.234321234321234e-22L, "1.23432e-22" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2309 { 1.234321234321234e-21L, "1.23432e-21" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2310 { 1.234321234321234e-20L, "1.23432e-20" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2311 { 1.234321234321234e-19L, "1.23432e-19" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2312 { 1.234321234321234e-18L, "1.23432e-18" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2313 { 1.234321234321234e-17L, "1.23432e-17" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2314 { 1.234321234321234e-16L, "1.23432e-16" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2315 { 1.234321234321234e-15L, "1.23432e-15" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2316 { 1.234321234321234e-14L, "1.23432e-14" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2317 { 1.234321234321234e-13L, "1.23432e-13" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2318 { 1.234321234321234e-12L, "1.23432e-12" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2319 { 1.234321234321234e-11L, "1.23432e-11" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2320 { 1.234321234321234e-10L, "1.23432e-10" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2321 { 1.234321234321234e-9L, "1.23432e-09" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2322 { 1.234321234321234e-8L, "1.23432e-08" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2323 { 1.234321234321234e-7L, "1.23432e-07" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2324 { 1.234321234321234e-6L, "1.23432e-06" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2325 { 1.234321234321234e-5L, "1.23432e-05" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2326 { 1.234321234321234e-4L, "0.000123432" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2327 { 1.234321234321234e-3L, "0.00123432" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2328 { 1.234321234321234e-2L, "0.0123432" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2329 { 1.234321234321234e-1L, "0.123432" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2330 { 1.234321234321234L, "1.23432" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2331 { 1.234321234321234e1L, "12.3432" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2332 { 1.234321234321234e2L, "123.432" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2333 { 1.234321234321234e3L, "1234.32" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2334 { 1.234321234321234e4L, "12343.2" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2335 { 1.234321234321234e5L, "123432" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2336 { 1.234321234321234e6L, "1.23432e+06" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2337 { 1.234321234321234e7L, "1.23432e+07" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2338 { 1.234321234321234e8L, "1.23432e+08" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2339 { 1.234321234321234e9L, "1.23432e+09" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2340 { 1.234321234321234e10L, "1.23432e+10" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2341 { 1.234321234321234e11L, "1.23432e+11" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2342 { 1.234321234321234e12L, "1.23432e+12" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2343 { 1.234321234321234e13L, "1.23432e+13" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2344 { 1.234321234321234e14L, "1.23432e+14" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2345 { 1.234321234321234e15L, "1.23432e+15" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2346 { 1.234321234321234e16L, "1.23432e+16" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2347 { 1.234321234321234e17L, "1.23432e+17" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2348 { 1.234321234321234e18L, "1.23432e+18" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2349 { 1.234321234321234e19L, "1.23432e+19" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2350 { 1.234321234321234e20L, "1.23432e+20" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2351 { 1.234321234321234e21L, "1.23432e+21" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2352 { 1.234321234321234e22L, "1.23432e+22" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2353 { 1.234321234321234e23L, "1.23432e+23" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2354 { 1.234321234321234e24L, "1.23432e+24" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2355 { 1.234321234321234e25L, "1.23432e+25" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2356 { 1.234321234321234e26L, "1.23432e+26" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2357 { 1.234321234321234e27L, "1.23432e+27" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2358 { 1.234321234321234e28L, "1.23432e+28" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2359 { 1.234321234321234e29L, "1.23432e+29" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2360 { 1.234321234321234e30L, "1.23432e+30" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2361 { 1.234321234321234e31L, "1.23432e+31" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2362 { 1.234321234321234e32L, "1.23432e+32" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2363 { 1.234321234321234e33L, "1.23432e+33" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2364 { 1.234321234321234e34L, "1.23432e+34" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2365 { 1.234321234321234e35L, "1.23432e+35" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2366 { 1.234321234321234e36L, "1.23432e+36" }
8836
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2367 };
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2368 size_t k;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2369 for (k = 0; k < SIZEOF (data); k++)
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2370 {
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2371 int retval =
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2372 my_snprintf (result, sizeof (result), "%Lg", data[k].value);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2373 const char *expected = data[k].string;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2374 ASSERT (strcmp (result, expected) == 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2375 /* Some implementations produce exponents with 3 digits. */
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2376 || (expected[strlen (expected) - 4] == 'e'
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2377 && strlen (result) == strlen (expected) + 1
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2378 && memcmp (result, expected, strlen (expected) - 2) == 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2379 && result[strlen (expected) - 2] == '0'
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2380 && strcmp (result + strlen (expected) - 1,
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2381 expected + strlen (expected) - 2)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2382 == 0));
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2383 ASSERT (retval == strlen (result));
8836
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2384 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2385 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2386
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2387 { /* A negative number. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2388 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2389 my_snprintf (result, sizeof (result), "%Lg %d", -0.03125L, 33, 44, 55);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2390 ASSERT (strcmp (result, "-0.03125 33") == 0);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2391 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2392 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2393
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2394 { /* Positive zero. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2395 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2396 my_snprintf (result, sizeof (result), "%Lg %d", 0.0L, 33, 44, 55);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2397 ASSERT (strcmp (result, "0 33") == 0);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2398 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2399 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2400
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2401 { /* Negative zero. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2402 int retval =
10601
ca053fa79cd3 Use a more portable replacement expression for -0.0L.
Bruno Haible <bruno@clisp.org>
parents: 10458
diff changeset
2403 my_snprintf (result, sizeof (result), "%Lg %d", minus_zerol, 33, 44, 55);
8852
df0b5e8ea770 Avoid test failures on platforms where -0.0 and 0.0 are identical.
Bruno Haible <bruno@clisp.org>
parents: 8850
diff changeset
2404 if (have_minus_zero ())
df0b5e8ea770 Avoid test failures on platforms where -0.0 and 0.0 are identical.
Bruno Haible <bruno@clisp.org>
parents: 8850
diff changeset
2405 ASSERT (strcmp (result, "-0 33") == 0);
8836
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2406 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2407 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2408
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2409 { /* Positive infinity. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2410 int retval =
15595
328819af1c02 Support for MSVC compiler: Avoid division by a literal 0.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
2411 my_snprintf (result, sizeof (result), "%Lg %d", Infinityl (), 33, 44, 55);
8836
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2412 ASSERT (strcmp (result, "inf 33") == 0
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2413 || strcmp (result, "infinity 33") == 0);
8836
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2414 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2415 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2416
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2417 { /* Negative infinity. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2418 int retval =
15595
328819af1c02 Support for MSVC compiler: Avoid division by a literal 0.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
2419 my_snprintf (result, sizeof (result), "%Lg %d", - Infinityl (), 33, 44, 55);
8836
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2420 ASSERT (strcmp (result, "-inf 33") == 0
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2421 || strcmp (result, "-infinity 33") == 0);
8836
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2422 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2423 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2424
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2425 { /* NaN. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2426 int retval =
9854
baba3b346ab2 Use macros NaNf, NaNd, NaNl instead of NAN.
Bruno Haible <bruno@clisp.org>
parents: 9850
diff changeset
2427 my_snprintf (result, sizeof (result), "%Lg %d", NaNl (), 33, 44, 55);
8850
d1fe16dfbfee Avoid test failures on IRIX 6.5.
Bruno Haible <bruno@clisp.org>
parents: 8839
diff changeset
2428 ASSERT (strlen (result) >= 3 + 3
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2429 && strisnan (result, 0, strlen (result) - 3, 0)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2430 && strcmp (result + strlen (result) - 3, " 33") == 0);
8836
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2431 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2432 }
15906
400649d35651 *printf-posix tests: Fix for platforms where 'long double' == 'double'.
Bruno Haible <bruno@clisp.org>
parents: 15595
diff changeset
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
8919
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8870
diff changeset
2434 { /* Quiet NaN. */
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8870
diff changeset
2435 static union { unsigned int word[4]; long double value; } x =
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8870
diff changeset
2436 { LDBL80_WORDS (0xFFFF, 0xC3333333, 0x00000000) };
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8870
diff changeset
2437 int retval =
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8870
diff changeset
2438 my_snprintf (result, sizeof (result), "%Lg %d", x.value, 33, 44, 55);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8870
diff changeset
2439 ASSERT (strlen (result) >= 3 + 3
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2440 && strisnan (result, 0, strlen (result) - 3, 0)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2441 && strcmp (result + strlen (result) - 3, " 33") == 0);
8919
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8870
diff changeset
2442 ASSERT (retval == strlen (result));
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8870
diff changeset
2443 }
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8870
diff changeset
2444 {
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8870
diff changeset
2445 /* Signalling NaN. */
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8870
diff changeset
2446 static union { unsigned int word[4]; long double value; } x =
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8870
diff changeset
2447 { LDBL80_WORDS (0xFFFF, 0x83333333, 0x00000000) };
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8870
diff changeset
2448 int retval =
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8870
diff changeset
2449 my_snprintf (result, sizeof (result), "%Lg %d", x.value, 33, 44, 55);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8870
diff changeset
2450 ASSERT (strlen (result) >= 3 + 3
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2451 && strisnan (result, 0, strlen (result) - 3, 0)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2452 && strcmp (result + strlen (result) - 3, " 33") == 0);
8919
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8870
diff changeset
2453 ASSERT (retval == strlen (result));
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8870
diff changeset
2454 }
17927
b941bb9e9efb printf, isinf, etc.: noncanonical != NaN
Paul Eggert <eggert@cs.ucla.edu>
parents: 17848
diff changeset
2455 /* snprintf should print something for noncanonical values. */
b941bb9e9efb printf, isinf, etc.: noncanonical != NaN
Paul Eggert <eggert@cs.ucla.edu>
parents: 17848
diff changeset
2456 { /* Pseudo-NaN. */
b941bb9e9efb printf, isinf, etc.: noncanonical != NaN
Paul Eggert <eggert@cs.ucla.edu>
parents: 17848
diff changeset
2457 static union { unsigned int word[4]; long double value; } x =
b941bb9e9efb printf, isinf, etc.: noncanonical != NaN
Paul Eggert <eggert@cs.ucla.edu>
parents: 17848
diff changeset
2458 { LDBL80_WORDS (0xFFFF, 0x40000001, 0x00000000) };
b941bb9e9efb printf, isinf, etc.: noncanonical != NaN
Paul Eggert <eggert@cs.ucla.edu>
parents: 17848
diff changeset
2459 int retval =
b941bb9e9efb printf, isinf, etc.: noncanonical != NaN
Paul Eggert <eggert@cs.ucla.edu>
parents: 17848
diff changeset
2460 my_snprintf (result, sizeof (result), "%Lg %d", x.value, 33, 44, 55);
b941bb9e9efb printf, isinf, etc.: noncanonical != NaN
Paul Eggert <eggert@cs.ucla.edu>
parents: 17848
diff changeset
2461 ASSERT (retval == strlen (result));
b941bb9e9efb printf, isinf, etc.: noncanonical != NaN
Paul Eggert <eggert@cs.ucla.edu>
parents: 17848
diff changeset
2462 ASSERT (3 < retval && strcmp (result + retval - 3, " 33") == 0);
b941bb9e9efb printf, isinf, etc.: noncanonical != NaN
Paul Eggert <eggert@cs.ucla.edu>
parents: 17848
diff changeset
2463 }
b941bb9e9efb printf, isinf, etc.: noncanonical != NaN
Paul Eggert <eggert@cs.ucla.edu>
parents: 17848
diff changeset
2464 { /* Pseudo-Infinity. */
b941bb9e9efb printf, isinf, etc.: noncanonical != NaN
Paul Eggert <eggert@cs.ucla.edu>
parents: 17848
diff changeset
2465 static union { unsigned int word[4]; long double value; } x =
b941bb9e9efb printf, isinf, etc.: noncanonical != NaN
Paul Eggert <eggert@cs.ucla.edu>
parents: 17848
diff changeset
2466 { LDBL80_WORDS (0xFFFF, 0x00000000, 0x00000000) };
b941bb9e9efb printf, isinf, etc.: noncanonical != NaN
Paul Eggert <eggert@cs.ucla.edu>
parents: 17848
diff changeset
2467 int retval =
b941bb9e9efb printf, isinf, etc.: noncanonical != NaN
Paul Eggert <eggert@cs.ucla.edu>
parents: 17848
diff changeset
2468 my_snprintf (result, sizeof (result), "%Lg %d", x.value, 33, 44, 55);
b941bb9e9efb printf, isinf, etc.: noncanonical != NaN
Paul Eggert <eggert@cs.ucla.edu>
parents: 17848
diff changeset
2469 ASSERT (retval == strlen (result));
b941bb9e9efb printf, isinf, etc.: noncanonical != NaN
Paul Eggert <eggert@cs.ucla.edu>
parents: 17848
diff changeset
2470 ASSERT (3 < retval && strcmp (result + retval - 3, " 33") == 0);
b941bb9e9efb printf, isinf, etc.: noncanonical != NaN
Paul Eggert <eggert@cs.ucla.edu>
parents: 17848
diff changeset
2471 }
b941bb9e9efb printf, isinf, etc.: noncanonical != NaN
Paul Eggert <eggert@cs.ucla.edu>
parents: 17848
diff changeset
2472 { /* Pseudo-Zero. */
b941bb9e9efb printf, isinf, etc.: noncanonical != NaN
Paul Eggert <eggert@cs.ucla.edu>
parents: 17848
diff changeset
2473 static union { unsigned int word[4]; long double value; } x =
b941bb9e9efb printf, isinf, etc.: noncanonical != NaN
Paul Eggert <eggert@cs.ucla.edu>
parents: 17848
diff changeset
2474 { LDBL80_WORDS (0x4004, 0x00000000, 0x00000000) };
b941bb9e9efb printf, isinf, etc.: noncanonical != NaN
Paul Eggert <eggert@cs.ucla.edu>
parents: 17848
diff changeset
2475 int retval =
b941bb9e9efb printf, isinf, etc.: noncanonical != NaN
Paul Eggert <eggert@cs.ucla.edu>
parents: 17848
diff changeset
2476 my_snprintf (result, sizeof (result), "%Lg %d", x.value, 33, 44, 55);
b941bb9e9efb printf, isinf, etc.: noncanonical != NaN
Paul Eggert <eggert@cs.ucla.edu>
parents: 17848
diff changeset
2477 ASSERT (retval == strlen (result));
b941bb9e9efb printf, isinf, etc.: noncanonical != NaN
Paul Eggert <eggert@cs.ucla.edu>
parents: 17848
diff changeset
2478 ASSERT (3 < retval && strcmp (result + retval - 3, " 33") == 0);
b941bb9e9efb printf, isinf, etc.: noncanonical != NaN
Paul Eggert <eggert@cs.ucla.edu>
parents: 17848
diff changeset
2479 }
b941bb9e9efb printf, isinf, etc.: noncanonical != NaN
Paul Eggert <eggert@cs.ucla.edu>
parents: 17848
diff changeset
2480 { /* Unnormalized number. */
b941bb9e9efb printf, isinf, etc.: noncanonical != NaN
Paul Eggert <eggert@cs.ucla.edu>
parents: 17848
diff changeset
2481 static union { unsigned int word[4]; long double value; } x =
b941bb9e9efb printf, isinf, etc.: noncanonical != NaN
Paul Eggert <eggert@cs.ucla.edu>
parents: 17848
diff changeset
2482 { LDBL80_WORDS (0x4000, 0x63333333, 0x00000000) };
b941bb9e9efb printf, isinf, etc.: noncanonical != NaN
Paul Eggert <eggert@cs.ucla.edu>
parents: 17848
diff changeset
2483 int retval =
b941bb9e9efb printf, isinf, etc.: noncanonical != NaN
Paul Eggert <eggert@cs.ucla.edu>
parents: 17848
diff changeset
2484 my_snprintf (result, sizeof (result), "%Lg %d", x.value, 33, 44, 55);
b941bb9e9efb printf, isinf, etc.: noncanonical != NaN
Paul Eggert <eggert@cs.ucla.edu>
parents: 17848
diff changeset
2485 ASSERT (retval == strlen (result));
b941bb9e9efb printf, isinf, etc.: noncanonical != NaN
Paul Eggert <eggert@cs.ucla.edu>
parents: 17848
diff changeset
2486 ASSERT (3 < retval && strcmp (result + retval - 3, " 33") == 0);
b941bb9e9efb printf, isinf, etc.: noncanonical != NaN
Paul Eggert <eggert@cs.ucla.edu>
parents: 17848
diff changeset
2487 }
8919
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8870
diff changeset
2488 { /* Pseudo-Denormal. */
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8870
diff changeset
2489 static union { unsigned int word[4]; long double value; } x =
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8870
diff changeset
2490 { LDBL80_WORDS (0x0000, 0x83333333, 0x00000000) };
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8870
diff changeset
2491 int retval =
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8870
diff changeset
2492 my_snprintf (result, sizeof (result), "%Lg %d", x.value, 33, 44, 55);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8870
diff changeset
2493 ASSERT (retval == strlen (result));
17927
b941bb9e9efb printf, isinf, etc.: noncanonical != NaN
Paul Eggert <eggert@cs.ucla.edu>
parents: 17848
diff changeset
2494 ASSERT (3 < retval && strcmp (result + retval - 3, " 33") == 0);
8919
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8870
diff changeset
2495 }
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8870
diff changeset
2496 #endif
8836
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2497
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2498 { /* Width. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2499 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2500 my_snprintf (result, sizeof (result), "%10Lg %d", 1.75L, 33, 44, 55);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2501 ASSERT (strcmp (result, " 1.75 33") == 0);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2502 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2503 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2504
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2505 { /* FLAG_LEFT. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2506 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2507 my_snprintf (result, sizeof (result), "%-10Lg %d", 1.75L, 33, 44, 55);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2508 ASSERT (strcmp (result, "1.75 33") == 0);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2509 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2510 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2511
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2512 { /* FLAG_SHOWSIGN. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2513 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2514 my_snprintf (result, sizeof (result), "%+Lg %d", 1.75L, 33, 44, 55);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2515 ASSERT (strcmp (result, "+1.75 33") == 0);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2516 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2517 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2518
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2519 { /* FLAG_SPACE. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2520 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2521 my_snprintf (result, sizeof (result), "% Lg %d", 1.75L, 33, 44, 55);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2522 ASSERT (strcmp (result, " 1.75 33") == 0);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2523 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2524 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2525
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2526 { /* FLAG_ALT. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2527 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2528 my_snprintf (result, sizeof (result), "%#Lg %d", 1.75L, 33, 44, 55);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2529 ASSERT (strcmp (result, "1.75000 33") == 0);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2530 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2531 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2532
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2533 { /* FLAG_ALT. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2534 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2535 my_snprintf (result, sizeof (result), "%#.Lg %d", 1.75L, 33, 44, 55);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2536 ASSERT (strcmp (result, "2. 33") == 0);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2537 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2538 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2539
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2540 { /* FLAG_ALT. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2541 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2542 my_snprintf (result, sizeof (result), "%#.Lg %d", 9.75L, 33, 44, 55);
10458
1cc9cffb9615 Allow 3-digit exponents in %e and %g results on 'long double'.
Bruno Haible <bruno@clisp.org>
parents: 10457
diff changeset
2543 ASSERT (strcmp (result, "1.e+01 33") == 0
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2544 || strcmp (result, "1.e+001 33") == 0);
8836
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2545 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2546 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2547
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2548 { /* FLAG_ZERO with finite number. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2549 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2550 my_snprintf (result, sizeof (result), "%010Lg %d", 1234.0L, 33, 44, 55);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2551 ASSERT (strcmp (result, "0000001234 33") == 0);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2552 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2553 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2554
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2555 { /* FLAG_ZERO with infinite number. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2556 int retval =
15595
328819af1c02 Support for MSVC compiler: Avoid division by a literal 0.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
2557 my_snprintf (result, sizeof (result), "%015Lg %d", - Infinityl (), 33, 44, 55);
8836
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2558 ASSERT (strcmp (result, " -inf 33") == 0
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2559 || strcmp (result, " -infinity 33") == 0);
8836
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2560 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2561 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2562
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2563 { /* FLAG_ZERO with NaN. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2564 int retval =
9854
baba3b346ab2 Use macros NaNf, NaNd, NaNl instead of NAN.
Bruno Haible <bruno@clisp.org>
parents: 9850
diff changeset
2565 my_snprintf (result, sizeof (result), "%050Lg %d", NaNl (), 33, 44, 55);
8870
4e1f2ea486b4 Allow for a longer printed representation of NaN.
Bruno Haible <bruno@clisp.org>
parents: 8865
diff changeset
2566 ASSERT (strlen (result) == 50 + 3
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2567 && strisnan (result, strspn (result, " "), strlen (result) - 3, 0)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2568 && strcmp (result + strlen (result) - 3, " 33") == 0);
8836
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2569 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2570 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2571
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2572 { /* Precision. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2573 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2574 my_snprintf (result, sizeof (result), "%.Lg %d", 1234.0L, 33, 44, 55);
10458
1cc9cffb9615 Allow 3-digit exponents in %e and %g results on 'long double'.
Bruno Haible <bruno@clisp.org>
parents: 10457
diff changeset
2575 ASSERT (strcmp (result, "1e+03 33") == 0
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2576 || strcmp (result, "1e+003 33") == 0);
8836
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2577 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2578 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2579
9938
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9854
diff changeset
2580 { /* Precision with no rounding. */
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9854
diff changeset
2581 int retval =
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9854
diff changeset
2582 my_snprintf (result, sizeof (result), "%.5Lg %d", 999.951L, 33, 44, 55);
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9854
diff changeset
2583 ASSERT (strcmp (result, "999.95 33") == 0);
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9854
diff changeset
2584 ASSERT (retval == strlen (result));
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9854
diff changeset
2585 }
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9854
diff changeset
2586
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9854
diff changeset
2587 { /* Precision with rounding. */
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9854
diff changeset
2588 int retval =
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9854
diff changeset
2589 my_snprintf (result, sizeof (result), "%.5Lg %d", 999.996L, 33, 44, 55);
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9854
diff changeset
2590 ASSERT (strcmp (result, "1000 33") == 0);
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9854
diff changeset
2591 ASSERT (retval == strlen (result));
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9854
diff changeset
2592 }
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9854
diff changeset
2593
8364
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
2594 /* Test the support of the %n format directive. */
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
2595
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
2596 {
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
2597 int count = -1;
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
2598 int retval =
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
2599 my_snprintf (result, sizeof (result), "%d %n", 123, &count, 33, 44, 55);
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
2600 ASSERT (strcmp (result, "123 ") == 0);
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
2601 ASSERT (retval == strlen (result));
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
2602 ASSERT (count == 4);
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
2603 }
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
2604
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
2605 /* Test the support of the POSIX/XSI format strings with positions. */
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
2606
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
2607 {
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
2608 int retval =
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
2609 my_snprintf (result, sizeof (result), "%2$d %1$d", 33, 55);
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
2610 ASSERT (strcmp (result, "55 33") == 0);
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
2611 ASSERT (retval == strlen (result));
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
2612 }
8803
6c1d98929550 Work around lack of support of grouping flag.
Bruno Haible <bruno@clisp.org>
parents: 8684
diff changeset
2613
6c1d98929550 Work around lack of support of grouping flag.
Bruno Haible <bruno@clisp.org>
parents: 8684
diff changeset
2614 /* Test the support of the grouping flag. */
6c1d98929550 Work around lack of support of grouping flag.
Bruno Haible <bruno@clisp.org>
parents: 8684
diff changeset
2615
6c1d98929550 Work around lack of support of grouping flag.
Bruno Haible <bruno@clisp.org>
parents: 8684
diff changeset
2616 {
6c1d98929550 Work around lack of support of grouping flag.
Bruno Haible <bruno@clisp.org>
parents: 8684
diff changeset
2617 int retval =
6c1d98929550 Work around lack of support of grouping flag.
Bruno Haible <bruno@clisp.org>
parents: 8684
diff changeset
2618 my_snprintf (result, sizeof (result), "%'d %d", 1234567, 99);
6c1d98929550 Work around lack of support of grouping flag.
Bruno Haible <bruno@clisp.org>
parents: 8684
diff changeset
2619 ASSERT (result[strlen (result) - 1] == '9');
6c1d98929550 Work around lack of support of grouping flag.
Bruno Haible <bruno@clisp.org>
parents: 8684
diff changeset
2620 ASSERT (retval == strlen (result));
6c1d98929550 Work around lack of support of grouping flag.
Bruno Haible <bruno@clisp.org>
parents: 8684
diff changeset
2621 }
9447
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
2622
9674
b69f1141e94f Fix *printf behaviour regarding the left-adjust flag on HP-UX 10.20.
Bruno Haible <bruno@clisp.org>
parents: 9447
diff changeset
2623 /* Test the support of the left-adjust flag. */
b69f1141e94f Fix *printf behaviour regarding the left-adjust flag on HP-UX 10.20.
Bruno Haible <bruno@clisp.org>
parents: 9447
diff changeset
2624
b69f1141e94f Fix *printf behaviour regarding the left-adjust flag on HP-UX 10.20.
Bruno Haible <bruno@clisp.org>
parents: 9447
diff changeset
2625 {
b69f1141e94f Fix *printf behaviour regarding the left-adjust flag on HP-UX 10.20.
Bruno Haible <bruno@clisp.org>
parents: 9447
diff changeset
2626 int retval =
b69f1141e94f Fix *printf behaviour regarding the left-adjust flag on HP-UX 10.20.
Bruno Haible <bruno@clisp.org>
parents: 9447
diff changeset
2627 my_snprintf (result, sizeof (result), "a%*sc", -3, "b");
b69f1141e94f Fix *printf behaviour regarding the left-adjust flag on HP-UX 10.20.
Bruno Haible <bruno@clisp.org>
parents: 9447
diff changeset
2628 ASSERT (strcmp (result, "ab c") == 0);
b69f1141e94f Fix *printf behaviour regarding the left-adjust flag on HP-UX 10.20.
Bruno Haible <bruno@clisp.org>
parents: 9447
diff changeset
2629 ASSERT (retval == strlen (result));
b69f1141e94f Fix *printf behaviour regarding the left-adjust flag on HP-UX 10.20.
Bruno Haible <bruno@clisp.org>
parents: 9447
diff changeset
2630 }
b69f1141e94f Fix *printf behaviour regarding the left-adjust flag on HP-UX 10.20.
Bruno Haible <bruno@clisp.org>
parents: 9447
diff changeset
2631
b69f1141e94f Fix *printf behaviour regarding the left-adjust flag on HP-UX 10.20.
Bruno Haible <bruno@clisp.org>
parents: 9447
diff changeset
2632 {
b69f1141e94f Fix *printf behaviour regarding the left-adjust flag on HP-UX 10.20.
Bruno Haible <bruno@clisp.org>
parents: 9447
diff changeset
2633 int retval =
b69f1141e94f Fix *printf behaviour regarding the left-adjust flag on HP-UX 10.20.
Bruno Haible <bruno@clisp.org>
parents: 9447
diff changeset
2634 my_snprintf (result, sizeof (result), "a%-*sc", 3, "b");
b69f1141e94f Fix *printf behaviour regarding the left-adjust flag on HP-UX 10.20.
Bruno Haible <bruno@clisp.org>
parents: 9447
diff changeset
2635 ASSERT (strcmp (result, "ab c") == 0);
b69f1141e94f Fix *printf behaviour regarding the left-adjust flag on HP-UX 10.20.
Bruno Haible <bruno@clisp.org>
parents: 9447
diff changeset
2636 ASSERT (retval == strlen (result));
b69f1141e94f Fix *printf behaviour regarding the left-adjust flag on HP-UX 10.20.
Bruno Haible <bruno@clisp.org>
parents: 9447
diff changeset
2637 }
b69f1141e94f Fix *printf behaviour regarding the left-adjust flag on HP-UX 10.20.
Bruno Haible <bruno@clisp.org>
parents: 9447
diff changeset
2638
b69f1141e94f Fix *printf behaviour regarding the left-adjust flag on HP-UX 10.20.
Bruno Haible <bruno@clisp.org>
parents: 9447
diff changeset
2639 {
b69f1141e94f Fix *printf behaviour regarding the left-adjust flag on HP-UX 10.20.
Bruno Haible <bruno@clisp.org>
parents: 9447
diff changeset
2640 int retval =
b69f1141e94f Fix *printf behaviour regarding the left-adjust flag on HP-UX 10.20.
Bruno Haible <bruno@clisp.org>
parents: 9447
diff changeset
2641 my_snprintf (result, sizeof (result), "a%-*sc", -3, "b");
b69f1141e94f Fix *printf behaviour regarding the left-adjust flag on HP-UX 10.20.
Bruno Haible <bruno@clisp.org>
parents: 9447
diff changeset
2642 ASSERT (strcmp (result, "ab c") == 0);
b69f1141e94f Fix *printf behaviour regarding the left-adjust flag on HP-UX 10.20.
Bruno Haible <bruno@clisp.org>
parents: 9447
diff changeset
2643 ASSERT (retval == strlen (result));
b69f1141e94f Fix *printf behaviour regarding the left-adjust flag on HP-UX 10.20.
Bruno Haible <bruno@clisp.org>
parents: 9447
diff changeset
2644 }
b69f1141e94f Fix *printf behaviour regarding the left-adjust flag on HP-UX 10.20.
Bruno Haible <bruno@clisp.org>
parents: 9447
diff changeset
2645
9447
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
2646 /* Test the support of large precision. */
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
2647
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
2648 {
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
2649 int retval =
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
2650 my_snprintf (result, sizeof (result), "%.4000d %d", 1234567, 99);
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
2651 size_t i;
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
2652 for (i = 0; i < 4000 - 7; i++)
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
2653 ASSERT (result[i] == '0');
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
2654 ASSERT (strcmp (result + 4000 - 7, "1234567 99") == 0);
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
2655 ASSERT (retval == strlen (result));
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
2656 }
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
2657
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
2658 {
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
2659 int retval =
10394
4b3ac67aa7bc vasnprintf-posix: handle large precision via %.*d
Eric Blake <ebb9@byu.net>
parents: 10296
diff changeset
2660 my_snprintf (result, sizeof (result), "%.*d %d", 4000, 1234567, 99);
4b3ac67aa7bc vasnprintf-posix: handle large precision via %.*d
Eric Blake <ebb9@byu.net>
parents: 10296
diff changeset
2661 size_t i;
4b3ac67aa7bc vasnprintf-posix: handle large precision via %.*d
Eric Blake <ebb9@byu.net>
parents: 10296
diff changeset
2662 for (i = 0; i < 4000 - 7; i++)
4b3ac67aa7bc vasnprintf-posix: handle large precision via %.*d
Eric Blake <ebb9@byu.net>
parents: 10296
diff changeset
2663 ASSERT (result[i] == '0');
4b3ac67aa7bc vasnprintf-posix: handle large precision via %.*d
Eric Blake <ebb9@byu.net>
parents: 10296
diff changeset
2664 ASSERT (strcmp (result + 4000 - 7, "1234567 99") == 0);
4b3ac67aa7bc vasnprintf-posix: handle large precision via %.*d
Eric Blake <ebb9@byu.net>
parents: 10296
diff changeset
2665 ASSERT (retval == strlen (result));
4b3ac67aa7bc vasnprintf-posix: handle large precision via %.*d
Eric Blake <ebb9@byu.net>
parents: 10296
diff changeset
2666 }
4b3ac67aa7bc vasnprintf-posix: handle large precision via %.*d
Eric Blake <ebb9@byu.net>
parents: 10296
diff changeset
2667
4b3ac67aa7bc vasnprintf-posix: handle large precision via %.*d
Eric Blake <ebb9@byu.net>
parents: 10296
diff changeset
2668 {
4b3ac67aa7bc vasnprintf-posix: handle large precision via %.*d
Eric Blake <ebb9@byu.net>
parents: 10296
diff changeset
2669 int retval =
9447
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
2670 my_snprintf (result, sizeof (result), "%.4000d %d", -1234567, 99);
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
2671 size_t i;
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
2672 ASSERT (result[0] == '-');
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
2673 for (i = 0; i < 4000 - 7; i++)
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
2674 ASSERT (result[1 + i] == '0');
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
2675 ASSERT (strcmp (result + 1 + 4000 - 7, "1234567 99") == 0);
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
2676 ASSERT (retval == strlen (result));
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
2677 }
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
2678
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
2679 {
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
2680 int retval =
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
2681 my_snprintf (result, sizeof (result), "%.4000u %d", 1234567, 99);
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
2682 size_t i;
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
2683 for (i = 0; i < 4000 - 7; i++)
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
2684 ASSERT (result[i] == '0');
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
2685 ASSERT (strcmp (result + 4000 - 7, "1234567 99") == 0);
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
2686 ASSERT (retval == strlen (result));
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
2687 }
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
2688
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
2689 {
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
2690 int retval =
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
2691 my_snprintf (result, sizeof (result), "%.4000o %d", 1234567, 99);
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
2692 size_t i;
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
2693 for (i = 0; i < 4000 - 7; i++)
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
2694 ASSERT (result[i] == '0');
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
2695 ASSERT (strcmp (result + 4000 - 7, "4553207 99") == 0);
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
2696 ASSERT (retval == strlen (result));
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
2697 }
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
2698
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
2699 {
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
2700 int retval =
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
2701 my_snprintf (result, sizeof (result), "%.4000x %d", 1234567, 99);
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
2702 size_t i;
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
2703 for (i = 0; i < 4000 - 6; i++)
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
2704 ASSERT (result[i] == '0');
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
2705 ASSERT (strcmp (result + 4000 - 6, "12d687 99") == 0);
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
2706 ASSERT (retval == strlen (result));
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
2707 }
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
2708
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
2709 {
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
2710 int retval =
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
2711 my_snprintf (result, sizeof (result), "%#.4000x %d", 1234567, 99);
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
2712 size_t i;
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
2713 ASSERT (result[0] == '0');
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
2714 ASSERT (result[1] == 'x');
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
2715 for (i = 0; i < 4000 - 6; i++)
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
2716 ASSERT (result[2 + i] == '0');
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
2717 ASSERT (strcmp (result + 2 + 4000 - 6, "12d687 99") == 0);
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
2718 ASSERT (retval == strlen (result));
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
2719 }
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
2720
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
2721 {
13908
4b4e2b0d175e *printf-posix: Detect a bug on Solaris 10/x86.
Bruno Haible <bruno@clisp.org>
parents: 13834
diff changeset
2722 int retval =
4b4e2b0d175e *printf-posix: Detect a bug on Solaris 10/x86.
Bruno Haible <bruno@clisp.org>
parents: 13834
diff changeset
2723 my_snprintf (result, sizeof (result), "%.4000f %d", 1.0, 99);
4b4e2b0d175e *printf-posix: Detect a bug on Solaris 10/x86.
Bruno Haible <bruno@clisp.org>
parents: 13834
diff changeset
2724 size_t i;
4b4e2b0d175e *printf-posix: Detect a bug on Solaris 10/x86.
Bruno Haible <bruno@clisp.org>
parents: 13834
diff changeset
2725 ASSERT (result[0] == '1');
4b4e2b0d175e *printf-posix: Detect a bug on Solaris 10/x86.
Bruno Haible <bruno@clisp.org>
parents: 13834
diff changeset
2726 ASSERT (result[1] == '.');
4b4e2b0d175e *printf-posix: Detect a bug on Solaris 10/x86.
Bruno Haible <bruno@clisp.org>
parents: 13834
diff changeset
2727 for (i = 0; i < 4000; i++)
4b4e2b0d175e *printf-posix: Detect a bug on Solaris 10/x86.
Bruno Haible <bruno@clisp.org>
parents: 13834
diff changeset
2728 ASSERT (result[2 + i] == '0');
4b4e2b0d175e *printf-posix: Detect a bug on Solaris 10/x86.
Bruno Haible <bruno@clisp.org>
parents: 13834
diff changeset
2729 ASSERT (strcmp (result + 2 + 4000, " 99") == 0);
4b4e2b0d175e *printf-posix: Detect a bug on Solaris 10/x86.
Bruno Haible <bruno@clisp.org>
parents: 13834
diff changeset
2730 ASSERT (retval == strlen (result));
4b4e2b0d175e *printf-posix: Detect a bug on Solaris 10/x86.
Bruno Haible <bruno@clisp.org>
parents: 13834
diff changeset
2731 }
4b4e2b0d175e *printf-posix: Detect a bug on Solaris 10/x86.
Bruno Haible <bruno@clisp.org>
parents: 13834
diff changeset
2732
4b4e2b0d175e *printf-posix: Detect a bug on Solaris 10/x86.
Bruno Haible <bruno@clisp.org>
parents: 13834
diff changeset
2733 {
14005
f585ecc144aa *printf: Detect large precisions bug on Solaris 10/SPARC.
Bruno Haible <bruno@clisp.org>
parents: 13908
diff changeset
2734 int retval =
f585ecc144aa *printf: Detect large precisions bug on Solaris 10/SPARC.
Bruno Haible <bruno@clisp.org>
parents: 13908
diff changeset
2735 my_snprintf (result, sizeof (result), "%.511f %d", 1.0, 99);
f585ecc144aa *printf: Detect large precisions bug on Solaris 10/SPARC.
Bruno Haible <bruno@clisp.org>
parents: 13908
diff changeset
2736 size_t i;
f585ecc144aa *printf: Detect large precisions bug on Solaris 10/SPARC.
Bruno Haible <bruno@clisp.org>
parents: 13908
diff changeset
2737 ASSERT (result[0] == '1');
f585ecc144aa *printf: Detect large precisions bug on Solaris 10/SPARC.
Bruno Haible <bruno@clisp.org>
parents: 13908
diff changeset
2738 ASSERT (result[1] == '.');
f585ecc144aa *printf: Detect large precisions bug on Solaris 10/SPARC.
Bruno Haible <bruno@clisp.org>
parents: 13908
diff changeset
2739 for (i = 0; i < 511; i++)
f585ecc144aa *printf: Detect large precisions bug on Solaris 10/SPARC.
Bruno Haible <bruno@clisp.org>
parents: 13908
diff changeset
2740 ASSERT (result[2 + i] == '0');
f585ecc144aa *printf: Detect large precisions bug on Solaris 10/SPARC.
Bruno Haible <bruno@clisp.org>
parents: 13908
diff changeset
2741 ASSERT (strcmp (result + 2 + 511, " 99") == 0);
f585ecc144aa *printf: Detect large precisions bug on Solaris 10/SPARC.
Bruno Haible <bruno@clisp.org>
parents: 13908
diff changeset
2742 ASSERT (retval == strlen (result));
f585ecc144aa *printf: Detect large precisions bug on Solaris 10/SPARC.
Bruno Haible <bruno@clisp.org>
parents: 13908
diff changeset
2743 }
f585ecc144aa *printf: Detect large precisions bug on Solaris 10/SPARC.
Bruno Haible <bruno@clisp.org>
parents: 13908
diff changeset
2744
f585ecc144aa *printf: Detect large precisions bug on Solaris 10/SPARC.
Bruno Haible <bruno@clisp.org>
parents: 13908
diff changeset
2745 {
9447
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
2746 char input[5000];
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
2747 int retval;
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
2748 size_t i;
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
2749
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
2750 for (i = 0; i < sizeof (input) - 1; i++)
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
2751 input[i] = 'a' + ((1000000 / (i + 1)) % 26);
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
2752 input[i] = '\0';
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
2753 retval = my_snprintf (result, sizeof (result), "%.4000s %d", input, 99);
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
2754 ASSERT (memcmp (result, input, 4000) == 0);
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
2755 ASSERT (strcmp (result + 4000, " 99") == 0);
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
2756 ASSERT (retval == strlen (result));
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
2757 }
11207
4daf474e9033 vasnprintf: Fix invalid read past end of memory block.
Bruno Haible <bruno@clisp.org>
parents: 11002
diff changeset
2758
4daf474e9033 vasnprintf: Fix invalid read past end of memory block.
Bruno Haible <bruno@clisp.org>
parents: 11002
diff changeset
2759 /* Test the support of the %s format directive. */
4daf474e9033 vasnprintf: Fix invalid read past end of memory block.
Bruno Haible <bruno@clisp.org>
parents: 11002
diff changeset
2760
4daf474e9033 vasnprintf: Fix invalid read past end of memory block.
Bruno Haible <bruno@clisp.org>
parents: 11002
diff changeset
2761 /* To verify that these tests succeed, it is necessary to run them under
4daf474e9033 vasnprintf: Fix invalid read past end of memory block.
Bruno Haible <bruno@clisp.org>
parents: 11002
diff changeset
2762 a tool that checks against invalid memory accesses, such as ElectricFence
4daf474e9033 vasnprintf: Fix invalid read past end of memory block.
Bruno Haible <bruno@clisp.org>
parents: 11002
diff changeset
2763 or "valgrind --tool=memcheck". */
4daf474e9033 vasnprintf: Fix invalid read past end of memory block.
Bruno Haible <bruno@clisp.org>
parents: 11002
diff changeset
2764 {
4daf474e9033 vasnprintf: Fix invalid read past end of memory block.
Bruno Haible <bruno@clisp.org>
parents: 11002
diff changeset
2765 size_t i;
4daf474e9033 vasnprintf: Fix invalid read past end of memory block.
Bruno Haible <bruno@clisp.org>
parents: 11002
diff changeset
2766
4daf474e9033 vasnprintf: Fix invalid read past end of memory block.
Bruno Haible <bruno@clisp.org>
parents: 11002
diff changeset
2767 for (i = 1; i <= 8; i++)
4daf474e9033 vasnprintf: Fix invalid read past end of memory block.
Bruno Haible <bruno@clisp.org>
parents: 11002
diff changeset
2768 {
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2769 char *block;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2770 int retval;
11207
4daf474e9033 vasnprintf: Fix invalid read past end of memory block.
Bruno Haible <bruno@clisp.org>
parents: 11002
diff changeset
2771
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2772 block = (char *) malloc (i);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2773 memcpy (block, "abcdefgh", i);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2774 retval = my_snprintf (result, sizeof (result), "%.*s", (int) i, block);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2775 ASSERT (memcmp (result, block, i) == 0);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2776 ASSERT (result[i] == '\0');
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2777 ASSERT (retval == strlen (result));
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2778 free (block);
11207
4daf474e9033 vasnprintf: Fix invalid read past end of memory block.
Bruno Haible <bruno@clisp.org>
parents: 11002
diff changeset
2779 }
4daf474e9033 vasnprintf: Fix invalid read past end of memory block.
Bruno Haible <bruno@clisp.org>
parents: 11002
diff changeset
2780 }
4daf474e9033 vasnprintf: Fix invalid read past end of memory block.
Bruno Haible <bruno@clisp.org>
parents: 11002
diff changeset
2781 #if HAVE_WCHAR_T
4daf474e9033 vasnprintf: Fix invalid read past end of memory block.
Bruno Haible <bruno@clisp.org>
parents: 11002
diff changeset
2782 {
4daf474e9033 vasnprintf: Fix invalid read past end of memory block.
Bruno Haible <bruno@clisp.org>
parents: 11002
diff changeset
2783 size_t i;
4daf474e9033 vasnprintf: Fix invalid read past end of memory block.
Bruno Haible <bruno@clisp.org>
parents: 11002
diff changeset
2784
4daf474e9033 vasnprintf: Fix invalid read past end of memory block.
Bruno Haible <bruno@clisp.org>
parents: 11002
diff changeset
2785 for (i = 1; i <= 8; i++)
4daf474e9033 vasnprintf: Fix invalid read past end of memory block.
Bruno Haible <bruno@clisp.org>
parents: 11002
diff changeset
2786 {
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2787 wchar_t *block;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2788 size_t j;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2789 int retval;
11207
4daf474e9033 vasnprintf: Fix invalid read past end of memory block.
Bruno Haible <bruno@clisp.org>
parents: 11002
diff changeset
2790
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2791 block = (wchar_t *) malloc (i * sizeof (wchar_t));
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2792 for (j = 0; j < i; j++)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2793 block[j] = "abcdefgh"[j];
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2794 retval = my_snprintf (result, sizeof (result), "%.*ls", (int) i, block);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2795 ASSERT (memcmp (result, "abcdefgh", i) == 0);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2796 ASSERT (result[i] == '\0');
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2797 ASSERT (retval == strlen (result));
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2798 free (block);
11207
4daf474e9033 vasnprintf: Fix invalid read past end of memory block.
Bruno Haible <bruno@clisp.org>
parents: 11002
diff changeset
2799 }
4daf474e9033 vasnprintf: Fix invalid read past end of memory block.
Bruno Haible <bruno@clisp.org>
parents: 11002
diff changeset
2800 }
4daf474e9033 vasnprintf: Fix invalid read past end of memory block.
Bruno Haible <bruno@clisp.org>
parents: 11002
diff changeset
2801 #endif
8364
6b68eeda7e0a Test for gnulib modules 'snprintf-posix' and 'vsnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
2802 }