annotate tests/test-vasprintf-posix.c @ 17476:6057744acd2c default tip master

autoupdate
author Karl Berry <karl@freefriends.org>
date Fri, 16 Aug 2013 06:32:22 -0700 (2013-08-16)
parents 35650a3443e8
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8342
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1 /* Test of POSIX compatible vasprintf() and asprintf() functions.
17249
e542fd46ad6f maint: update all copyright year number ranges
Eric Blake <eblake@redhat.com>
parents: 16935
diff changeset
2 Copyright (C) 2007-2013 Free Software Foundation, Inc.
8342
504f056f113a Tests for module 'vasprintf-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
8342
504f056f113a Tests for module 'vasprintf-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.
8342
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
8
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
9 This program is distributed in the hope that it will be useful,
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
12 GNU General Public License for more details.
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
13
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
14 You should have received a copy of the GNU General Public License
9309
bbbbbf4cd1c5 Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 8919
diff changeset
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
8342
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
16
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
17 /* Written by Bruno Haible <bruno@clisp.org>, 2007. */
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
18
8891
633babea5f62 Unconditionally include <config.h> in unit tests.
Eric Blake <ebb9@byu.net>
parents: 8870
diff changeset
19 #include <config.h>
8342
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
20
8570
4175c39ba7cc Move vasprintf prototypes to stdio.
Simon Josefsson <simon@josefsson.org>
parents: 8543
diff changeset
21 #include <stdio.h>
8342
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
22
8919
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
23 #include <float.h>
8342
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
24 #include <stdarg.h>
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
25 #include <stddef.h>
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
26 #include <stdint.h>
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
27 #include <stdlib.h>
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
28 #include <string.h>
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
29
12496
a48d3d749ca5 Refactor common macros used in tests.
Bruno Haible <bruno@clisp.org>
parents: 12421
diff changeset
30 #include "macros.h"
13834
108bbfd6f03b frexp, tests: work around ICC bug with -zero
Eric Blake <eblake@redhat.com>
parents: 12559
diff changeset
31 #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
32 #include "infinity.h"
9854
baba3b346ab2 Use macros NaNf, NaNd, NaNl instead of NAN.
Bruno Haible <bruno@clisp.org>
parents: 9850
diff changeset
33 #include "nan.h"
baba3b346ab2 Use macros NaNf, NaNd, NaNl instead of NAN.
Bruno Haible <bruno@clisp.org>
parents: 9850
diff changeset
34
8852
df0b5e8ea770 Avoid test failures on platforms where -0.0 and 0.0 are identical.
Bruno Haible <bruno@clisp.org>
parents: 8850
diff changeset
35 /* 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
36 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
37 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
38 {
df0b5e8ea770 Avoid test failures on platforms where -0.0 and 0.0 are identical.
Bruno Haible <bruno@clisp.org>
parents: 8850
diff changeset
39 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
40 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
41 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
42 }
df0b5e8ea770 Avoid test failures on platforms where -0.0 and 0.0 are identical.
Bruno Haible <bruno@clisp.org>
parents: 8850
diff changeset
43
8919
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
44 /* 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: 8891
diff changeset
45 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: 8891
diff changeset
46 #ifdef WORDS_BIGENDIAN
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
47 # 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: 8891
diff changeset
48 { ((unsigned int) (exponent) << 16) | ((unsigned int) (manthi) >> 16), \
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
49 ((unsigned int) (manthi) << 16) | (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: 8891
diff changeset
50 (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: 8891
diff changeset
51 }
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
52 #else
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
53 # 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: 8891
diff changeset
54 { mantlo, manthi, exponent }
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
55 #endif
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
56
8834
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
57 static int
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
58 strmatch (const char *pattern, const char *string)
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
59 {
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
60 if (strlen (pattern) != strlen (string))
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
61 return 0;
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
62 for (; *pattern != '\0'; pattern++, string++)
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
63 if (*pattern != '*' && *string != *pattern)
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
64 return 0;
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
65 return 1;
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
66 }
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
67
8865
9e203d8ade65 Stricter check for printf result for NaN arguments.
Bruno Haible <bruno@clisp.org>
parents: 8857
diff changeset
68 /* 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
69 representation of NaN. */
9e203d8ade65 Stricter check for printf result for NaN arguments.
Bruno Haible <bruno@clisp.org>
parents: 8857
diff changeset
70 static int
9e203d8ade65 Stricter check for printf result for NaN arguments.
Bruno Haible <bruno@clisp.org>
parents: 8857
diff changeset
71 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
72 {
9e203d8ade65 Stricter check for printf result for NaN arguments.
Bruno Haible <bruno@clisp.org>
parents: 8857
diff changeset
73 if (start_index < end_index)
9e203d8ade65 Stricter check for printf result for NaN arguments.
Bruno Haible <bruno@clisp.org>
parents: 8857
diff changeset
74 {
9e203d8ade65 Stricter check for printf result for NaN arguments.
Bruno Haible <bruno@clisp.org>
parents: 8857
diff changeset
75 if (string[start_index] == '-')
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
76 start_index++;
8865
9e203d8ade65 Stricter check for printf result for NaN arguments.
Bruno Haible <bruno@clisp.org>
parents: 8857
diff changeset
77 if (start_index + 3 <= end_index
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
78 && 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
79 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
80 start_index += 3;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
81 if (start_index == end_index
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
82 || (string[start_index] == '(' && string[end_index - 1] == ')'))
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
83 return 1;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
84 }
8865
9e203d8ade65 Stricter check for printf result for NaN arguments.
Bruno Haible <bruno@clisp.org>
parents: 8857
diff changeset
85 }
9e203d8ade65 Stricter check for printf result for NaN arguments.
Bruno Haible <bruno@clisp.org>
parents: 8857
diff changeset
86 return 0;
9e203d8ade65 Stricter check for printf result for NaN arguments.
Bruno Haible <bruno@clisp.org>
parents: 8857
diff changeset
87 }
9850
7f3ed6b093be Guarantee a definition of NAN.
Eric Blake <ebb9@byu.net>
parents: 9674
diff changeset
88
8342
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
89 static void
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
90 test_function (int (*my_asprintf) (char **, const char *, ...))
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
91 {
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
92 int repeat;
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
93
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
94 /* Test return value convention. */
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
95
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
96 for (repeat = 0; repeat <= 8; repeat++)
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
97 {
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
98 char *result;
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
99 int retval = asprintf (&result, "%d", 12345);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
100 ASSERT (retval == 5);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
101 ASSERT (result != NULL);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
102 ASSERT (strcmp (result, "12345") == 0);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
103 free (result);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
104 }
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
105
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
106 /* Test support of size specifiers as in C99. */
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
107
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
108 {
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
109 char *result;
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
110 int retval =
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
111 my_asprintf (&result, "%ju %d", (uintmax_t) 12345671, 33, 44, 55);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
112 ASSERT (result != NULL);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
113 ASSERT (strcmp (result, "12345671 33") == 0);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
114 ASSERT (retval == strlen (result));
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
115 free (result);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
116 }
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
117
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
118 {
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
119 char *result;
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
120 int retval =
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
121 my_asprintf (&result, "%zu %d", (size_t) 12345672, 33, 44, 55);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
122 ASSERT (result != NULL);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
123 ASSERT (strcmp (result, "12345672 33") == 0);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
124 ASSERT (retval == strlen (result));
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
125 free (result);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
126 }
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
127
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
128 {
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
129 char *result;
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
130 int retval =
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
131 my_asprintf (&result, "%tu %d", (ptrdiff_t) 12345673, 33, 44, 55);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
132 ASSERT (result != NULL);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
133 ASSERT (strcmp (result, "12345673 33") == 0);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
134 ASSERT (retval == strlen (result));
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
135 free (result);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
136 }
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
137
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
138 {
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
139 char *result;
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
140 int retval =
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
141 my_asprintf (&result, "%Lg %d", (long double) 1.5, 33, 44, 55);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
142 ASSERT (result != NULL);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
143 ASSERT (strcmp (result, "1.5 33") == 0);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
144 ASSERT (retval == strlen (result));
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
145 free (result);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
146 }
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
147
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
148 /* Test the support of the 'a' and 'A' conversion specifier for hexadecimal
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
149 output of floating-point numbers. */
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
150
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
151 { /* A positive number. */
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
152 char *result;
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
153 int retval =
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
154 my_asprintf (&result, "%a %d", 3.1416015625, 33, 44, 55);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
155 ASSERT (result != NULL);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
156 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
157 || strcmp (result, "0x3.244p+0 33") == 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
158 || strcmp (result, "0x6.488p-1 33") == 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
159 || strcmp (result, "0xc.91p-2 33") == 0);
8342
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
160 ASSERT (retval == strlen (result));
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
161 free (result);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
162 }
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
163
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
164 { /* A negative number. */
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
165 char *result;
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
166 int retval =
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
167 my_asprintf (&result, "%A %d", -3.1416015625, 33, 44, 55);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
168 ASSERT (result != NULL);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
169 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
170 || strcmp (result, "-0X3.244P+0 33") == 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
171 || strcmp (result, "-0X6.488P-1 33") == 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
172 || strcmp (result, "-0XC.91P-2 33") == 0);
8342
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
173 ASSERT (retval == strlen (result));
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
174 free (result);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
175 }
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
176
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
177 { /* Positive zero. */
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
178 char *result;
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
179 int retval =
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
180 my_asprintf (&result, "%a %d", 0.0, 33, 44, 55);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
181 ASSERT (result != NULL);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
182 ASSERT (strcmp (result, "0x0p+0 33") == 0);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
183 ASSERT (retval == strlen (result));
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
184 free (result);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
185 }
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
186
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
187 { /* Negative zero. */
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
188 char *result;
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
189 int retval =
13834
108bbfd6f03b frexp, tests: work around ICC bug with -zero
Eric Blake <eblake@redhat.com>
parents: 12559
diff changeset
190 my_asprintf (&result, "%a %d", minus_zerod, 33, 44, 55);
8342
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
191 ASSERT (result != NULL);
8852
df0b5e8ea770 Avoid test failures on platforms where -0.0 and 0.0 are identical.
Bruno Haible <bruno@clisp.org>
parents: 8850
diff changeset
192 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
193 ASSERT (strcmp (result, "-0x0p+0 33") == 0);
8342
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
194 ASSERT (retval == strlen (result));
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
195 free (result);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
196 }
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
197
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
198 { /* Positive infinity. */
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
199 char *result;
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
200 int retval =
15595
328819af1c02 Support for MSVC compiler: Avoid division by a literal 0.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
201 my_asprintf (&result, "%a %d", Infinityd (), 33, 44, 55);
8342
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
202 ASSERT (result != NULL);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
203 ASSERT (strcmp (result, "inf 33") == 0);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
204 ASSERT (retval == strlen (result));
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
205 free (result);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
206 }
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
207
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
208 { /* Negative infinity. */
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
209 char *result;
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
210 int retval =
15595
328819af1c02 Support for MSVC compiler: Avoid division by a literal 0.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
211 my_asprintf (&result, "%a %d", - Infinityd (), 33, 44, 55);
8342
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
212 ASSERT (result != NULL);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
213 ASSERT (strcmp (result, "-inf 33") == 0);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
214 ASSERT (retval == strlen (result));
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
215 free (result);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
216 }
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
217
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
218 { /* NaN. */
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
219 char *result;
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
220 int retval =
9854
baba3b346ab2 Use macros NaNf, NaNd, NaNl instead of NAN.
Bruno Haible <bruno@clisp.org>
parents: 9850
diff changeset
221 my_asprintf (&result, "%a %d", NaNd (), 33, 44, 55);
8342
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
222 ASSERT (result != NULL);
8850
d1fe16dfbfee Avoid test failures on IRIX 6.5.
Bruno Haible <bruno@clisp.org>
parents: 8839
diff changeset
223 ASSERT (strlen (result) >= 3 + 3
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
224 && strisnan (result, 0, strlen (result) - 3, 0)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
225 && strcmp (result + strlen (result) - 3, " 33") == 0);
8342
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
226 ASSERT (retval == strlen (result));
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
227 free (result);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
228 }
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
229
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
230 { /* Rounding near the decimal point. */
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
231 char *result;
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
232 int retval =
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
233 my_asprintf (&result, "%.0a %d", 1.5, 33, 44, 55);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
234 ASSERT (result != NULL);
17360
e2ab31f19799 vasprintf-posix-tests: allow rounding 1.5 to 1.
Gary V. Vaughan <gary@gnu.org>
parents: 17249
diff changeset
235 ASSERT (strcmp (result, "0x1p+0 33") == 0
e2ab31f19799 vasprintf-posix-tests: allow rounding 1.5 to 1.
Gary V. Vaughan <gary@gnu.org>
parents: 17249
diff changeset
236 || strcmp (result, "0x2p+0 33") == 0
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
237 || strcmp (result, "0x3p-1 33") == 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
238 || strcmp (result, "0x6p-2 33") == 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
239 || strcmp (result, "0xcp-3 33") == 0);
8342
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
240 ASSERT (retval == strlen (result));
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
241 free (result);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
242 }
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
243
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
244 { /* Rounding with precision 0. */
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
245 char *result;
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
246 int retval =
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
247 my_asprintf (&result, "%.0a %d", 1.51, 33, 44, 55);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
248 ASSERT (result != NULL);
17361
35650a3443e8 vasprintf-posix-tests: allow rounding 1.51 to 1.
Gary V. Vaughan <gary@gnu.org>
parents: 17360
diff changeset
249 ASSERT (strcmp (result, "0x1p+0 33") == 0
35650a3443e8 vasprintf-posix-tests: allow rounding 1.51 to 1.
Gary V. Vaughan <gary@gnu.org>
parents: 17360
diff changeset
250 || strcmp (result, "0x2p+0 33") == 0
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
251 || strcmp (result, "0x3p-1 33") == 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
252 || strcmp (result, "0x6p-2 33") == 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
253 || strcmp (result, "0xcp-3 33") == 0);
8342
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
254 ASSERT (retval == strlen (result));
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
255 free (result);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
256 }
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
257
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
258 { /* Rounding with precision 1. */
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
259 char *result;
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
260 int retval =
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
261 my_asprintf (&result, "%.1a %d", 1.51, 33, 44, 55);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
262 ASSERT (result != NULL);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
263 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
264 || strcmp (result, "0x3.0p-1 33") == 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
265 || strcmp (result, "0x6.1p-2 33") == 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
266 || strcmp (result, "0xc.1p-3 33") == 0);
8342
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
267 ASSERT (retval == strlen (result));
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
268 free (result);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
269 }
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
270
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
271 { /* Rounding with precision 2. */
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
272 char *result;
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
273 int retval =
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
274 my_asprintf (&result, "%.2a %d", 1.51, 33, 44, 55);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
275 ASSERT (result != NULL);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
276 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
277 || strcmp (result, "0x3.05p-1 33") == 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
278 || strcmp (result, "0x6.0ap-2 33") == 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
279 || strcmp (result, "0xc.14p-3 33") == 0);
8342
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
280 ASSERT (retval == strlen (result));
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
281 free (result);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
282 }
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
283
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
284 { /* Rounding with precision 3. */
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
285 char *result;
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
286 int retval =
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
287 my_asprintf (&result, "%.3a %d", 1.51, 33, 44, 55);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
288 ASSERT (result != NULL);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
289 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
290 || strcmp (result, "0x3.052p-1 33") == 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
291 || strcmp (result, "0x6.0a4p-2 33") == 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
292 || strcmp (result, "0xc.148p-3 33") == 0);
8342
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
293 ASSERT (retval == strlen (result));
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
294 free (result);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
295 }
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
296
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
297 { /* Rounding can turn a ...FFF into a ...000. */
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
298 char *result;
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
299 int retval =
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
300 my_asprintf (&result, "%.3a %d", 1.49999, 33, 44, 55);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
301 ASSERT (result != NULL);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
302 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
303 || strcmp (result, "0x3.000p-1 33") == 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
304 || strcmp (result, "0x6.000p-2 33") == 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
305 || strcmp (result, "0xc.000p-3 33") == 0);
8342
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
306 ASSERT (retval == strlen (result));
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
307 free (result);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
308 }
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
309
8344
c8055280f68e Test a corner case. Exclude two buggy implementations.
Bruno Haible <bruno@clisp.org>
parents: 8342
diff changeset
310 { /* 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
311 This shows a Mac OS X 10.3.9 (Darwin 7.9) bug. */
8344
c8055280f68e Test a corner case. Exclude two buggy implementations.
Bruno Haible <bruno@clisp.org>
parents: 8342
diff changeset
312 char *result;
c8055280f68e Test a corner case. Exclude two buggy implementations.
Bruno Haible <bruno@clisp.org>
parents: 8342
diff changeset
313 int retval =
c8055280f68e Test a corner case. Exclude two buggy implementations.
Bruno Haible <bruno@clisp.org>
parents: 8342
diff changeset
314 my_asprintf (&result, "%.1a %d", 1.999, 33, 44, 55);
c8055280f68e Test a corner case. Exclude two buggy implementations.
Bruno Haible <bruno@clisp.org>
parents: 8342
diff changeset
315 ASSERT (result != NULL);
c8055280f68e Test a corner case. Exclude two buggy implementations.
Bruno Haible <bruno@clisp.org>
parents: 8342
diff changeset
316 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
317 || strcmp (result, "0x2.0p+0 33") == 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
318 || strcmp (result, "0x4.0p-1 33") == 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
319 || strcmp (result, "0x8.0p-2 33") == 0);
8344
c8055280f68e Test a corner case. Exclude two buggy implementations.
Bruno Haible <bruno@clisp.org>
parents: 8342
diff changeset
320 ASSERT (retval == strlen (result));
c8055280f68e Test a corner case. Exclude two buggy implementations.
Bruno Haible <bruno@clisp.org>
parents: 8342
diff changeset
321 free (result);
c8055280f68e Test a corner case. Exclude two buggy implementations.
Bruno Haible <bruno@clisp.org>
parents: 8342
diff changeset
322 }
c8055280f68e Test a corner case. Exclude two buggy implementations.
Bruno Haible <bruno@clisp.org>
parents: 8342
diff changeset
323
8342
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
324 { /* Width. */
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
325 char *result;
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
326 int retval =
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
327 my_asprintf (&result, "%10a %d", 1.75, 33, 44, 55);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
328 ASSERT (result != NULL);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
329 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
330 || strcmp (result, " 0x3.8p-1 33") == 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
331 || strcmp (result, " 0x7p-2 33") == 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
332 || strcmp (result, " 0xep-3 33") == 0);
8342
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
333 ASSERT (retval == strlen (result));
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
334 free (result);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
335 }
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
336
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
337 { /* Small precision. */
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
338 char *result;
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
339 int retval =
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
340 my_asprintf (&result, "%.10a %d", 1.75, 33, 44, 55);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
341 ASSERT (result != NULL);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
342 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
343 || strcmp (result, "0x3.8000000000p-1 33") == 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
344 || strcmp (result, "0x7.0000000000p-2 33") == 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
345 || strcmp (result, "0xe.0000000000p-3 33") == 0);
8342
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
346 ASSERT (retval == strlen (result));
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
347 free (result);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
348 }
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
349
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
350 { /* Large precision. */
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
351 char *result;
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
352 int retval =
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
353 my_asprintf (&result, "%.50a %d", 1.75, 33, 44, 55);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
354 ASSERT (result != NULL);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
355 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
356 || strcmp (result, "0x3.80000000000000000000000000000000000000000000000000p-1 33") == 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
357 || strcmp (result, "0x7.00000000000000000000000000000000000000000000000000p-2 33") == 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
358 || strcmp (result, "0xe.00000000000000000000000000000000000000000000000000p-3 33") == 0);
8342
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
359 ASSERT (retval == strlen (result));
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
360 free (result);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
361 }
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
362
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
363 { /* FLAG_LEFT. */
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
364 char *result;
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
365 int retval =
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
366 my_asprintf (&result, "%-10a %d", 1.75, 33, 44, 55);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
367 ASSERT (result != NULL);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
368 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
369 || strcmp (result, "0x3.8p-1 33") == 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
370 || strcmp (result, "0x7p-2 33") == 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
371 || strcmp (result, "0xep-3 33") == 0);
8342
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
372 ASSERT (retval == strlen (result));
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
373 free (result);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
374 }
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
375
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
376 { /* FLAG_SHOWSIGN. */
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
377 char *result;
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
378 int retval =
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
379 my_asprintf (&result, "%+a %d", 1.75, 33, 44, 55);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
380 ASSERT (result != NULL);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
381 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
382 || strcmp (result, "+0x3.8p-1 33") == 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
383 || strcmp (result, "+0x7p-2 33") == 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
384 || strcmp (result, "+0xep-3 33") == 0);
8342
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
385 ASSERT (retval == strlen (result));
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
386 free (result);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
387 }
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
388
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
389 { /* FLAG_SPACE. */
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
390 char *result;
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
391 int retval =
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
392 my_asprintf (&result, "% a %d", 1.75, 33, 44, 55);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
393 ASSERT (result != NULL);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
394 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
395 || strcmp (result, " 0x3.8p-1 33") == 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
396 || strcmp (result, " 0x7p-2 33") == 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
397 || strcmp (result, " 0xep-3 33") == 0);
8342
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
398 ASSERT (retval == strlen (result));
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
399 free (result);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
400 }
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
401
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
402 { /* FLAG_ALT. */
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
403 char *result;
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
404 int retval =
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
405 my_asprintf (&result, "%#a %d", 1.75, 33, 44, 55);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
406 ASSERT (result != NULL);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
407 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
408 || strcmp (result, "0x3.8p-1 33") == 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
409 || strcmp (result, "0x7.p-2 33") == 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
410 || strcmp (result, "0xe.p-3 33") == 0);
8342
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
411 ASSERT (retval == strlen (result));
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
412 free (result);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
413 }
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
414
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
415 { /* FLAG_ALT. */
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
416 char *result;
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
417 int retval =
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
418 my_asprintf (&result, "%#a %d", 1.0, 33, 44, 55);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
419 ASSERT (result != NULL);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
420 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
421 || strcmp (result, "0x2.p-1 33") == 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
422 || strcmp (result, "0x4.p-2 33") == 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
423 || strcmp (result, "0x8.p-3 33") == 0);
8342
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
424 ASSERT (retval == strlen (result));
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
425 free (result);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
426 }
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
427
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
428 { /* FLAG_ZERO with finite number. */
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
429 char *result;
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
430 int retval =
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
431 my_asprintf (&result, "%010a %d", 1.75, 33, 44, 55);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
432 ASSERT (result != NULL);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
433 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
434 || strcmp (result, "0x003.8p-1 33") == 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
435 || strcmp (result, "0x00007p-2 33") == 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
436 || strcmp (result, "0x0000ep-3 33") == 0);
8342
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
437 ASSERT (retval == strlen (result));
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
438 free (result);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
439 }
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
440
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
441 { /* FLAG_ZERO with infinite number. */
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
442 char *result;
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
443 int retval =
15595
328819af1c02 Support for MSVC compiler: Avoid division by a literal 0.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
444 my_asprintf (&result, "%010a %d", Infinityd (), 33, 44, 55);
8342
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
445 ASSERT (result != NULL);
8662
023aa5c883a7 Guard against FreeBSD 6.1 bug.
Bruno Haible <bruno@clisp.org>
parents: 8648
diff changeset
446 /* "0000000inf 33" is not a valid result; see
023aa5c883a7 Guard against FreeBSD 6.1 bug.
Bruno Haible <bruno@clisp.org>
parents: 8648
diff changeset
447 <http://lists.gnu.org/archive/html/bug-gnulib/2007-04/msg00107.html> */
023aa5c883a7 Guard against FreeBSD 6.1 bug.
Bruno Haible <bruno@clisp.org>
parents: 8648
diff changeset
448 ASSERT (strcmp (result, " inf 33") == 0);
8342
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
449 ASSERT (retval == strlen (result));
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
450 free (result);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
451 }
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
452
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
453 { /* FLAG_ZERO with NaN. */
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
454 char *result;
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
455 int retval =
9854
baba3b346ab2 Use macros NaNf, NaNd, NaNl instead of NAN.
Bruno Haible <bruno@clisp.org>
parents: 9850
diff changeset
456 my_asprintf (&result, "%050a %d", NaNd (), 33, 44, 55);
8342
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
457 ASSERT (result != NULL);
8662
023aa5c883a7 Guard against FreeBSD 6.1 bug.
Bruno Haible <bruno@clisp.org>
parents: 8648
diff changeset
458 /* "0000000nan 33" is not a valid result; see
023aa5c883a7 Guard against FreeBSD 6.1 bug.
Bruno Haible <bruno@clisp.org>
parents: 8648
diff changeset
459 <http://lists.gnu.org/archive/html/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
460 ASSERT (strlen (result) == 50 + 3
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
461 && strisnan (result, strspn (result, " "), strlen (result) - 3, 0)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
462 && strcmp (result + strlen (result) - 3, " 33") == 0);
8342
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
463 ASSERT (retval == strlen (result));
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
464 free (result);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
465 }
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
466
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
467 { /* A positive number. */
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
468 char *result;
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
469 int retval =
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
470 my_asprintf (&result, "%La %d", 3.1416015625L, 33, 44, 55);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
471 ASSERT (result != NULL);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
472 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
473 || strcmp (result, "0x3.244p+0 33") == 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
474 || strcmp (result, "0x6.488p-1 33") == 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
475 || strcmp (result, "0xc.91p-2 33") == 0);
8342
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
476 ASSERT (retval == strlen (result));
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
477 free (result);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
478 }
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
479
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
480 { /* A negative number. */
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
481 char *result;
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
482 int retval =
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
483 my_asprintf (&result, "%LA %d", -3.1416015625L, 33, 44, 55);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
484 ASSERT (result != NULL);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
485 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
486 || strcmp (result, "-0X3.244P+0 33") == 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
487 || strcmp (result, "-0X6.488P-1 33") == 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
488 || strcmp (result, "-0XC.91P-2 33") == 0);
8342
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
489 ASSERT (retval == strlen (result));
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
490 free (result);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
491 }
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
492
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
493 { /* Positive zero. */
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
494 char *result;
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
495 int retval =
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
496 my_asprintf (&result, "%La %d", 0.0L, 33, 44, 55);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
497 ASSERT (result != NULL);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
498 ASSERT (strcmp (result, "0x0p+0 33") == 0);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
499 ASSERT (retval == strlen (result));
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
500 free (result);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
501 }
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
502
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
503 { /* Negative zero. */
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
504 char *result;
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
505 int retval =
10601
ca053fa79cd3 Use a more portable replacement expression for -0.0L.
Bruno Haible <bruno@clisp.org>
parents: 10458
diff changeset
506 my_asprintf (&result, "%La %d", minus_zerol, 33, 44, 55);
8342
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
507 ASSERT (result != NULL);
8852
df0b5e8ea770 Avoid test failures on platforms where -0.0 and 0.0 are identical.
Bruno Haible <bruno@clisp.org>
parents: 8850
diff changeset
508 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
509 ASSERT (strcmp (result, "-0x0p+0 33") == 0);
8342
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
510 ASSERT (retval == strlen (result));
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
511 free (result);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
512 }
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
513
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
514 { /* Positive infinity. */
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
515 char *result;
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
516 int retval =
15595
328819af1c02 Support for MSVC compiler: Avoid division by a literal 0.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
517 my_asprintf (&result, "%La %d", Infinityl (), 33, 44, 55);
8342
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
518 ASSERT (result != NULL);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
519 ASSERT (strcmp (result, "inf 33") == 0);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
520 ASSERT (retval == strlen (result));
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
521 free (result);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
522 }
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
523
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
524 { /* Negative infinity. */
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
525 char *result;
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
526 int retval =
15595
328819af1c02 Support for MSVC compiler: Avoid division by a literal 0.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
527 my_asprintf (&result, "%La %d", - Infinityl (), 33, 44, 55);
8342
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
528 ASSERT (result != NULL);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
529 ASSERT (strcmp (result, "-inf 33") == 0);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
530 ASSERT (retval == strlen (result));
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
531 free (result);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
532 }
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
533
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
534 { /* NaN. */
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
535 char *result;
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
536 int retval =
9854
baba3b346ab2 Use macros NaNf, NaNd, NaNl instead of NAN.
Bruno Haible <bruno@clisp.org>
parents: 9850
diff changeset
537 my_asprintf (&result, "%La %d", NaNl (), 33, 44, 55);
8342
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
538 ASSERT (result != NULL);
8850
d1fe16dfbfee Avoid test failures on IRIX 6.5.
Bruno Haible <bruno@clisp.org>
parents: 8839
diff changeset
539 ASSERT (strlen (result) >= 3 + 3
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
540 && strisnan (result, 0, strlen (result) - 3, 0)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
541 && strcmp (result + strlen (result) - 3, " 33") == 0);
8342
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
542 ASSERT (retval == strlen (result));
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
543 free (result);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
544 }
15906
400649d35651 *printf-posix tests: Fix for platforms where 'long double' == 'double'.
Bruno Haible <bruno@clisp.org>
parents: 15595
diff changeset
545 #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: 8891
diff changeset
546 { /* Quiet NaN. */
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
547 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: 8891
diff changeset
548 { 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: 8891
diff changeset
549 char *result;
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
550 int retval =
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
551 my_asprintf (&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: 8891
diff changeset
552 ASSERT (result != NULL);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
553 ASSERT (strlen (result) >= 3 + 3
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
554 && strisnan (result, 0, strlen (result) - 3, 0)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
555 && 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: 8891
diff changeset
556 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: 8891
diff changeset
557 free (result);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
558 }
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
559 {
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
560 /* Signalling NaN. */
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
561 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: 8891
diff changeset
562 { 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: 8891
diff changeset
563 char *result;
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
564 int retval =
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
565 my_asprintf (&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: 8891
diff changeset
566 ASSERT (result != NULL);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
567 ASSERT (strlen (result) >= 3 + 3
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
568 && strisnan (result, 0, strlen (result) - 3, 0)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
569 && 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: 8891
diff changeset
570 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: 8891
diff changeset
571 free (result);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
572 }
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
573 /* The isnanl function should recognize Pseudo-NaNs, Pseudo-Infinities,
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
574 Pseudo-Zeroes, Unnormalized Numbers, and Pseudo-Denormals, as defined in
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
575 Intel IA-64 Architecture Software Developer's Manual, Volume 1:
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
576 Application Architecture.
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
577 Table 5-2 "Floating-Point Register Encodings"
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
578 Figure 5-6 "Memory to Floating-Point Register Data Translation"
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
579 */
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
580 { /* Pseudo-NaN. */
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
581 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: 8891
diff changeset
582 { LDBL80_WORDS (0xFFFF, 0x40000001, 0x00000000) };
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
583 char *result;
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
584 int retval =
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
585 my_asprintf (&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: 8891
diff changeset
586 ASSERT (result != NULL);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
587 ASSERT (strlen (result) >= 3 + 3
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
588 && strisnan (result, 0, strlen (result) - 3, 0)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
589 && 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: 8891
diff changeset
590 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: 8891
diff changeset
591 free (result);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
592 }
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
593 { /* Pseudo-Infinity. */
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
594 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: 8891
diff changeset
595 { LDBL80_WORDS (0xFFFF, 0x00000000, 0x00000000) };
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
596 char *result;
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
597 int retval =
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
598 my_asprintf (&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: 8891
diff changeset
599 ASSERT (result != NULL);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
600 ASSERT (strlen (result) >= 3 + 3
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
601 && strisnan (result, 0, strlen (result) - 3, 0)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
602 && 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: 8891
diff changeset
603 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: 8891
diff changeset
604 free (result);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
605 }
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
606 { /* Pseudo-Zero. */
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
607 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: 8891
diff changeset
608 { 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: 8891
diff changeset
609 char *result;
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
610 int retval =
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
611 my_asprintf (&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: 8891
diff changeset
612 ASSERT (result != NULL);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
613 ASSERT (strlen (result) >= 3 + 3
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
614 && strisnan (result, 0, strlen (result) - 3, 0)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
615 && 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: 8891
diff changeset
616 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: 8891
diff changeset
617 free (result);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
618 }
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
619 { /* Unnormalized number. */
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
620 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: 8891
diff changeset
621 { 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: 8891
diff changeset
622 char *result;
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
623 int retval =
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
624 my_asprintf (&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: 8891
diff changeset
625 ASSERT (result != NULL);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
626 ASSERT (strlen (result) >= 3 + 3
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
627 && strisnan (result, 0, strlen (result) - 3, 0)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
628 && 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: 8891
diff changeset
629 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: 8891
diff changeset
630 free (result);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
631 }
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
632 { /* Pseudo-Denormal. */
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
633 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: 8891
diff changeset
634 { 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: 8891
diff changeset
635 char *result;
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
636 int retval =
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
637 my_asprintf (&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: 8891
diff changeset
638 ASSERT (result != NULL);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
639 ASSERT (strlen (result) >= 3 + 3
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
640 && strisnan (result, 0, strlen (result) - 3, 0)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
641 && 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: 8891
diff changeset
642 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: 8891
diff changeset
643 free (result);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
644 }
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
645 #endif
8342
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
646
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
647 { /* Rounding near the decimal point. */
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
648 char *result;
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
649 int retval =
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
650 my_asprintf (&result, "%.0La %d", 1.5L, 33, 44, 55);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
651 ASSERT (result != NULL);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
652 ASSERT (strcmp (result, "0x2p+0 33") == 0
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
653 || strcmp (result, "0x3p-1 33") == 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
654 || strcmp (result, "0x6p-2 33") == 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
655 || strcmp (result, "0xcp-3 33") == 0);
8342
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
656 ASSERT (retval == strlen (result));
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
657 free (result);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
658 }
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
659
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
660 { /* Rounding with precision 0. */
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
661 char *result;
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
662 int retval =
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
663 my_asprintf (&result, "%.0La %d", 1.51L, 33, 44, 55);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
664 ASSERT (result != NULL);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
665 ASSERT (strcmp (result, "0x2p+0 33") == 0
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
666 || strcmp (result, "0x3p-1 33") == 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
667 || strcmp (result, "0x6p-2 33") == 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
668 || strcmp (result, "0xcp-3 33") == 0);
8342
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
669 ASSERT (retval == strlen (result));
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
670 free (result);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
671 }
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
672
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
673 { /* Rounding with precision 1. */
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
674 char *result;
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
675 int retval =
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
676 my_asprintf (&result, "%.1La %d", 1.51L, 33, 44, 55);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
677 ASSERT (result != NULL);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
678 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
679 || strcmp (result, "0x3.0p-1 33") == 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
680 || strcmp (result, "0x6.1p-2 33") == 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
681 || strcmp (result, "0xc.1p-3 33") == 0);
8342
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
682 ASSERT (retval == strlen (result));
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
683 free (result);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
684 }
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
685
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
686 { /* Rounding with precision 2. */
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
687 char *result;
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
688 int retval =
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
689 my_asprintf (&result, "%.2La %d", 1.51L, 33, 44, 55);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
690 ASSERT (result != NULL);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
691 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
692 || strcmp (result, "0x3.05p-1 33") == 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
693 || strcmp (result, "0x6.0ap-2 33") == 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
694 || strcmp (result, "0xc.14p-3 33") == 0);
8342
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
695 ASSERT (retval == strlen (result));
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
696 free (result);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
697 }
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
698
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
699 { /* Rounding with precision 3. */
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
700 char *result;
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
701 int retval =
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
702 my_asprintf (&result, "%.3La %d", 1.51L, 33, 44, 55);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
703 ASSERT (result != NULL);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
704 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
705 || strcmp (result, "0x3.052p-1 33") == 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
706 || strcmp (result, "0x6.0a4p-2 33") == 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
707 || strcmp (result, "0xc.148p-3 33") == 0);
8342
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
708 ASSERT (retval == strlen (result));
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
709 free (result);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
710 }
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
711
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
712 { /* Rounding can turn a ...FFF into a ...000. */
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
713 char *result;
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
714 int retval =
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
715 my_asprintf (&result, "%.3La %d", 1.49999L, 33, 44, 55);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
716 ASSERT (result != NULL);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
717 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
718 || strcmp (result, "0x3.000p-1 33") == 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
719 || strcmp (result, "0x6.000p-2 33") == 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
720 || strcmp (result, "0xc.000p-3 33") == 0);
8342
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
721 ASSERT (retval == strlen (result));
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
722 free (result);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
723 }
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
724
8344
c8055280f68e Test a corner case. Exclude two buggy implementations.
Bruno Haible <bruno@clisp.org>
parents: 8342
diff changeset
725 { /* 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
726 This shows a Mac OS X 10.3.9 (Darwin 7.9) bug and a
8344
c8055280f68e Test a corner case. Exclude two buggy implementations.
Bruno Haible <bruno@clisp.org>
parents: 8342
diff changeset
727 glibc 2.4 bug <http://sourceware.org/bugzilla/show_bug.cgi?id=2908>. */
c8055280f68e Test a corner case. Exclude two buggy implementations.
Bruno Haible <bruno@clisp.org>
parents: 8342
diff changeset
728 char *result;
c8055280f68e Test a corner case. Exclude two buggy implementations.
Bruno Haible <bruno@clisp.org>
parents: 8342
diff changeset
729 int retval =
c8055280f68e Test a corner case. Exclude two buggy implementations.
Bruno Haible <bruno@clisp.org>
parents: 8342
diff changeset
730 my_asprintf (&result, "%.1La %d", 1.999L, 33, 44, 55);
c8055280f68e Test a corner case. Exclude two buggy implementations.
Bruno Haible <bruno@clisp.org>
parents: 8342
diff changeset
731 ASSERT (result != NULL);
c8055280f68e Test a corner case. Exclude two buggy implementations.
Bruno Haible <bruno@clisp.org>
parents: 8342
diff changeset
732 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
733 || strcmp (result, "0x2.0p+0 33") == 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
734 || strcmp (result, "0x4.0p-1 33") == 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
735 || strcmp (result, "0x8.0p-2 33") == 0);
8344
c8055280f68e Test a corner case. Exclude two buggy implementations.
Bruno Haible <bruno@clisp.org>
parents: 8342
diff changeset
736 ASSERT (retval == strlen (result));
c8055280f68e Test a corner case. Exclude two buggy implementations.
Bruno Haible <bruno@clisp.org>
parents: 8342
diff changeset
737 free (result);
c8055280f68e Test a corner case. Exclude two buggy implementations.
Bruno Haible <bruno@clisp.org>
parents: 8342
diff changeset
738 }
c8055280f68e Test a corner case. Exclude two buggy implementations.
Bruno Haible <bruno@clisp.org>
parents: 8342
diff changeset
739
8342
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
740 { /* Width. */
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
741 char *result;
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
742 int retval =
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
743 my_asprintf (&result, "%10La %d", 1.75L, 33, 44, 55);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
744 ASSERT (result != NULL);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
745 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
746 || strcmp (result, " 0x3.8p-1 33") == 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
747 || strcmp (result, " 0x7p-2 33") == 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
748 || strcmp (result, " 0xep-3 33") == 0);
8342
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
749 ASSERT (retval == strlen (result));
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
750 free (result);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
751 }
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
752
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
753 { /* Small precision. */
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
754 char *result;
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
755 int retval =
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
756 my_asprintf (&result, "%.10La %d", 1.75L, 33, 44, 55);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
757 ASSERT (result != NULL);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
758 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
759 || strcmp (result, "0x3.8000000000p-1 33") == 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
760 || strcmp (result, "0x7.0000000000p-2 33") == 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
761 || strcmp (result, "0xe.0000000000p-3 33") == 0);
8342
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
762 ASSERT (retval == strlen (result));
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
763 free (result);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
764 }
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
765
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
766 { /* Large precision. */
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
767 char *result;
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
768 int retval =
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
769 my_asprintf (&result, "%.50La %d", 1.75L, 33, 44, 55);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
770 ASSERT (result != NULL);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
771 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
772 || strcmp (result, "0x3.80000000000000000000000000000000000000000000000000p-1 33") == 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
773 || strcmp (result, "0x7.00000000000000000000000000000000000000000000000000p-2 33") == 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
774 || strcmp (result, "0xe.00000000000000000000000000000000000000000000000000p-3 33") == 0);
8342
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
775 ASSERT (retval == strlen (result));
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
776 free (result);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
777 }
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
778
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
779 { /* FLAG_LEFT. */
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
780 char *result;
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
781 int retval =
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
782 my_asprintf (&result, "%-10La %d", 1.75L, 33, 44, 55);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
783 ASSERT (result != NULL);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
784 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
785 || strcmp (result, "0x3.8p-1 33") == 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
786 || strcmp (result, "0x7p-2 33") == 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
787 || strcmp (result, "0xep-3 33") == 0);
8342
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
788 ASSERT (retval == strlen (result));
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
789 free (result);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
790 }
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
791
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
792 { /* FLAG_SHOWSIGN. */
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
793 char *result;
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
794 int retval =
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
795 my_asprintf (&result, "%+La %d", 1.75L, 33, 44, 55);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
796 ASSERT (result != NULL);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
797 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
798 || strcmp (result, "+0x3.8p-1 33") == 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
799 || strcmp (result, "+0x7p-2 33") == 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
800 || strcmp (result, "+0xep-3 33") == 0);
8342
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
801 ASSERT (retval == strlen (result));
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
802 free (result);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
803 }
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
804
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
805 { /* FLAG_SPACE. */
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
806 char *result;
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
807 int retval =
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
808 my_asprintf (&result, "% La %d", 1.75L, 33, 44, 55);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
809 ASSERT (result != NULL);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
810 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
811 || strcmp (result, " 0x3.8p-1 33") == 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
812 || strcmp (result, " 0x7p-2 33") == 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
813 || strcmp (result, " 0xep-3 33") == 0);
8342
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
814 ASSERT (retval == strlen (result));
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
815 free (result);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
816 }
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
817
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
818 { /* FLAG_ALT. */
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
819 char *result;
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
820 int retval =
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
821 my_asprintf (&result, "%#La %d", 1.75L, 33, 44, 55);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
822 ASSERT (result != NULL);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
823 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
824 || strcmp (result, "0x3.8p-1 33") == 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
825 || strcmp (result, "0x7.p-2 33") == 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
826 || strcmp (result, "0xe.p-3 33") == 0);
8342
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
827 ASSERT (retval == strlen (result));
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
828 free (result);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
829 }
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
830
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
831 { /* FLAG_ALT. */
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
832 char *result;
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
833 int retval =
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
834 my_asprintf (&result, "%#La %d", 1.0L, 33, 44, 55);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
835 ASSERT (result != NULL);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
836 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
837 || strcmp (result, "0x2.p-1 33") == 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
838 || strcmp (result, "0x4.p-2 33") == 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
839 || strcmp (result, "0x8.p-3 33") == 0);
8342
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
840 ASSERT (retval == strlen (result));
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
841 free (result);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
842 }
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
843
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
844 { /* FLAG_ZERO with finite number. */
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
845 char *result;
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
846 int retval =
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
847 my_asprintf (&result, "%010La %d", 1.75L, 33, 44, 55);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
848 ASSERT (result != NULL);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
849 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
850 || strcmp (result, "0x003.8p-1 33") == 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
851 || strcmp (result, "0x00007p-2 33") == 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
852 || strcmp (result, "0x0000ep-3 33") == 0);
8342
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
853 ASSERT (retval == strlen (result));
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
854 free (result);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
855 }
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
856
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
857 { /* FLAG_ZERO with infinite number. */
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
858 char *result;
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
859 int retval =
15595
328819af1c02 Support for MSVC compiler: Avoid division by a literal 0.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
860 my_asprintf (&result, "%010La %d", Infinityl (), 33, 44, 55);
8342
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
861 ASSERT (result != NULL);
8662
023aa5c883a7 Guard against FreeBSD 6.1 bug.
Bruno Haible <bruno@clisp.org>
parents: 8648
diff changeset
862 /* "0000000inf 33" is not a valid result; see
023aa5c883a7 Guard against FreeBSD 6.1 bug.
Bruno Haible <bruno@clisp.org>
parents: 8648
diff changeset
863 <http://lists.gnu.org/archive/html/bug-gnulib/2007-04/msg00107.html> */
023aa5c883a7 Guard against FreeBSD 6.1 bug.
Bruno Haible <bruno@clisp.org>
parents: 8648
diff changeset
864 ASSERT (strcmp (result, " inf 33") == 0);
8342
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
865 ASSERT (retval == strlen (result));
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
866 free (result);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
867 }
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
868
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
869 { /* FLAG_ZERO with NaN. */
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
870 char *result;
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
871 int retval =
9854
baba3b346ab2 Use macros NaNf, NaNd, NaNl instead of NAN.
Bruno Haible <bruno@clisp.org>
parents: 9850
diff changeset
872 my_asprintf (&result, "%050La %d", NaNl (), 33, 44, 55);
8342
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
873 ASSERT (result != NULL);
8662
023aa5c883a7 Guard against FreeBSD 6.1 bug.
Bruno Haible <bruno@clisp.org>
parents: 8648
diff changeset
874 /* "0000000nan 33" is not a valid result; see
023aa5c883a7 Guard against FreeBSD 6.1 bug.
Bruno Haible <bruno@clisp.org>
parents: 8648
diff changeset
875 <http://lists.gnu.org/archive/html/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
876 ASSERT (strlen (result) == 50 + 3
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
877 && strisnan (result, strspn (result, " "), strlen (result) - 3, 0)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
878 && strcmp (result + strlen (result) - 3, " 33") == 0);
8342
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
879 ASSERT (retval == strlen (result));
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
880 free (result);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
881 }
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
882
8684
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
883 /* 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
884
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
885 { /* A positive number. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
886 char *result;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
887 int retval =
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
888 my_asprintf (&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
889 ASSERT (result != NULL);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
890 ASSERT (strcmp (result, "12.750000 33") == 0);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
891 ASSERT (retval == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
892 free (result);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
893 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
894
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
895 { /* A larger positive number. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
896 char *result;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
897 int retval =
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
898 my_asprintf (&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
899 ASSERT (result != NULL);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
900 ASSERT (strcmp (result, "1234567.000000 33") == 0);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
901 ASSERT (retval == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
902 free (result);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
903 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
904
8834
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
905 { /* Small and large positive numbers. */
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
906 static struct { double value; const char *string; } data[] =
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
907 {
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
908 { 1.234321234321234e-37, "0.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
909 { 1.234321234321234e-36, "0.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
910 { 1.234321234321234e-35, "0.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
911 { 1.234321234321234e-34, "0.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
912 { 1.234321234321234e-33, "0.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
913 { 1.234321234321234e-32, "0.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
914 { 1.234321234321234e-31, "0.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
915 { 1.234321234321234e-30, "0.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
916 { 1.234321234321234e-29, "0.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
917 { 1.234321234321234e-28, "0.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
918 { 1.234321234321234e-27, "0.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
919 { 1.234321234321234e-26, "0.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
920 { 1.234321234321234e-25, "0.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
921 { 1.234321234321234e-24, "0.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
922 { 1.234321234321234e-23, "0.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
923 { 1.234321234321234e-22, "0.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
924 { 1.234321234321234e-21, "0.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
925 { 1.234321234321234e-20, "0.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
926 { 1.234321234321234e-19, "0.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
927 { 1.234321234321234e-18, "0.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
928 { 1.234321234321234e-17, "0.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
929 { 1.234321234321234e-16, "0.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
930 { 1.234321234321234e-15, "0.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
931 { 1.234321234321234e-14, "0.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
932 { 1.234321234321234e-13, "0.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
933 { 1.234321234321234e-12, "0.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
934 { 1.234321234321234e-11, "0.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
935 { 1.234321234321234e-10, "0.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
936 { 1.234321234321234e-9, "0.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
937 { 1.234321234321234e-8, "0.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
938 { 1.234321234321234e-7, "0.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
939 { 1.234321234321234e-6, "0.000001" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
940 { 1.234321234321234e-5, "0.000012" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
941 { 1.234321234321234e-4, "0.000123" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
942 { 1.234321234321234e-3, "0.001234" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
943 { 1.234321234321234e-2, "0.012343" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
944 { 1.234321234321234e-1, "0.123432" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
945 { 1.234321234321234, "1.234321" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
946 { 1.234321234321234e1, "12.343212" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
947 { 1.234321234321234e2, "123.432123" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
948 { 1.234321234321234e3, "1234.321234" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
949 { 1.234321234321234e4, "12343.212343" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
950 { 1.234321234321234e5, "123432.123432" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
951 { 1.234321234321234e6, "1234321.234321" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
952 { 1.234321234321234e7, "12343212.343212" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
953 { 1.234321234321234e8, "123432123.432123" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
954 { 1.234321234321234e9, "1234321234.321234" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
955 { 1.234321234321234e10, "12343212343.2123**" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
956 { 1.234321234321234e11, "123432123432.123***" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
957 { 1.234321234321234e12, "1234321234321.23****" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
958 { 1.234321234321234e13, "12343212343212.3*****" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
959 { 1.234321234321234e14, "123432123432123.******" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
960 { 1.234321234321234e15, "1234321234321234.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
961 { 1.234321234321234e16, "123432123432123**.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
962 { 1.234321234321234e17, "123432123432123***.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
963 { 1.234321234321234e18, "123432123432123****.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
964 { 1.234321234321234e19, "123432123432123*****.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
965 { 1.234321234321234e20, "123432123432123******.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
966 { 1.234321234321234e21, "123432123432123*******.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
967 { 1.234321234321234e22, "123432123432123********.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
968 { 1.234321234321234e23, "123432123432123*********.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
969 { 1.234321234321234e24, "123432123432123**********.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
970 { 1.234321234321234e25, "123432123432123***********.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
971 { 1.234321234321234e26, "123432123432123************.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
972 { 1.234321234321234e27, "123432123432123*************.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
973 { 1.234321234321234e28, "123432123432123**************.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
974 { 1.234321234321234e29, "123432123432123***************.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
975 { 1.234321234321234e30, "123432123432123****************.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
976 { 1.234321234321234e31, "123432123432123*****************.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
977 { 1.234321234321234e32, "123432123432123******************.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
978 { 1.234321234321234e33, "123432123432123*******************.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
979 { 1.234321234321234e34, "123432123432123********************.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
980 { 1.234321234321234e35, "123432123432123*********************.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
981 { 1.234321234321234e36, "123432123432123**********************.000000" }
8834
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
982 };
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
983 size_t k;
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
984 for (k = 0; k < SIZEOF (data); k++)
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
985 {
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
986 char *result;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
987 int retval =
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
988 my_asprintf (&result, "%f", data[k].value);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
989 ASSERT (result != NULL);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
990 ASSERT (strmatch (data[k].string, result));
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
991 ASSERT (retval == strlen (result));
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
992 free (result);
8834
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
993 }
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
994 }
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
995
8684
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
996 { /* A negative number. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
997 char *result;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
998 int retval =
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
999 my_asprintf (&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
1000 ASSERT (result != NULL);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1001 ASSERT (strcmp (result, "-0.031250 33") == 0);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1002 ASSERT (retval == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1003 free (result);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1004 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1005
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1006 { /* Positive zero. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1007 char *result;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1008 int retval =
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1009 my_asprintf (&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
1010 ASSERT (result != NULL);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1011 ASSERT (strcmp (result, "0.000000 33") == 0);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1012 ASSERT (retval == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1013 free (result);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1014 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1015
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1016 { /* Negative zero. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1017 char *result;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1018 int retval =
13834
108bbfd6f03b frexp, tests: work around ICC bug with -zero
Eric Blake <eblake@redhat.com>
parents: 12559
diff changeset
1019 my_asprintf (&result, "%f %d", minus_zerod, 33, 44, 55);
8684
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1020 ASSERT (result != NULL);
8852
df0b5e8ea770 Avoid test failures on platforms where -0.0 and 0.0 are identical.
Bruno Haible <bruno@clisp.org>
parents: 8850
diff changeset
1021 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
1022 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
1023 ASSERT (retval == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1024 free (result);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1025 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1026
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1027 { /* Positive infinity. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1028 char *result;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1029 int retval =
15595
328819af1c02 Support for MSVC compiler: Avoid division by a literal 0.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
1030 my_asprintf (&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
1031 ASSERT (result != NULL);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1032 ASSERT (strcmp (result, "inf 33") == 0
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1033 || strcmp (result, "infinity 33") == 0);
8684
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1034 ASSERT (retval == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1035 free (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 infinity. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1039 char *result;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1040 int retval =
15595
328819af1c02 Support for MSVC compiler: Avoid division by a literal 0.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
1041 my_asprintf (&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
1042 ASSERT (result != NULL);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1043 ASSERT (strcmp (result, "-inf 33") == 0
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1044 || strcmp (result, "-infinity 33") == 0);
8684
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1045 ASSERT (retval == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1046 free (result);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1047 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1048
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1049 { /* NaN. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1050 char *result;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1051 int retval =
9854
baba3b346ab2 Use macros NaNf, NaNd, NaNl instead of NAN.
Bruno Haible <bruno@clisp.org>
parents: 9850
diff changeset
1052 my_asprintf (&result, "%f %d", NaNd (), 33, 44, 55);
8684
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1053 ASSERT (result != NULL);
8850
d1fe16dfbfee Avoid test failures on IRIX 6.5.
Bruno Haible <bruno@clisp.org>
parents: 8839
diff changeset
1054 ASSERT (strlen (result) >= 3 + 3
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1055 && strisnan (result, 0, strlen (result) - 3, 0)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1056 && 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
1057 ASSERT (retval == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1058 free (result);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1059 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1060
8804
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1061 { /* Width. */
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1062 char *result;
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1063 int retval =
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1064 my_asprintf (&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
1065 ASSERT (result != NULL);
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1066 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
1067 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
1068 free (result);
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1069 }
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1070
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1071 { /* FLAG_LEFT. */
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1072 char *result;
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1073 int retval =
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1074 my_asprintf (&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
1075 ASSERT (result != NULL);
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1076 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
1077 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
1078 free (result);
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1079 }
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1080
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1081 { /* FLAG_SHOWSIGN. */
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1082 char *result;
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1083 int retval =
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1084 my_asprintf (&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
1085 ASSERT (result != NULL);
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1086 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
1087 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
1088 free (result);
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1089 }
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1090
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1091 { /* FLAG_SPACE. */
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1092 char *result;
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1093 int retval =
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1094 my_asprintf (&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
1095 ASSERT (result != NULL);
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1096 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
1097 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
1098 free (result);
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1099 }
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1100
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1101 { /* FLAG_ALT. */
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1102 char *result;
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1103 int retval =
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1104 my_asprintf (&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
1105 ASSERT (result != NULL);
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1106 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
1107 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
1108 free (result);
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1109 }
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1110
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1111 { /* FLAG_ALT. */
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1112 char *result;
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1113 int retval =
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1114 my_asprintf (&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
1115 ASSERT (result != NULL);
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1116 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
1117 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
1118 free (result);
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1119 }
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1120
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1121 { /* FLAG_ZERO with finite number. */
8684
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1122 char *result;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1123 int retval =
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1124 my_asprintf (&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
1125 ASSERT (result != NULL);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1126 ASSERT (strcmp (result, "00001234.000000 33") == 0);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1127 ASSERT (retval == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1128 free (result);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1129 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1130
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1131 { /* FLAG_ZERO with infinite number. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1132 char *result;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1133 int retval =
15595
328819af1c02 Support for MSVC compiler: Avoid division by a literal 0.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
1134 my_asprintf (&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
1135 ASSERT (result != NULL);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1136 ASSERT (strcmp (result, " -inf 33") == 0
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1137 || strcmp (result, " -infinity 33") == 0);
8684
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1138 ASSERT (retval == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1139 free (result);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1140 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1141
8804
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1142 { /* 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
1143 char *result;
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1144 int retval =
9854
baba3b346ab2 Use macros NaNf, NaNd, NaNl instead of NAN.
Bruno Haible <bruno@clisp.org>
parents: 9850
diff changeset
1145 my_asprintf (&result, "%050f %d", NaNd (), 33, 44, 55);
8804
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1146 ASSERT (result != NULL);
8870
4e1f2ea486b4 Allow for a longer printed representation of NaN.
Bruno Haible <bruno@clisp.org>
parents: 8865
diff changeset
1147 ASSERT (strlen (result) == 50 + 3
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1148 && strisnan (result, strspn (result, " "), strlen (result) - 3, 0)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1149 && 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
1150 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
1151 free (result);
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1152 }
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1153
8684
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1154 { /* Precision. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1155 char *result;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1156 int retval =
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1157 my_asprintf (&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
1158 ASSERT (result != NULL);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1159 ASSERT (strcmp (result, "1234 33") == 0);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1160 ASSERT (retval == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1161 free (result);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1162 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1163
9938
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
1164 { /* Precision with no rounding. */
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
1165 char *result;
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
1166 int retval =
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
1167 my_asprintf (&result, "%.2f %d", 999.951, 33, 44, 55);
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
1168 ASSERT (result != NULL);
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
1169 ASSERT (strcmp (result, "999.95 33") == 0);
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
1170 ASSERT (retval == strlen (result));
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
1171 free (result);
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
1172 }
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
1173
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
1174 { /* Precision with rounding. */
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
1175 char *result;
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
1176 int retval =
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
1177 my_asprintf (&result, "%.2f %d", 999.996, 33, 44, 55);
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
1178 ASSERT (result != NULL);
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
1179 ASSERT (strcmp (result, "1000.00 33") == 0);
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
1180 ASSERT (retval == strlen (result));
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
1181 free (result);
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
1182 }
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
1183
8684
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1184 { /* A positive number. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1185 char *result;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1186 int retval =
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1187 my_asprintf (&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
1188 ASSERT (result != NULL);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1189 ASSERT (strcmp (result, "12.750000 33") == 0);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1190 ASSERT (retval == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1191 free (result);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1192 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1193
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1194 { /* A larger positive number. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1195 char *result;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1196 int retval =
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1197 my_asprintf (&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
1198 ASSERT (result != NULL);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1199 ASSERT (strcmp (result, "1234567.000000 33") == 0);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1200 ASSERT (retval == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1201 free (result);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1202 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1203
8834
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1204 { /* Small and large positive numbers. */
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1205 static struct { long double value; const char *string; } data[] =
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1206 {
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1207 { 1.234321234321234e-37L, "0.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1208 { 1.234321234321234e-36L, "0.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1209 { 1.234321234321234e-35L, "0.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1210 { 1.234321234321234e-34L, "0.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1211 { 1.234321234321234e-33L, "0.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1212 { 1.234321234321234e-32L, "0.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1213 { 1.234321234321234e-31L, "0.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1214 { 1.234321234321234e-30L, "0.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1215 { 1.234321234321234e-29L, "0.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1216 { 1.234321234321234e-28L, "0.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1217 { 1.234321234321234e-27L, "0.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1218 { 1.234321234321234e-26L, "0.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1219 { 1.234321234321234e-25L, "0.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1220 { 1.234321234321234e-24L, "0.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1221 { 1.234321234321234e-23L, "0.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1222 { 1.234321234321234e-22L, "0.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1223 { 1.234321234321234e-21L, "0.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1224 { 1.234321234321234e-20L, "0.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1225 { 1.234321234321234e-19L, "0.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1226 { 1.234321234321234e-18L, "0.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1227 { 1.234321234321234e-17L, "0.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1228 { 1.234321234321234e-16L, "0.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1229 { 1.234321234321234e-15L, "0.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1230 { 1.234321234321234e-14L, "0.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1231 { 1.234321234321234e-13L, "0.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1232 { 1.234321234321234e-12L, "0.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1233 { 1.234321234321234e-11L, "0.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1234 { 1.234321234321234e-10L, "0.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1235 { 1.234321234321234e-9L, "0.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1236 { 1.234321234321234e-8L, "0.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1237 { 1.234321234321234e-7L, "0.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1238 { 1.234321234321234e-6L, "0.000001" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1239 { 1.234321234321234e-5L, "0.000012" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1240 { 1.234321234321234e-4L, "0.000123" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1241 { 1.234321234321234e-3L, "0.001234" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1242 { 1.234321234321234e-2L, "0.012343" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1243 { 1.234321234321234e-1L, "0.123432" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1244 { 1.234321234321234L, "1.234321" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1245 { 1.234321234321234e1L, "12.343212" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1246 { 1.234321234321234e2L, "123.432123" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1247 { 1.234321234321234e3L, "1234.321234" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1248 { 1.234321234321234e4L, "12343.212343" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1249 { 1.234321234321234e5L, "123432.123432" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1250 { 1.234321234321234e6L, "1234321.234321" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1251 { 1.234321234321234e7L, "12343212.343212" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1252 { 1.234321234321234e8L, "123432123.432123" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1253 { 1.234321234321234e9L, "1234321234.321234" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1254 { 1.234321234321234e10L, "12343212343.2123**" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1255 { 1.234321234321234e11L, "123432123432.123***" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1256 { 1.234321234321234e12L, "1234321234321.23****" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1257 { 1.234321234321234e13L, "12343212343212.3*****" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1258 { 1.234321234321234e14L, "123432123432123.******" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1259 { 1.234321234321234e15L, "1234321234321234.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1260 { 1.234321234321234e16L, "123432123432123**.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1261 { 1.234321234321234e17L, "123432123432123***.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1262 { 1.234321234321234e18L, "123432123432123****.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1263 { 1.234321234321234e19L, "123432123432123*****.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1264 { 1.234321234321234e20L, "123432123432123******.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1265 { 1.234321234321234e21L, "123432123432123*******.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1266 { 1.234321234321234e22L, "123432123432123********.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1267 { 1.234321234321234e23L, "123432123432123*********.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1268 { 1.234321234321234e24L, "123432123432123**********.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1269 { 1.234321234321234e25L, "123432123432123***********.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1270 { 1.234321234321234e26L, "123432123432123************.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1271 { 1.234321234321234e27L, "123432123432123*************.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1272 { 1.234321234321234e28L, "123432123432123**************.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1273 { 1.234321234321234e29L, "123432123432123***************.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1274 { 1.234321234321234e30L, "123432123432123****************.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1275 { 1.234321234321234e31L, "123432123432123*****************.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1276 { 1.234321234321234e32L, "123432123432123******************.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1277 { 1.234321234321234e33L, "123432123432123*******************.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1278 { 1.234321234321234e34L, "123432123432123********************.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1279 { 1.234321234321234e35L, "123432123432123*********************.000000" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1280 { 1.234321234321234e36L, "123432123432123**********************.000000" }
8834
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1281 };
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1282 size_t k;
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1283 for (k = 0; k < SIZEOF (data); k++)
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1284 {
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1285 char *result;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1286 int retval =
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1287 my_asprintf (&result, "%Lf", data[k].value);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1288 ASSERT (result != NULL);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1289 ASSERT (strmatch (data[k].string, result));
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1290 ASSERT (retval == strlen (result));
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1291 free (result);
8834
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1292 }
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1293 }
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1294
8684
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1295 { /* A negative number. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1296 char *result;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1297 int retval =
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1298 my_asprintf (&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
1299 ASSERT (result != NULL);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1300 ASSERT (strcmp (result, "-0.031250 33") == 0);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1301 ASSERT (retval == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1302 free (result);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1303 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1304
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1305 { /* Positive zero. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1306 char *result;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1307 int retval =
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1308 my_asprintf (&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
1309 ASSERT (result != NULL);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1310 ASSERT (strcmp (result, "0.000000 33") == 0);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1311 ASSERT (retval == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1312 free (result);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1313 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1314
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1315 { /* Negative zero. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1316 char *result;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1317 int retval =
10601
ca053fa79cd3 Use a more portable replacement expression for -0.0L.
Bruno Haible <bruno@clisp.org>
parents: 10458
diff changeset
1318 my_asprintf (&result, "%Lf %d", minus_zerol, 33, 44, 55);
8684
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1319 ASSERT (result != NULL);
8852
df0b5e8ea770 Avoid test failures on platforms where -0.0 and 0.0 are identical.
Bruno Haible <bruno@clisp.org>
parents: 8850
diff changeset
1320 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
1321 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
1322 ASSERT (retval == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1323 free (result);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1324 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1325
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1326 { /* Positive infinity. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1327 char *result;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1328 int retval =
15595
328819af1c02 Support for MSVC compiler: Avoid division by a literal 0.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
1329 my_asprintf (&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
1330 ASSERT (result != NULL);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1331 ASSERT (strcmp (result, "inf 33") == 0
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1332 || strcmp (result, "infinity 33") == 0);
8684
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1333 ASSERT (retval == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1334 free (result);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1335 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1336
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1337 { /* Negative infinity. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1338 char *result;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1339 int retval =
15595
328819af1c02 Support for MSVC compiler: Avoid division by a literal 0.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
1340 my_asprintf (&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
1341 ASSERT (result != NULL);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1342 ASSERT (strcmp (result, "-inf 33") == 0
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1343 || strcmp (result, "-infinity 33") == 0);
8684
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1344 ASSERT (retval == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1345 free (result);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1346 }
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 { /* NaN. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1349 char *result;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1350 int retval =
9854
baba3b346ab2 Use macros NaNf, NaNd, NaNl instead of NAN.
Bruno Haible <bruno@clisp.org>
parents: 9850
diff changeset
1351 my_asprintf (&result, "%Lf %d", NaNl (), 33, 44, 55);
8684
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1352 ASSERT (result != NULL);
8850
d1fe16dfbfee Avoid test failures on IRIX 6.5.
Bruno Haible <bruno@clisp.org>
parents: 8839
diff changeset
1353 ASSERT (strlen (result) >= 3 + 3
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1354 && strisnan (result, 0, strlen (result) - 3, 0)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1355 && 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
1356 ASSERT (retval == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1357 free (result);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1358 }
15906
400649d35651 *printf-posix tests: Fix for platforms where 'long double' == 'double'.
Bruno Haible <bruno@clisp.org>
parents: 15595
diff changeset
1359 #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: 8891
diff changeset
1360 { /* Quiet NaN. */
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
1361 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: 8891
diff changeset
1362 { 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: 8891
diff changeset
1363 char *result;
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
1364 int retval =
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
1365 my_asprintf (&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: 8891
diff changeset
1366 ASSERT (result != NULL);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
1367 ASSERT (strlen (result) >= 3 + 3
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1368 && strisnan (result, 0, strlen (result) - 3, 0)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1369 && 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: 8891
diff changeset
1370 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: 8891
diff changeset
1371 free (result);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
1372 }
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
1373 {
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
1374 /* Signalling NaN. */
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
1375 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: 8891
diff changeset
1376 { 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: 8891
diff changeset
1377 char *result;
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
1378 int retval =
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
1379 my_asprintf (&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: 8891
diff changeset
1380 ASSERT (result != NULL);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
1381 ASSERT (strlen (result) >= 3 + 3
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1382 && strisnan (result, 0, strlen (result) - 3, 0)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1383 && 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: 8891
diff changeset
1384 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: 8891
diff changeset
1385 free (result);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
1386 }
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
1387 /* The isnanl function should recognize Pseudo-NaNs, Pseudo-Infinities,
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
1388 Pseudo-Zeroes, Unnormalized Numbers, and Pseudo-Denormals, as defined in
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
1389 Intel IA-64 Architecture Software Developer's Manual, Volume 1:
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
1390 Application Architecture.
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
1391 Table 5-2 "Floating-Point Register Encodings"
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
1392 Figure 5-6 "Memory to Floating-Point Register Data Translation"
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
1393 */
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
1394 { /* Pseudo-NaN. */
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
1395 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: 8891
diff changeset
1396 { LDBL80_WORDS (0xFFFF, 0x40000001, 0x00000000) };
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
1397 char *result;
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
1398 int retval =
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
1399 my_asprintf (&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: 8891
diff changeset
1400 ASSERT (result != NULL);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
1401 ASSERT (strlen (result) >= 3 + 3
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1402 && strisnan (result, 0, strlen (result) - 3, 0)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1403 && 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: 8891
diff changeset
1404 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: 8891
diff changeset
1405 free (result);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
1406 }
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
1407 { /* Pseudo-Infinity. */
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
1408 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: 8891
diff changeset
1409 { LDBL80_WORDS (0xFFFF, 0x00000000, 0x00000000) };
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
1410 char *result;
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
1411 int retval =
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
1412 my_asprintf (&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: 8891
diff changeset
1413 ASSERT (result != NULL);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
1414 ASSERT (strlen (result) >= 3 + 3
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1415 && strisnan (result, 0, strlen (result) - 3, 0)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1416 && 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: 8891
diff changeset
1417 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: 8891
diff changeset
1418 free (result);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
1419 }
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
1420 { /* Pseudo-Zero. */
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
1421 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: 8891
diff changeset
1422 { 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: 8891
diff changeset
1423 char *result;
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
1424 int retval =
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
1425 my_asprintf (&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: 8891
diff changeset
1426 ASSERT (result != NULL);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
1427 ASSERT (strlen (result) >= 3 + 3
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1428 && strisnan (result, 0, strlen (result) - 3, 0)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1429 && 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: 8891
diff changeset
1430 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: 8891
diff changeset
1431 free (result);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
1432 }
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
1433 { /* Unnormalized number. */
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
1434 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: 8891
diff changeset
1435 { 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: 8891
diff changeset
1436 char *result;
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
1437 int retval =
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
1438 my_asprintf (&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: 8891
diff changeset
1439 ASSERT (result != NULL);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
1440 ASSERT (strlen (result) >= 3 + 3
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1441 && strisnan (result, 0, strlen (result) - 3, 0)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1442 && 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: 8891
diff changeset
1443 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: 8891
diff changeset
1444 free (result);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
1445 }
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
1446 { /* Pseudo-Denormal. */
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
1447 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: 8891
diff changeset
1448 { 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: 8891
diff changeset
1449 char *result;
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
1450 int retval =
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
1451 my_asprintf (&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: 8891
diff changeset
1452 ASSERT (result != NULL);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
1453 ASSERT (strlen (result) >= 3 + 3
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1454 && strisnan (result, 0, strlen (result) - 3, 0)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1455 && 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: 8891
diff changeset
1456 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: 8891
diff changeset
1457 free (result);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
1458 }
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
1459 #endif
8684
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1460
8804
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1461 { /* Width. */
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1462 char *result;
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1463 int retval =
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1464 my_asprintf (&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
1465 ASSERT (result != NULL);
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1466 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
1467 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
1468 free (result);
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1469 }
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1470
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1471 { /* FLAG_LEFT. */
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1472 char *result;
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1473 int retval =
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1474 my_asprintf (&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
1475 ASSERT (result != NULL);
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1476 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
1477 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
1478 free (result);
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1479 }
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1480
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1481 { /* FLAG_SHOWSIGN. */
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1482 char *result;
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1483 int retval =
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1484 my_asprintf (&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
1485 ASSERT (result != NULL);
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1486 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
1487 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
1488 free (result);
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1489 }
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1490
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1491 { /* FLAG_SPACE. */
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1492 char *result;
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1493 int retval =
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1494 my_asprintf (&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
1495 ASSERT (result != NULL);
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1496 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
1497 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
1498 free (result);
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1499 }
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1500
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1501 { /* FLAG_ALT. */
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1502 char *result;
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1503 int retval =
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1504 my_asprintf (&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
1505 ASSERT (result != NULL);
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1506 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
1507 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
1508 free (result);
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1509 }
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1510
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1511 { /* FLAG_ALT. */
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1512 char *result;
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1513 int retval =
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1514 my_asprintf (&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
1515 ASSERT (result != NULL);
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1516 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
1517 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
1518 free (result);
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1519 }
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1520
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1521 { /* FLAG_ZERO with finite number. */
8684
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1522 char *result;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1523 int retval =
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1524 my_asprintf (&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
1525 ASSERT (result != NULL);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1526 ASSERT (strcmp (result, "00001234.000000 33") == 0);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1527 ASSERT (retval == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1528 free (result);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1529 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1530
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1531 { /* FLAG_ZERO with infinite number. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1532 char *result;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1533 int retval =
15595
328819af1c02 Support for MSVC compiler: Avoid division by a literal 0.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
1534 my_asprintf (&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
1535 ASSERT (result != NULL);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1536 ASSERT (strcmp (result, " -inf 33") == 0
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1537 || strcmp (result, " -infinity 33") == 0);
8684
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1538 ASSERT (retval == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1539 free (result);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1540 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1541
8804
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1542 { /* 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
1543 char *result;
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1544 int retval =
9854
baba3b346ab2 Use macros NaNf, NaNd, NaNl instead of NAN.
Bruno Haible <bruno@clisp.org>
parents: 9850
diff changeset
1545 my_asprintf (&result, "%050Lf %d", NaNl (), 33, 44, 55);
8804
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1546 ASSERT (result != NULL);
8870
4e1f2ea486b4 Allow for a longer printed representation of NaN.
Bruno Haible <bruno@clisp.org>
parents: 8865
diff changeset
1547 ASSERT (strlen (result) == 50 + 3
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1548 && strisnan (result, strspn (result, " "), strlen (result) - 3, 0)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1549 && 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
1550 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
1551 free (result);
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1552 }
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1553
8684
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1554 { /* Precision. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1555 char *result;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1556 int retval =
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1557 my_asprintf (&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
1558 ASSERT (result != NULL);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1559 ASSERT (strcmp (result, "1234 33") == 0);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1560 ASSERT (retval == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1561 free (result);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1562 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1563
9938
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
1564 { /* Precision with no rounding. */
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
1565 char *result;
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
1566 int retval =
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
1567 my_asprintf (&result, "%.2Lf %d", 999.951L, 33, 44, 55);
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
1568 ASSERT (result != NULL);
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
1569 ASSERT (strcmp (result, "999.95 33") == 0);
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
1570 ASSERT (retval == strlen (result));
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
1571 free (result);
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
1572 }
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
1573
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
1574 { /* Precision with rounding. */
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
1575 char *result;
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
1576 int retval =
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
1577 my_asprintf (&result, "%.2Lf %d", 999.996L, 33, 44, 55);
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
1578 ASSERT (result != NULL);
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
1579 ASSERT (strcmp (result, "1000.00 33") == 0);
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
1580 ASSERT (retval == strlen (result));
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
1581 free (result);
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
1582 }
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
1583
8684
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1584 /* 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
1585
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1586 { /* A positive number. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1587 char *result;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1588 int retval =
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1589 my_asprintf (&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
1590 ASSERT (result != NULL);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1591 ASSERT (strcmp (result, "12.750000 33") == 0);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1592 ASSERT (retval == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1593 free (result);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1594 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1595
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1596 { /* A larger positive number. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1597 char *result;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1598 int retval =
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1599 my_asprintf (&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
1600 ASSERT (result != NULL);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1601 ASSERT (strcmp (result, "1234567.000000 33") == 0);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1602 ASSERT (retval == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1603 free (result);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1604 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1605
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1606 { /* A negative number. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1607 char *result;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1608 int retval =
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1609 my_asprintf (&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
1610 ASSERT (result != NULL);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1611 ASSERT (strcmp (result, "-0.031250 33") == 0);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1612 ASSERT (retval == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1613 free (result);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1614 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1615
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1616 { /* Positive zero. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1617 char *result;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1618 int retval =
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1619 my_asprintf (&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
1620 ASSERT (result != NULL);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1621 ASSERT (strcmp (result, "0.000000 33") == 0);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1622 ASSERT (retval == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1623 free (result);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1624 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1625
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1626 { /* Negative zero. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1627 char *result;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1628 int retval =
13834
108bbfd6f03b frexp, tests: work around ICC bug with -zero
Eric Blake <eblake@redhat.com>
parents: 12559
diff changeset
1629 my_asprintf (&result, "%F %d", minus_zerod, 33, 44, 55);
8684
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1630 ASSERT (result != NULL);
8852
df0b5e8ea770 Avoid test failures on platforms where -0.0 and 0.0 are identical.
Bruno Haible <bruno@clisp.org>
parents: 8850
diff changeset
1631 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
1632 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
1633 ASSERT (retval == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1634 free (result);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1635 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1636
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1637 { /* Positive infinity. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1638 char *result;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1639 int retval =
15595
328819af1c02 Support for MSVC compiler: Avoid division by a literal 0.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
1640 my_asprintf (&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
1641 ASSERT (result != NULL);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1642 ASSERT (strcmp (result, "INF 33") == 0
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1643 || strcmp (result, "INFINITY 33") == 0);
8684
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1644 ASSERT (retval == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1645 free (result);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1646 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1647
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1648 { /* Negative infinity. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1649 char *result;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1650 int retval =
15595
328819af1c02 Support for MSVC compiler: Avoid division by a literal 0.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
1651 my_asprintf (&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
1652 ASSERT (result != NULL);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1653 ASSERT (strcmp (result, "-INF 33") == 0
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1654 || strcmp (result, "-INFINITY 33") == 0);
8684
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1655 ASSERT (retval == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1656 free (result);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1657 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1658
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1659 { /* NaN. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1660 char *result;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1661 int retval =
9854
baba3b346ab2 Use macros NaNf, NaNd, NaNl instead of NAN.
Bruno Haible <bruno@clisp.org>
parents: 9850
diff changeset
1662 my_asprintf (&result, "%F %d", NaNd (), 33, 44, 55);
8684
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1663 ASSERT (result != NULL);
8850
d1fe16dfbfee Avoid test failures on IRIX 6.5.
Bruno Haible <bruno@clisp.org>
parents: 8839
diff changeset
1664 ASSERT (strlen (result) >= 3 + 3
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1665 && strisnan (result, 0, strlen (result) - 3, 1)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1666 && 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
1667 ASSERT (retval == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1668 free (result);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1669 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1670
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1671 { /* FLAG_ZERO. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1672 char *result;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1673 int retval =
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1674 my_asprintf (&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
1675 ASSERT (result != NULL);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1676 ASSERT (strcmp (result, "00001234.000000 33") == 0);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1677 ASSERT (retval == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1678 free (result);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1679 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1680
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1681 { /* FLAG_ZERO with infinite number. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1682 char *result;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1683 int retval =
15595
328819af1c02 Support for MSVC compiler: Avoid division by a literal 0.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
1684 my_asprintf (&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
1685 ASSERT (result != NULL);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1686 ASSERT (strcmp (result, " -INF 33") == 0
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1687 || strcmp (result, " -INFINITY 33") == 0);
8684
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1688 ASSERT (retval == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1689 free (result);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1690 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1691
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1692 { /* Precision. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1693 char *result;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1694 int retval =
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1695 my_asprintf (&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
1696 ASSERT (result != NULL);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1697 ASSERT (strcmp (result, "1234 33") == 0);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1698 ASSERT (retval == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1699 free (result);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1700 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1701
9938
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
1702 { /* Precision with no rounding. */
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
1703 char *result;
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
1704 int retval =
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
1705 my_asprintf (&result, "%.2F %d", 999.951, 33, 44, 55);
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
1706 ASSERT (result != NULL);
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
1707 ASSERT (strcmp (result, "999.95 33") == 0);
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
1708 ASSERT (retval == strlen (result));
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
1709 free (result);
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
1710 }
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
1711
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
1712 { /* Precision with rounding. */
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
1713 char *result;
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
1714 int retval =
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
1715 my_asprintf (&result, "%.2F %d", 999.996, 33, 44, 55);
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
1716 ASSERT (result != NULL);
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
1717 ASSERT (strcmp (result, "1000.00 33") == 0);
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
1718 ASSERT (retval == strlen (result));
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
1719 free (result);
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
1720 }
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
1721
8684
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1722 { /* A positive number. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1723 char *result;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1724 int retval =
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1725 my_asprintf (&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
1726 ASSERT (result != NULL);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1727 ASSERT (strcmp (result, "12.750000 33") == 0);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1728 ASSERT (retval == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1729 free (result);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1730 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1731
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1732 { /* A larger positive number. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1733 char *result;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1734 int retval =
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1735 my_asprintf (&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
1736 ASSERT (result != NULL);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1737 ASSERT (strcmp (result, "1234567.000000 33") == 0);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1738 ASSERT (retval == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1739 free (result);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1740 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1741
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1742 { /* A negative number. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1743 char *result;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1744 int retval =
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1745 my_asprintf (&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
1746 ASSERT (result != NULL);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1747 ASSERT (strcmp (result, "-0.031250 33") == 0);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1748 ASSERT (retval == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1749 free (result);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1750 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1751
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1752 { /* Positive zero. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1753 char *result;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1754 int retval =
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1755 my_asprintf (&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
1756 ASSERT (result != NULL);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1757 ASSERT (strcmp (result, "0.000000 33") == 0);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1758 ASSERT (retval == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1759 free (result);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1760 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1761
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1762 { /* Negative zero. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1763 char *result;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1764 int retval =
10601
ca053fa79cd3 Use a more portable replacement expression for -0.0L.
Bruno Haible <bruno@clisp.org>
parents: 10458
diff changeset
1765 my_asprintf (&result, "%LF %d", minus_zerol, 33, 44, 55);
8684
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1766 ASSERT (result != NULL);
8852
df0b5e8ea770 Avoid test failures on platforms where -0.0 and 0.0 are identical.
Bruno Haible <bruno@clisp.org>
parents: 8850
diff changeset
1767 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
1768 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
1769 ASSERT (retval == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1770 free (result);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1771 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1772
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1773 { /* Positive infinity. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1774 char *result;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1775 int retval =
15595
328819af1c02 Support for MSVC compiler: Avoid division by a literal 0.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
1776 my_asprintf (&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
1777 ASSERT (result != NULL);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1778 ASSERT (strcmp (result, "INF 33") == 0
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1779 || strcmp (result, "INFINITY 33") == 0);
8684
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1780 ASSERT (retval == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1781 free (result);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1782 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1783
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1784 { /* Negative infinity. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1785 char *result;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1786 int retval =
15595
328819af1c02 Support for MSVC compiler: Avoid division by a literal 0.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
1787 my_asprintf (&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
1788 ASSERT (result != NULL);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1789 ASSERT (strcmp (result, "-INF 33") == 0
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1790 || strcmp (result, "-INFINITY 33") == 0);
8684
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1791 ASSERT (retval == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1792 free (result);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1793 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1794
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1795 { /* NaN. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1796 char *result;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1797 int retval =
9854
baba3b346ab2 Use macros NaNf, NaNd, NaNl instead of NAN.
Bruno Haible <bruno@clisp.org>
parents: 9850
diff changeset
1798 my_asprintf (&result, "%LF %d", NaNl (), 33, 44, 55);
8684
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1799 ASSERT (result != NULL);
8850
d1fe16dfbfee Avoid test failures on IRIX 6.5.
Bruno Haible <bruno@clisp.org>
parents: 8839
diff changeset
1800 ASSERT (strlen (result) >= 3 + 3
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1801 && strisnan (result, 0, strlen (result) - 3, 1)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1802 && 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
1803 ASSERT (retval == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1804 free (result);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1805 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1806
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1807 { /* FLAG_ZERO. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1808 char *result;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1809 int retval =
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1810 my_asprintf (&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
1811 ASSERT (result != NULL);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1812 ASSERT (strcmp (result, "00001234.000000 33") == 0);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1813 ASSERT (retval == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1814 free (result);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1815 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1816
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1817 { /* FLAG_ZERO with infinite number. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1818 char *result;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1819 int retval =
15595
328819af1c02 Support for MSVC compiler: Avoid division by a literal 0.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
1820 my_asprintf (&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
1821 ASSERT (result != NULL);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1822 ASSERT (strcmp (result, " -INF 33") == 0
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1823 || strcmp (result, " -INFINITY 33") == 0);
8684
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1824 ASSERT (retval == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1825 free (result);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1826 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1827
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1828 { /* Precision. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1829 char *result;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1830 int retval =
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1831 my_asprintf (&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
1832 ASSERT (result != NULL);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1833 ASSERT (strcmp (result, "1234 33") == 0);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1834 ASSERT (retval == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1835 free (result);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1836 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1837
9938
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
1838 { /* Precision with no rounding. */
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
1839 char *result;
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
1840 int retval =
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
1841 my_asprintf (&result, "%.2LF %d", 999.951L, 33, 44, 55);
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
1842 ASSERT (result != NULL);
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
1843 ASSERT (strcmp (result, "999.95 33") == 0);
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
1844 ASSERT (retval == strlen (result));
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
1845 free (result);
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
1846 }
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
1847
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
1848 { /* Precision with rounding. */
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
1849 char *result;
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
1850 int retval =
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
1851 my_asprintf (&result, "%.2LF %d", 999.996L, 33, 44, 55);
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
1852 ASSERT (result != NULL);
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
1853 ASSERT (strcmp (result, "1000.00 33") == 0);
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
1854 ASSERT (retval == strlen (result));
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
1855 free (result);
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
1856 }
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
1857
8836
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1858 /* 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
1859
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1860 { /* A positive number. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1861 char *result;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1862 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1863 my_asprintf (&result, "%e %d", 12.75, 33, 44, 55);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1864 ASSERT (result != NULL);
8839
5efc1d668039 Accomodate for implementations that produce 3 exponent digits in %e and %g.
Bruno Haible <bruno@clisp.org>
parents: 8836
diff changeset
1865 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
1866 || 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
1867 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1868 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1869 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1870
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1871 { /* A larger positive number. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1872 char *result;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1873 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1874 my_asprintf (&result, "%e %d", 1234567.0, 33, 44, 55);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1875 ASSERT (result != NULL);
8839
5efc1d668039 Accomodate for implementations that produce 3 exponent digits in %e and %g.
Bruno Haible <bruno@clisp.org>
parents: 8836
diff changeset
1876 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
1877 || 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
1878 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1879 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1880 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1881
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1882 { /* Small and large positive numbers. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1883 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
1884 {
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1885 { 1.234321234321234e-37, "1.234321e-37" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1886 { 1.234321234321234e-36, "1.234321e-36" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1887 { 1.234321234321234e-35, "1.234321e-35" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1888 { 1.234321234321234e-34, "1.234321e-34" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1889 { 1.234321234321234e-33, "1.234321e-33" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1890 { 1.234321234321234e-32, "1.234321e-32" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1891 { 1.234321234321234e-31, "1.234321e-31" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1892 { 1.234321234321234e-30, "1.234321e-30" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1893 { 1.234321234321234e-29, "1.234321e-29" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1894 { 1.234321234321234e-28, "1.234321e-28" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1895 { 1.234321234321234e-27, "1.234321e-27" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1896 { 1.234321234321234e-26, "1.234321e-26" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1897 { 1.234321234321234e-25, "1.234321e-25" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1898 { 1.234321234321234e-24, "1.234321e-24" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1899 { 1.234321234321234e-23, "1.234321e-23" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1900 { 1.234321234321234e-22, "1.234321e-22" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1901 { 1.234321234321234e-21, "1.234321e-21" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1902 { 1.234321234321234e-20, "1.234321e-20" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1903 { 1.234321234321234e-19, "1.234321e-19" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1904 { 1.234321234321234e-18, "1.234321e-18" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1905 { 1.234321234321234e-17, "1.234321e-17" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1906 { 1.234321234321234e-16, "1.234321e-16" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1907 { 1.234321234321234e-15, "1.234321e-15" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1908 { 1.234321234321234e-14, "1.234321e-14" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1909 { 1.234321234321234e-13, "1.234321e-13" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1910 { 1.234321234321234e-12, "1.234321e-12" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1911 { 1.234321234321234e-11, "1.234321e-11" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1912 { 1.234321234321234e-10, "1.234321e-10" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1913 { 1.234321234321234e-9, "1.234321e-09" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1914 { 1.234321234321234e-8, "1.234321e-08" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1915 { 1.234321234321234e-7, "1.234321e-07" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1916 { 1.234321234321234e-6, "1.234321e-06" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1917 { 1.234321234321234e-5, "1.234321e-05" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1918 { 1.234321234321234e-4, "1.234321e-04" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1919 { 1.234321234321234e-3, "1.234321e-03" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1920 { 1.234321234321234e-2, "1.234321e-02" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1921 { 1.234321234321234e-1, "1.234321e-01" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1922 { 1.234321234321234, "1.234321e+00" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1923 { 1.234321234321234e1, "1.234321e+01" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1924 { 1.234321234321234e2, "1.234321e+02" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1925 { 1.234321234321234e3, "1.234321e+03" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1926 { 1.234321234321234e4, "1.234321e+04" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1927 { 1.234321234321234e5, "1.234321e+05" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1928 { 1.234321234321234e6, "1.234321e+06" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1929 { 1.234321234321234e7, "1.234321e+07" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1930 { 1.234321234321234e8, "1.234321e+08" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1931 { 1.234321234321234e9, "1.234321e+09" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1932 { 1.234321234321234e10, "1.234321e+10" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1933 { 1.234321234321234e11, "1.234321e+11" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1934 { 1.234321234321234e12, "1.234321e+12" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1935 { 1.234321234321234e13, "1.234321e+13" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1936 { 1.234321234321234e14, "1.234321e+14" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1937 { 1.234321234321234e15, "1.234321e+15" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1938 { 1.234321234321234e16, "1.234321e+16" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1939 { 1.234321234321234e17, "1.234321e+17" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1940 { 1.234321234321234e18, "1.234321e+18" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1941 { 1.234321234321234e19, "1.234321e+19" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1942 { 1.234321234321234e20, "1.234321e+20" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1943 { 1.234321234321234e21, "1.234321e+21" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1944 { 1.234321234321234e22, "1.234321e+22" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1945 { 1.234321234321234e23, "1.234321e+23" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1946 { 1.234321234321234e24, "1.234321e+24" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1947 { 1.234321234321234e25, "1.234321e+25" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1948 { 1.234321234321234e26, "1.234321e+26" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1949 { 1.234321234321234e27, "1.234321e+27" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1950 { 1.234321234321234e28, "1.234321e+28" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1951 { 1.234321234321234e29, "1.234321e+29" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1952 { 1.234321234321234e30, "1.234321e+30" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1953 { 1.234321234321234e31, "1.234321e+31" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1954 { 1.234321234321234e32, "1.234321e+32" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1955 { 1.234321234321234e33, "1.234321e+33" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1956 { 1.234321234321234e34, "1.234321e+34" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1957 { 1.234321234321234e35, "1.234321e+35" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1958 { 1.234321234321234e36, "1.234321e+36" }
8836
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 size_t k;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1961 for (k = 0; k < SIZEOF (data); k++)
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1962 {
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1963 char *result;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1964 int retval =
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1965 my_asprintf (&result, "%e", data[k].value);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1966 const char *expected = data[k].string;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1967 ASSERT (result != NULL);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1968 ASSERT (strcmp (result, expected) == 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1969 /* Some implementations produce exponents with 3 digits. */
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1970 || (strlen (result) == strlen (expected) + 1
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1971 && memcmp (result, expected, strlen (expected) - 2) == 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1972 && result[strlen (expected) - 2] == '0'
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1973 && strcmp (result + strlen (expected) - 1,
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1974 expected + strlen (expected) - 2)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1975 == 0));
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1976 ASSERT (retval == strlen (result));
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
1977 free (result);
8836
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1978 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1979 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1980
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1981 { /* A negative number. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1982 char *result;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1983 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1984 my_asprintf (&result, "%e %d", -0.03125, 33, 44, 55);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1985 ASSERT (result != NULL);
8839
5efc1d668039 Accomodate for implementations that produce 3 exponent digits in %e and %g.
Bruno Haible <bruno@clisp.org>
parents: 8836
diff changeset
1986 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
1987 || 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
1988 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1989 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1990 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1991
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1992 { /* Positive zero. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1993 char *result;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1994 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1995 my_asprintf (&result, "%e %d", 0.0, 33, 44, 55);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1996 ASSERT (result != NULL);
8839
5efc1d668039 Accomodate for implementations that produce 3 exponent digits in %e and %g.
Bruno Haible <bruno@clisp.org>
parents: 8836
diff changeset
1997 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
1998 || 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
1999 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2000 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2001 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2002
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2003 { /* Negative zero. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2004 char *result;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2005 int retval =
13834
108bbfd6f03b frexp, tests: work around ICC bug with -zero
Eric Blake <eblake@redhat.com>
parents: 12559
diff changeset
2006 my_asprintf (&result, "%e %d", minus_zerod, 33, 44, 55);
8836
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2007 ASSERT (result != NULL);
8852
df0b5e8ea770 Avoid test failures on platforms where -0.0 and 0.0 are identical.
Bruno Haible <bruno@clisp.org>
parents: 8850
diff changeset
2008 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
2009 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
2010 || 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
2011 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2012 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2013 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2014
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2015 { /* Positive infinity. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2016 char *result;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2017 int retval =
15595
328819af1c02 Support for MSVC compiler: Avoid division by a literal 0.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
2018 my_asprintf (&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
2019 ASSERT (result != NULL);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2020 ASSERT (strcmp (result, "inf 33") == 0
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2021 || strcmp (result, "infinity 33") == 0);
8836
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2022 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2023 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2024 }
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 { /* Negative infinity. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2027 char *result;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2028 int retval =
15595
328819af1c02 Support for MSVC compiler: Avoid division by a literal 0.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
2029 my_asprintf (&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
2030 ASSERT (result != NULL);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2031 ASSERT (strcmp (result, "-inf 33") == 0
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2032 || strcmp (result, "-infinity 33") == 0);
8836
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2033 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2034 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2035 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2036
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2037 { /* NaN. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2038 char *result;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2039 int retval =
9854
baba3b346ab2 Use macros NaNf, NaNd, NaNl instead of NAN.
Bruno Haible <bruno@clisp.org>
parents: 9850
diff changeset
2040 my_asprintf (&result, "%e %d", NaNd (), 33, 44, 55);
8836
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2041 ASSERT (result != NULL);
8850
d1fe16dfbfee Avoid test failures on IRIX 6.5.
Bruno Haible <bruno@clisp.org>
parents: 8839
diff changeset
2042 ASSERT (strlen (result) >= 3 + 3
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2043 && strisnan (result, 0, strlen (result) - 3, 0)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2044 && 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
2045 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2046 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2047 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2048
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2049 { /* Width. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2050 char *result;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2051 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2052 my_asprintf (&result, "%15e %d", 1.75, 33, 44, 55);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2053 ASSERT (result != NULL);
8839
5efc1d668039 Accomodate for implementations that produce 3 exponent digits in %e and %g.
Bruno Haible <bruno@clisp.org>
parents: 8836
diff changeset
2054 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
2055 || 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
2056 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2057 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2058 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2059
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2060 { /* FLAG_LEFT. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2061 char *result;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2062 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2063 my_asprintf (&result, "%-15e %d", 1.75, 33, 44, 55);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2064 ASSERT (result != NULL);
8839
5efc1d668039 Accomodate for implementations that produce 3 exponent digits in %e and %g.
Bruno Haible <bruno@clisp.org>
parents: 8836
diff changeset
2065 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
2066 || 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
2067 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2068 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2069 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2070
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2071 { /* FLAG_SHOWSIGN. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2072 char *result;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2073 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2074 my_asprintf (&result, "%+e %d", 1.75, 33, 44, 55);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2075 ASSERT (result != NULL);
8839
5efc1d668039 Accomodate for implementations that produce 3 exponent digits in %e and %g.
Bruno Haible <bruno@clisp.org>
parents: 8836
diff changeset
2076 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
2077 || 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
2078 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2079 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2080 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2081
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2082 { /* FLAG_SPACE. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2083 char *result;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2084 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2085 my_asprintf (&result, "% e %d", 1.75, 33, 44, 55);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2086 ASSERT (result != NULL);
8839
5efc1d668039 Accomodate for implementations that produce 3 exponent digits in %e and %g.
Bruno Haible <bruno@clisp.org>
parents: 8836
diff changeset
2087 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
2088 || 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
2089 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2090 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2091 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2092
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2093 { /* FLAG_ALT. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2094 char *result;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2095 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2096 my_asprintf (&result, "%#e %d", 1.75, 33, 44, 55);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2097 ASSERT (result != NULL);
8839
5efc1d668039 Accomodate for implementations that produce 3 exponent digits in %e and %g.
Bruno Haible <bruno@clisp.org>
parents: 8836
diff changeset
2098 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
2099 || 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
2100 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2101 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2102 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2103
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2104 { /* FLAG_ALT. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2105 char *result;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2106 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2107 my_asprintf (&result, "%#.e %d", 1.75, 33, 44, 55);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2108 ASSERT (result != NULL);
8839
5efc1d668039 Accomodate for implementations that produce 3 exponent digits in %e and %g.
Bruno Haible <bruno@clisp.org>
parents: 8836
diff changeset
2109 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
2110 || 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
2111 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2112 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2113 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2114
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2115 { /* FLAG_ALT. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2116 char *result;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2117 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2118 my_asprintf (&result, "%#.e %d", 9.75, 33, 44, 55);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2119 ASSERT (result != NULL);
8839
5efc1d668039 Accomodate for implementations that produce 3 exponent digits in %e and %g.
Bruno Haible <bruno@clisp.org>
parents: 8836
diff changeset
2120 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
2121 || 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
2122 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2123 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2124 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2125
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2126 { /* FLAG_ZERO with finite number. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2127 char *result;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2128 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2129 my_asprintf (&result, "%015e %d", 1234.0, 33, 44, 55);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2130 ASSERT (result != NULL);
8839
5efc1d668039 Accomodate for implementations that produce 3 exponent digits in %e and %g.
Bruno Haible <bruno@clisp.org>
parents: 8836
diff changeset
2131 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
2132 || 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
2133 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2134 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2135 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2136
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2137 { /* FLAG_ZERO with infinite number. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2138 char *result;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2139 int retval =
15595
328819af1c02 Support for MSVC compiler: Avoid division by a literal 0.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
2140 my_asprintf (&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
2141 ASSERT (result != NULL);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2142 ASSERT (strcmp (result, " -inf 33") == 0
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2143 || strcmp (result, " -infinity 33") == 0);
8836
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2144 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2145 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2146 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2147
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2148 { /* FLAG_ZERO with NaN. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2149 char *result;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2150 int retval =
9854
baba3b346ab2 Use macros NaNf, NaNd, NaNl instead of NAN.
Bruno Haible <bruno@clisp.org>
parents: 9850
diff changeset
2151 my_asprintf (&result, "%050e %d", NaNd (), 33, 44, 55);
8836
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2152 ASSERT (result != NULL);
8870
4e1f2ea486b4 Allow for a longer printed representation of NaN.
Bruno Haible <bruno@clisp.org>
parents: 8865
diff changeset
2153 ASSERT (strlen (result) == 50 + 3
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2154 && strisnan (result, strspn (result, " "), strlen (result) - 3, 0)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2155 && 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
2156 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2157 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2158 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2159
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2160 { /* Precision. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2161 char *result;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2162 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2163 my_asprintf (&result, "%.e %d", 1234.0, 33, 44, 55);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2164 ASSERT (result != NULL);
8839
5efc1d668039 Accomodate for implementations that produce 3 exponent digits in %e and %g.
Bruno Haible <bruno@clisp.org>
parents: 8836
diff changeset
2165 ASSERT (strcmp (result, "1e+03 33") == 0
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2166 || strcmp (result, "1e+003 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 free (result);
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
9938
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
2171 { /* Precision with no rounding. */
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
2172 char *result;
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
2173 int retval =
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
2174 my_asprintf (&result, "%.4e %d", 999.951, 33, 44, 55);
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
2175 ASSERT (result != NULL);
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
2176 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
2177 || strcmp (result, "9.9995e+002 33") == 0);
9938
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
2178 ASSERT (retval == strlen (result));
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
2179 free (result);
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
2180 }
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
2181
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
2182 { /* Precision with rounding. */
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
2183 char *result;
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
2184 int retval =
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
2185 my_asprintf (&result, "%.4e %d", 999.996, 33, 44, 55);
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
2186 ASSERT (result != NULL);
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
2187 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
2188 || strcmp (result, "1.0000e+003 33") == 0);
9938
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
2189 ASSERT (retval == strlen (result));
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
2190 free (result);
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
2191 }
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
2192
8836
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2193 { /* A positive number. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2194 char *result;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2195 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2196 my_asprintf (&result, "%Le %d", 12.75L, 33, 44, 55);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2197 ASSERT (result != NULL);
10458
1cc9cffb9615 Allow 3-digit exponents in %e and %g results on 'long double'.
Bruno Haible <bruno@clisp.org>
parents: 10394
diff changeset
2198 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
2199 || 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
2200 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2201 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2202 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2203
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2204 { /* A larger positive number. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2205 char *result;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2206 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2207 my_asprintf (&result, "%Le %d", 1234567.0L, 33, 44, 55);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2208 ASSERT (result != NULL);
10458
1cc9cffb9615 Allow 3-digit exponents in %e and %g results on 'long double'.
Bruno Haible <bruno@clisp.org>
parents: 10394
diff changeset
2209 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
2210 || 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
2211 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2212 free (result);
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
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2215 { /* Small and large positive numbers. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2216 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
2217 {
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2218 { 1.234321234321234e-37L, "1.234321e-37" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2219 { 1.234321234321234e-36L, "1.234321e-36" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2220 { 1.234321234321234e-35L, "1.234321e-35" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2221 { 1.234321234321234e-34L, "1.234321e-34" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2222 { 1.234321234321234e-33L, "1.234321e-33" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2223 { 1.234321234321234e-32L, "1.234321e-32" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2224 { 1.234321234321234e-31L, "1.234321e-31" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2225 { 1.234321234321234e-30L, "1.234321e-30" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2226 { 1.234321234321234e-29L, "1.234321e-29" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2227 { 1.234321234321234e-28L, "1.234321e-28" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2228 { 1.234321234321234e-27L, "1.234321e-27" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2229 { 1.234321234321234e-26L, "1.234321e-26" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2230 { 1.234321234321234e-25L, "1.234321e-25" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2231 { 1.234321234321234e-24L, "1.234321e-24" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2232 { 1.234321234321234e-23L, "1.234321e-23" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2233 { 1.234321234321234e-22L, "1.234321e-22" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2234 { 1.234321234321234e-21L, "1.234321e-21" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2235 { 1.234321234321234e-20L, "1.234321e-20" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2236 { 1.234321234321234e-19L, "1.234321e-19" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2237 { 1.234321234321234e-18L, "1.234321e-18" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2238 { 1.234321234321234e-17L, "1.234321e-17" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2239 { 1.234321234321234e-16L, "1.234321e-16" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2240 { 1.234321234321234e-15L, "1.234321e-15" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2241 { 1.234321234321234e-14L, "1.234321e-14" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2242 { 1.234321234321234e-13L, "1.234321e-13" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2243 { 1.234321234321234e-12L, "1.234321e-12" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2244 { 1.234321234321234e-11L, "1.234321e-11" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2245 { 1.234321234321234e-10L, "1.234321e-10" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2246 { 1.234321234321234e-9L, "1.234321e-09" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2247 { 1.234321234321234e-8L, "1.234321e-08" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2248 { 1.234321234321234e-7L, "1.234321e-07" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2249 { 1.234321234321234e-6L, "1.234321e-06" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2250 { 1.234321234321234e-5L, "1.234321e-05" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2251 { 1.234321234321234e-4L, "1.234321e-04" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2252 { 1.234321234321234e-3L, "1.234321e-03" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2253 { 1.234321234321234e-2L, "1.234321e-02" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2254 { 1.234321234321234e-1L, "1.234321e-01" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2255 { 1.234321234321234L, "1.234321e+00" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2256 { 1.234321234321234e1L, "1.234321e+01" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2257 { 1.234321234321234e2L, "1.234321e+02" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2258 { 1.234321234321234e3L, "1.234321e+03" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2259 { 1.234321234321234e4L, "1.234321e+04" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2260 { 1.234321234321234e5L, "1.234321e+05" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2261 { 1.234321234321234e6L, "1.234321e+06" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2262 { 1.234321234321234e7L, "1.234321e+07" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2263 { 1.234321234321234e8L, "1.234321e+08" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2264 { 1.234321234321234e9L, "1.234321e+09" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2265 { 1.234321234321234e10L, "1.234321e+10" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2266 { 1.234321234321234e11L, "1.234321e+11" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2267 { 1.234321234321234e12L, "1.234321e+12" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2268 { 1.234321234321234e13L, "1.234321e+13" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2269 { 1.234321234321234e14L, "1.234321e+14" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2270 { 1.234321234321234e15L, "1.234321e+15" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2271 { 1.234321234321234e16L, "1.234321e+16" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2272 { 1.234321234321234e17L, "1.234321e+17" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2273 { 1.234321234321234e18L, "1.234321e+18" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2274 { 1.234321234321234e19L, "1.234321e+19" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2275 { 1.234321234321234e20L, "1.234321e+20" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2276 { 1.234321234321234e21L, "1.234321e+21" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2277 { 1.234321234321234e22L, "1.234321e+22" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2278 { 1.234321234321234e23L, "1.234321e+23" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2279 { 1.234321234321234e24L, "1.234321e+24" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2280 { 1.234321234321234e25L, "1.234321e+25" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2281 { 1.234321234321234e26L, "1.234321e+26" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2282 { 1.234321234321234e27L, "1.234321e+27" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2283 { 1.234321234321234e28L, "1.234321e+28" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2284 { 1.234321234321234e29L, "1.234321e+29" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2285 { 1.234321234321234e30L, "1.234321e+30" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2286 { 1.234321234321234e31L, "1.234321e+31" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2287 { 1.234321234321234e32L, "1.234321e+32" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2288 { 1.234321234321234e33L, "1.234321e+33" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2289 { 1.234321234321234e34L, "1.234321e+34" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2290 { 1.234321234321234e35L, "1.234321e+35" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2291 { 1.234321234321234e36L, "1.234321e+36" }
8836
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2292 };
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2293 size_t k;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2294 for (k = 0; k < SIZEOF (data); k++)
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2295 {
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2296 char *result;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2297 int retval =
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2298 my_asprintf (&result, "%Le", data[k].value);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2299 const char *expected = data[k].string;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2300 ASSERT (result != NULL);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2301 ASSERT (strcmp (result, expected) == 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2302 /* Some implementations produce exponents with 3 digits. */
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2303 || (strlen (result) == strlen (expected) + 1
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2304 && memcmp (result, expected, strlen (expected) - 2) == 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2305 && result[strlen (expected) - 2] == '0'
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2306 && strcmp (result + strlen (expected) - 1,
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2307 expected + strlen (expected) - 2)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2308 == 0));
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2309 ASSERT (retval == strlen (result));
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2310 free (result);
8836
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2311 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2312 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2313
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2314 { /* A negative number. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2315 char *result;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2316 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2317 my_asprintf (&result, "%Le %d", -0.03125L, 33, 44, 55);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2318 ASSERT (result != NULL);
10458
1cc9cffb9615 Allow 3-digit exponents in %e and %g results on 'long double'.
Bruno Haible <bruno@clisp.org>
parents: 10394
diff changeset
2319 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
2320 || 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
2321 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2322 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2323 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2324
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2325 { /* Positive zero. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2326 char *result;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2327 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2328 my_asprintf (&result, "%Le %d", 0.0L, 33, 44, 55);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2329 ASSERT (result != NULL);
10458
1cc9cffb9615 Allow 3-digit exponents in %e and %g results on 'long double'.
Bruno Haible <bruno@clisp.org>
parents: 10394
diff changeset
2330 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
2331 || 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
2332 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2333 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2334 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2335
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2336 { /* Negative zero. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2337 char *result;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2338 int retval =
10601
ca053fa79cd3 Use a more portable replacement expression for -0.0L.
Bruno Haible <bruno@clisp.org>
parents: 10458
diff changeset
2339 my_asprintf (&result, "%Le %d", minus_zerol, 33, 44, 55);
8836
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2340 ASSERT (result != NULL);
8852
df0b5e8ea770 Avoid test failures on platforms where -0.0 and 0.0 are identical.
Bruno Haible <bruno@clisp.org>
parents: 8850
diff changeset
2341 if (have_minus_zero ())
10458
1cc9cffb9615 Allow 3-digit exponents in %e and %g results on 'long double'.
Bruno Haible <bruno@clisp.org>
parents: 10394
diff changeset
2342 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
2343 || 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
2344 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2345 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2346 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2347
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2348 { /* Positive infinity. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2349 char *result;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2350 int retval =
15595
328819af1c02 Support for MSVC compiler: Avoid division by a literal 0.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
2351 my_asprintf (&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
2352 ASSERT (result != NULL);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2353 ASSERT (strcmp (result, "inf 33") == 0
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2354 || strcmp (result, "infinity 33") == 0);
8836
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2355 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2356 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2357 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2358
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2359 { /* Negative infinity. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2360 char *result;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2361 int retval =
15595
328819af1c02 Support for MSVC compiler: Avoid division by a literal 0.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
2362 my_asprintf (&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
2363 ASSERT (result != NULL);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2364 ASSERT (strcmp (result, "-inf 33") == 0
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2365 || strcmp (result, "-infinity 33") == 0);
8836
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2366 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2367 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2368 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2369
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2370 { /* NaN. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2371 char *result;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2372 int retval =
9854
baba3b346ab2 Use macros NaNf, NaNd, NaNl instead of NAN.
Bruno Haible <bruno@clisp.org>
parents: 9850
diff changeset
2373 my_asprintf (&result, "%Le %d", NaNl (), 33, 44, 55);
8836
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2374 ASSERT (result != NULL);
8850
d1fe16dfbfee Avoid test failures on IRIX 6.5.
Bruno Haible <bruno@clisp.org>
parents: 8839
diff changeset
2375 ASSERT (strlen (result) >= 3 + 3
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2376 && strisnan (result, 0, strlen (result) - 3, 0)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2377 && 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
2378 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2379 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2380 }
15906
400649d35651 *printf-posix tests: Fix for platforms where 'long double' == 'double'.
Bruno Haible <bruno@clisp.org>
parents: 15595
diff changeset
2381 #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: 8891
diff changeset
2382 { /* Quiet NaN. */
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2383 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: 8891
diff changeset
2384 { 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: 8891
diff changeset
2385 char *result;
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2386 int retval =
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2387 my_asprintf (&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: 8891
diff changeset
2388 ASSERT (result != NULL);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2389 ASSERT (strlen (result) >= 3 + 3
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2390 && strisnan (result, 0, strlen (result) - 3, 0)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2391 && 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: 8891
diff changeset
2392 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: 8891
diff changeset
2393 free (result);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2394 }
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2395 {
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2396 /* Signalling NaN. */
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2397 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: 8891
diff changeset
2398 { 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: 8891
diff changeset
2399 char *result;
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2400 int retval =
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2401 my_asprintf (&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: 8891
diff changeset
2402 ASSERT (result != NULL);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2403 ASSERT (strlen (result) >= 3 + 3
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2404 && strisnan (result, 0, strlen (result) - 3, 0)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2405 && 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: 8891
diff changeset
2406 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: 8891
diff changeset
2407 free (result);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2408 }
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2409 /* The isnanl function should recognize Pseudo-NaNs, Pseudo-Infinities,
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2410 Pseudo-Zeroes, Unnormalized Numbers, and Pseudo-Denormals, as defined in
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2411 Intel IA-64 Architecture Software Developer's Manual, Volume 1:
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2412 Application Architecture.
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2413 Table 5-2 "Floating-Point Register Encodings"
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2414 Figure 5-6 "Memory to Floating-Point Register Data Translation"
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2415 */
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2416 { /* Pseudo-NaN. */
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2417 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: 8891
diff changeset
2418 { LDBL80_WORDS (0xFFFF, 0x40000001, 0x00000000) };
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2419 char *result;
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2420 int retval =
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2421 my_asprintf (&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: 8891
diff changeset
2422 ASSERT (result != NULL);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2423 ASSERT (strlen (result) >= 3 + 3
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2424 && strisnan (result, 0, strlen (result) - 3, 0)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2425 && 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: 8891
diff changeset
2426 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: 8891
diff changeset
2427 free (result);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2428 }
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2429 { /* Pseudo-Infinity. */
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2430 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: 8891
diff changeset
2431 { LDBL80_WORDS (0xFFFF, 0x00000000, 0x00000000) };
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2432 char *result;
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2433 int retval =
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2434 my_asprintf (&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: 8891
diff changeset
2435 ASSERT (result != NULL);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2436 ASSERT (strlen (result) >= 3 + 3
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2437 && strisnan (result, 0, strlen (result) - 3, 0)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2438 && 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: 8891
diff changeset
2439 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: 8891
diff changeset
2440 free (result);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2441 }
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2442 { /* Pseudo-Zero. */
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2443 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: 8891
diff changeset
2444 { 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: 8891
diff changeset
2445 char *result;
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2446 int retval =
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2447 my_asprintf (&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: 8891
diff changeset
2448 ASSERT (result != NULL);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2449 ASSERT (strlen (result) >= 3 + 3
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2450 && strisnan (result, 0, strlen (result) - 3, 0)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2451 && 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: 8891
diff changeset
2452 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: 8891
diff changeset
2453 free (result);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2454 }
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2455 { /* Unnormalized number. */
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2456 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: 8891
diff changeset
2457 { 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: 8891
diff changeset
2458 char *result;
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2459 int retval =
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2460 my_asprintf (&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: 8891
diff changeset
2461 ASSERT (result != NULL);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2462 ASSERT (strlen (result) >= 3 + 3
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2463 && strisnan (result, 0, strlen (result) - 3, 0)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2464 && 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: 8891
diff changeset
2465 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: 8891
diff changeset
2466 free (result);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2467 }
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2468 { /* Pseudo-Denormal. */
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2469 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: 8891
diff changeset
2470 { 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: 8891
diff changeset
2471 char *result;
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2472 int retval =
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2473 my_asprintf (&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: 8891
diff changeset
2474 ASSERT (result != NULL);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2475 ASSERT (strlen (result) >= 3 + 3
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2476 && strisnan (result, 0, strlen (result) - 3, 0)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2477 && 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: 8891
diff changeset
2478 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: 8891
diff changeset
2479 free (result);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2480 }
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2481 #endif
8836
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2482
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2483 { /* Width. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2484 char *result;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2485 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2486 my_asprintf (&result, "%15Le %d", 1.75L, 33, 44, 55);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2487 ASSERT (result != NULL);
10458
1cc9cffb9615 Allow 3-digit exponents in %e and %g results on 'long double'.
Bruno Haible <bruno@clisp.org>
parents: 10394
diff changeset
2488 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
2489 || 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
2490 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2491 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2492 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2493
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2494 { /* FLAG_LEFT. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2495 char *result;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2496 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2497 my_asprintf (&result, "%-15Le %d", 1.75L, 33, 44, 55);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2498 ASSERT (result != NULL);
10458
1cc9cffb9615 Allow 3-digit exponents in %e and %g results on 'long double'.
Bruno Haible <bruno@clisp.org>
parents: 10394
diff changeset
2499 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
2500 || 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
2501 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2502 free (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_SHOWSIGN. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2506 char *result;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2507 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2508 my_asprintf (&result, "%+Le %d", 1.75L, 33, 44, 55);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2509 ASSERT (result != NULL);
10458
1cc9cffb9615 Allow 3-digit exponents in %e and %g results on 'long double'.
Bruno Haible <bruno@clisp.org>
parents: 10394
diff changeset
2510 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
2511 || 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
2512 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2513 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2514 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2515
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2516 { /* FLAG_SPACE. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2517 char *result;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2518 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2519 my_asprintf (&result, "% Le %d", 1.75L, 33, 44, 55);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2520 ASSERT (result != NULL);
10458
1cc9cffb9615 Allow 3-digit exponents in %e and %g results on 'long double'.
Bruno Haible <bruno@clisp.org>
parents: 10394
diff changeset
2521 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
2522 || 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
2523 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2524 free (result);
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
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2527 { /* FLAG_ALT. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2528 char *result;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2529 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2530 my_asprintf (&result, "%#Le %d", 1.75L, 33, 44, 55);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2531 ASSERT (result != NULL);
10458
1cc9cffb9615 Allow 3-digit exponents in %e and %g results on 'long double'.
Bruno Haible <bruno@clisp.org>
parents: 10394
diff changeset
2532 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
2533 || 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
2534 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2535 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2536 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2537
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2538 { /* FLAG_ALT. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2539 char *result;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2540 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2541 my_asprintf (&result, "%#.Le %d", 1.75L, 33, 44, 55);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2542 ASSERT (result != NULL);
10458
1cc9cffb9615 Allow 3-digit exponents in %e and %g results on 'long double'.
Bruno Haible <bruno@clisp.org>
parents: 10394
diff changeset
2543 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
2544 || 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
2545 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2546 free (result);
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
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2549 { /* FLAG_ALT. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2550 char *result;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2551 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2552 my_asprintf (&result, "%#.Le %d", 9.75L, 33, 44, 55);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2553 ASSERT (result != NULL);
10458
1cc9cffb9615 Allow 3-digit exponents in %e and %g results on 'long double'.
Bruno Haible <bruno@clisp.org>
parents: 10394
diff changeset
2554 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
2555 || 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
2556 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2557 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2558 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2559
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2560 { /* FLAG_ZERO with finite number. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2561 char *result;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2562 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2563 my_asprintf (&result, "%015Le %d", 1234.0L, 33, 44, 55);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2564 ASSERT (result != NULL);
10458
1cc9cffb9615 Allow 3-digit exponents in %e and %g results on 'long double'.
Bruno Haible <bruno@clisp.org>
parents: 10394
diff changeset
2565 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
2566 || 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
2567 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2568 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2569 }
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 { /* FLAG_ZERO with infinite number. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2572 char *result;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2573 int retval =
15595
328819af1c02 Support for MSVC compiler: Avoid division by a literal 0.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
2574 my_asprintf (&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
2575 ASSERT (result != NULL);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2576 ASSERT (strcmp (result, " -inf 33") == 0
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2577 || strcmp (result, " -infinity 33") == 0);
8836
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2578 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2579 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2580 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2581
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2582 { /* FLAG_ZERO with NaN. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2583 char *result;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2584 int retval =
9854
baba3b346ab2 Use macros NaNf, NaNd, NaNl instead of NAN.
Bruno Haible <bruno@clisp.org>
parents: 9850
diff changeset
2585 my_asprintf (&result, "%050Le %d", NaNl (), 33, 44, 55);
8836
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2586 ASSERT (result != NULL);
8870
4e1f2ea486b4 Allow for a longer printed representation of NaN.
Bruno Haible <bruno@clisp.org>
parents: 8865
diff changeset
2587 ASSERT (strlen (result) == 50 + 3
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2588 && strisnan (result, strspn (result, " "), strlen (result) - 3, 0)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2589 && 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
2590 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2591 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2592 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2593
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2594 { /* Precision. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2595 char *result;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2596 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2597 my_asprintf (&result, "%.Le %d", 1234.0L, 33, 44, 55);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2598 ASSERT (result != NULL);
10458
1cc9cffb9615 Allow 3-digit exponents in %e and %g results on 'long double'.
Bruno Haible <bruno@clisp.org>
parents: 10394
diff changeset
2599 ASSERT (strcmp (result, "1e+03 33") == 0
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2600 || strcmp (result, "1e+003 33") == 0);
8836
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2601 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2602 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2603 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2604
9938
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
2605 { /* Precision with no rounding. */
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
2606 char *result;
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
2607 int retval =
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
2608 my_asprintf (&result, "%.4Le %d", 999.951L, 33, 44, 55);
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
2609 ASSERT (result != NULL);
10458
1cc9cffb9615 Allow 3-digit exponents in %e and %g results on 'long double'.
Bruno Haible <bruno@clisp.org>
parents: 10394
diff changeset
2610 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
2611 || strcmp (result, "9.9995e+002 33") == 0);
9938
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
2612 ASSERT (retval == strlen (result));
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
2613 free (result);
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
2614 }
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
2615
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
2616 { /* Precision with rounding. */
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
2617 char *result;
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
2618 int retval =
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
2619 my_asprintf (&result, "%.4Le %d", 999.996L, 33, 44, 55);
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
2620 ASSERT (result != NULL);
10458
1cc9cffb9615 Allow 3-digit exponents in %e and %g results on 'long double'.
Bruno Haible <bruno@clisp.org>
parents: 10394
diff changeset
2621 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
2622 || strcmp (result, "1.0000e+003 33") == 0);
9938
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
2623 ASSERT (retval == strlen (result));
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
2624 free (result);
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
2625 }
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
2626
8836
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2627 /* 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
2628
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2629 { /* A positive number. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2630 char *result;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2631 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2632 my_asprintf (&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
2633 ASSERT (result != NULL);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2634 ASSERT (strcmp (result, "12.75 33") == 0);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2635 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2636 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2637 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2638
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2639 { /* A larger positive number. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2640 char *result;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2641 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2642 my_asprintf (&result, "%g %d", 1234567.0, 33, 44, 55);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2643 ASSERT (result != NULL);
8839
5efc1d668039 Accomodate for implementations that produce 3 exponent digits in %e and %g.
Bruno Haible <bruno@clisp.org>
parents: 8836
diff changeset
2644 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
2645 || 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
2646 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2647 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2648 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2649
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2650 { /* Small and large positive numbers. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2651 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
2652 {
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2653 { 1.234321234321234e-37, "1.23432e-37" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2654 { 1.234321234321234e-36, "1.23432e-36" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2655 { 1.234321234321234e-35, "1.23432e-35" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2656 { 1.234321234321234e-34, "1.23432e-34" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2657 { 1.234321234321234e-33, "1.23432e-33" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2658 { 1.234321234321234e-32, "1.23432e-32" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2659 { 1.234321234321234e-31, "1.23432e-31" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2660 { 1.234321234321234e-30, "1.23432e-30" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2661 { 1.234321234321234e-29, "1.23432e-29" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2662 { 1.234321234321234e-28, "1.23432e-28" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2663 { 1.234321234321234e-27, "1.23432e-27" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2664 { 1.234321234321234e-26, "1.23432e-26" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2665 { 1.234321234321234e-25, "1.23432e-25" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2666 { 1.234321234321234e-24, "1.23432e-24" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2667 { 1.234321234321234e-23, "1.23432e-23" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2668 { 1.234321234321234e-22, "1.23432e-22" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2669 { 1.234321234321234e-21, "1.23432e-21" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2670 { 1.234321234321234e-20, "1.23432e-20" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2671 { 1.234321234321234e-19, "1.23432e-19" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2672 { 1.234321234321234e-18, "1.23432e-18" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2673 { 1.234321234321234e-17, "1.23432e-17" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2674 { 1.234321234321234e-16, "1.23432e-16" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2675 { 1.234321234321234e-15, "1.23432e-15" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2676 { 1.234321234321234e-14, "1.23432e-14" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2677 { 1.234321234321234e-13, "1.23432e-13" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2678 { 1.234321234321234e-12, "1.23432e-12" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2679 { 1.234321234321234e-11, "1.23432e-11" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2680 { 1.234321234321234e-10, "1.23432e-10" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2681 { 1.234321234321234e-9, "1.23432e-09" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2682 { 1.234321234321234e-8, "1.23432e-08" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2683 { 1.234321234321234e-7, "1.23432e-07" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2684 { 1.234321234321234e-6, "1.23432e-06" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2685 { 1.234321234321234e-5, "1.23432e-05" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2686 { 1.234321234321234e-4, "0.000123432" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2687 { 1.234321234321234e-3, "0.00123432" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2688 { 1.234321234321234e-2, "0.0123432" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2689 { 1.234321234321234e-1, "0.123432" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2690 { 1.234321234321234, "1.23432" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2691 { 1.234321234321234e1, "12.3432" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2692 { 1.234321234321234e2, "123.432" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2693 { 1.234321234321234e3, "1234.32" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2694 { 1.234321234321234e4, "12343.2" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2695 { 1.234321234321234e5, "123432" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2696 { 1.234321234321234e6, "1.23432e+06" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2697 { 1.234321234321234e7, "1.23432e+07" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2698 { 1.234321234321234e8, "1.23432e+08" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2699 { 1.234321234321234e9, "1.23432e+09" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2700 { 1.234321234321234e10, "1.23432e+10" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2701 { 1.234321234321234e11, "1.23432e+11" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2702 { 1.234321234321234e12, "1.23432e+12" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2703 { 1.234321234321234e13, "1.23432e+13" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2704 { 1.234321234321234e14, "1.23432e+14" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2705 { 1.234321234321234e15, "1.23432e+15" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2706 { 1.234321234321234e16, "1.23432e+16" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2707 { 1.234321234321234e17, "1.23432e+17" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2708 { 1.234321234321234e18, "1.23432e+18" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2709 { 1.234321234321234e19, "1.23432e+19" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2710 { 1.234321234321234e20, "1.23432e+20" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2711 { 1.234321234321234e21, "1.23432e+21" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2712 { 1.234321234321234e22, "1.23432e+22" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2713 { 1.234321234321234e23, "1.23432e+23" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2714 { 1.234321234321234e24, "1.23432e+24" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2715 { 1.234321234321234e25, "1.23432e+25" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2716 { 1.234321234321234e26, "1.23432e+26" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2717 { 1.234321234321234e27, "1.23432e+27" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2718 { 1.234321234321234e28, "1.23432e+28" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2719 { 1.234321234321234e29, "1.23432e+29" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2720 { 1.234321234321234e30, "1.23432e+30" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2721 { 1.234321234321234e31, "1.23432e+31" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2722 { 1.234321234321234e32, "1.23432e+32" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2723 { 1.234321234321234e33, "1.23432e+33" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2724 { 1.234321234321234e34, "1.23432e+34" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2725 { 1.234321234321234e35, "1.23432e+35" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2726 { 1.234321234321234e36, "1.23432e+36" }
8836
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2727 };
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2728 size_t k;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2729 for (k = 0; k < SIZEOF (data); k++)
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2730 {
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2731 char *result;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2732 int retval =
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2733 my_asprintf (&result, "%g", data[k].value);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2734 const char *expected = data[k].string;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2735 ASSERT (result != NULL);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2736 ASSERT (strcmp (result, expected) == 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2737 /* Some implementations produce exponents with 3 digits. */
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2738 || (expected[strlen (expected) - 4] == 'e'
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2739 && strlen (result) == strlen (expected) + 1
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2740 && memcmp (result, expected, strlen (expected) - 2) == 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2741 && result[strlen (expected) - 2] == '0'
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2742 && strcmp (result + strlen (expected) - 1,
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2743 expected + strlen (expected) - 2)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2744 == 0));
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2745 ASSERT (retval == strlen (result));
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2746 free (result);
8836
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2747 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2748 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2749
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2750 { /* A negative number. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2751 char *result;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2752 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2753 my_asprintf (&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
2754 ASSERT (result != NULL);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2755 ASSERT (strcmp (result, "-0.03125 33") == 0);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2756 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2757 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2758 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2759
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2760 { /* Positive zero. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2761 char *result;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2762 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2763 my_asprintf (&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
2764 ASSERT (result != NULL);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2765 ASSERT (strcmp (result, "0 33") == 0);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2766 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2767 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2768 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2769
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2770 { /* Negative zero. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2771 char *result;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2772 int retval =
13834
108bbfd6f03b frexp, tests: work around ICC bug with -zero
Eric Blake <eblake@redhat.com>
parents: 12559
diff changeset
2773 my_asprintf (&result, "%g %d", minus_zerod, 33, 44, 55);
8836
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2774 ASSERT (result != NULL);
8852
df0b5e8ea770 Avoid test failures on platforms where -0.0 and 0.0 are identical.
Bruno Haible <bruno@clisp.org>
parents: 8850
diff changeset
2775 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
2776 ASSERT (strcmp (result, "-0 33") == 0);
8836
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2777 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2778 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2779 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2780
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2781 { /* Positive infinity. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2782 char *result;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2783 int retval =
15595
328819af1c02 Support for MSVC compiler: Avoid division by a literal 0.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
2784 my_asprintf (&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
2785 ASSERT (result != NULL);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2786 ASSERT (strcmp (result, "inf 33") == 0
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2787 || strcmp (result, "infinity 33") == 0);
8836
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2788 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2789 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2790 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2791
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2792 { /* Negative infinity. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2793 char *result;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2794 int retval =
15595
328819af1c02 Support for MSVC compiler: Avoid division by a literal 0.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
2795 my_asprintf (&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
2796 ASSERT (result != NULL);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2797 ASSERT (strcmp (result, "-inf 33") == 0
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2798 || strcmp (result, "-infinity 33") == 0);
8836
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2799 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2800 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2801 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2802
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2803 { /* NaN. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2804 char *result;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2805 int retval =
9854
baba3b346ab2 Use macros NaNf, NaNd, NaNl instead of NAN.
Bruno Haible <bruno@clisp.org>
parents: 9850
diff changeset
2806 my_asprintf (&result, "%g %d", NaNd (), 33, 44, 55);
8836
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2807 ASSERT (result != NULL);
8850
d1fe16dfbfee Avoid test failures on IRIX 6.5.
Bruno Haible <bruno@clisp.org>
parents: 8839
diff changeset
2808 ASSERT (strlen (result) >= 3 + 3
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2809 && strisnan (result, 0, strlen (result) - 3, 0)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2810 && 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
2811 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2812 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2813 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2814
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2815 { /* Width. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2816 char *result;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2817 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2818 my_asprintf (&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
2819 ASSERT (result != NULL);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2820 ASSERT (strcmp (result, " 1.75 33") == 0);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2821 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2822 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2823 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2824
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2825 { /* FLAG_LEFT. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2826 char *result;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2827 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2828 my_asprintf (&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
2829 ASSERT (result != NULL);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2830 ASSERT (strcmp (result, "1.75 33") == 0);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2831 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2832 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2833 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2834
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2835 { /* FLAG_SHOWSIGN. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2836 char *result;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2837 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2838 my_asprintf (&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
2839 ASSERT (result != NULL);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2840 ASSERT (strcmp (result, "+1.75 33") == 0);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2841 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2842 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2843 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2844
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2845 { /* FLAG_SPACE. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2846 char *result;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2847 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2848 my_asprintf (&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
2849 ASSERT (result != NULL);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2850 ASSERT (strcmp (result, " 1.75 33") == 0);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2851 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2852 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2853 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2854
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2855 { /* FLAG_ALT. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2856 char *result;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2857 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2858 my_asprintf (&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
2859 ASSERT (result != NULL);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2860 ASSERT (strcmp (result, "1.75000 33") == 0);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2861 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2862 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2863 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2864
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2865 { /* FLAG_ALT. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2866 char *result;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2867 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2868 my_asprintf (&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
2869 ASSERT (result != NULL);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2870 ASSERT (strcmp (result, "2. 33") == 0);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2871 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2872 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2873 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2874
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2875 { /* FLAG_ALT. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2876 char *result;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2877 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2878 my_asprintf (&result, "%#.g %d", 9.75, 33, 44, 55);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2879 ASSERT (result != NULL);
8839
5efc1d668039 Accomodate for implementations that produce 3 exponent digits in %e and %g.
Bruno Haible <bruno@clisp.org>
parents: 8836
diff changeset
2880 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
2881 || 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
2882 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2883 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2884 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2885
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2886 { /* FLAG_ZERO with finite number. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2887 char *result;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2888 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2889 my_asprintf (&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
2890 ASSERT (result != NULL);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2891 ASSERT (strcmp (result, "0000001234 33") == 0);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2892 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2893 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2894 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2895
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2896 { /* FLAG_ZERO with infinite number. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2897 char *result;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2898 int retval =
15595
328819af1c02 Support for MSVC compiler: Avoid division by a literal 0.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
2899 my_asprintf (&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
2900 ASSERT (result != NULL);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2901 ASSERT (strcmp (result, " -inf 33") == 0
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2902 || strcmp (result, " -infinity 33") == 0);
8836
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2903 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2904 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2905 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2906
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2907 { /* FLAG_ZERO with NaN. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2908 char *result;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2909 int retval =
9854
baba3b346ab2 Use macros NaNf, NaNd, NaNl instead of NAN.
Bruno Haible <bruno@clisp.org>
parents: 9850
diff changeset
2910 my_asprintf (&result, "%050g %d", NaNd (), 33, 44, 55);
8836
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2911 ASSERT (result != NULL);
8870
4e1f2ea486b4 Allow for a longer printed representation of NaN.
Bruno Haible <bruno@clisp.org>
parents: 8865
diff changeset
2912 ASSERT (strlen (result) == 50 + 3
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2913 && strisnan (result, strspn (result, " "), strlen (result) - 3, 0)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2914 && 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
2915 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2916 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2917 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2918
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2919 { /* Precision. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2920 char *result;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2921 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2922 my_asprintf (&result, "%.g %d", 1234.0, 33, 44, 55);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2923 ASSERT (result != NULL);
8839
5efc1d668039 Accomodate for implementations that produce 3 exponent digits in %e and %g.
Bruno Haible <bruno@clisp.org>
parents: 8836
diff changeset
2924 ASSERT (strcmp (result, "1e+03 33") == 0
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2925 || strcmp (result, "1e+003 33") == 0);
8836
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2926 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2927 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2928 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2929
9938
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
2930 { /* Precision with no rounding. */
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
2931 char *result;
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
2932 int retval =
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
2933 my_asprintf (&result, "%.5g %d", 999.951, 33, 44, 55);
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
2934 ASSERT (result != NULL);
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
2935 ASSERT (strcmp (result, "999.95 33") == 0);
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
2936 ASSERT (retval == strlen (result));
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
2937 free (result);
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
2938 }
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
2939
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
2940 { /* Precision with rounding. */
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
2941 char *result;
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
2942 int retval =
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
2943 my_asprintf (&result, "%.5g %d", 999.996, 33, 44, 55);
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
2944 ASSERT (result != NULL);
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
2945 ASSERT (strcmp (result, "1000 33") == 0);
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
2946 ASSERT (retval == strlen (result));
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
2947 free (result);
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
2948 }
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
2949
8836
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2950 { /* A positive number. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2951 char *result;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2952 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2953 my_asprintf (&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
2954 ASSERT (result != NULL);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2955 ASSERT (strcmp (result, "12.75 33") == 0);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2956 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2957 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2958 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2959
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2960 { /* A larger positive number. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2961 char *result;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2962 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2963 my_asprintf (&result, "%Lg %d", 1234567.0L, 33, 44, 55);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2964 ASSERT (result != NULL);
10458
1cc9cffb9615 Allow 3-digit exponents in %e and %g results on 'long double'.
Bruno Haible <bruno@clisp.org>
parents: 10394
diff changeset
2965 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
2966 || 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
2967 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2968 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2969 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2970
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2971 { /* Small and large positive numbers. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2972 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
2973 {
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2974 { 1.234321234321234e-37L, "1.23432e-37" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2975 { 1.234321234321234e-36L, "1.23432e-36" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2976 { 1.234321234321234e-35L, "1.23432e-35" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2977 { 1.234321234321234e-34L, "1.23432e-34" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2978 { 1.234321234321234e-33L, "1.23432e-33" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2979 { 1.234321234321234e-32L, "1.23432e-32" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2980 { 1.234321234321234e-31L, "1.23432e-31" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2981 { 1.234321234321234e-30L, "1.23432e-30" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2982 { 1.234321234321234e-29L, "1.23432e-29" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2983 { 1.234321234321234e-28L, "1.23432e-28" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2984 { 1.234321234321234e-27L, "1.23432e-27" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2985 { 1.234321234321234e-26L, "1.23432e-26" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2986 { 1.234321234321234e-25L, "1.23432e-25" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2987 { 1.234321234321234e-24L, "1.23432e-24" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2988 { 1.234321234321234e-23L, "1.23432e-23" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2989 { 1.234321234321234e-22L, "1.23432e-22" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2990 { 1.234321234321234e-21L, "1.23432e-21" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2991 { 1.234321234321234e-20L, "1.23432e-20" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2992 { 1.234321234321234e-19L, "1.23432e-19" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2993 { 1.234321234321234e-18L, "1.23432e-18" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2994 { 1.234321234321234e-17L, "1.23432e-17" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2995 { 1.234321234321234e-16L, "1.23432e-16" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2996 { 1.234321234321234e-15L, "1.23432e-15" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2997 { 1.234321234321234e-14L, "1.23432e-14" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2998 { 1.234321234321234e-13L, "1.23432e-13" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
2999 { 1.234321234321234e-12L, "1.23432e-12" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
3000 { 1.234321234321234e-11L, "1.23432e-11" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
3001 { 1.234321234321234e-10L, "1.23432e-10" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
3002 { 1.234321234321234e-9L, "1.23432e-09" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
3003 { 1.234321234321234e-8L, "1.23432e-08" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
3004 { 1.234321234321234e-7L, "1.23432e-07" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
3005 { 1.234321234321234e-6L, "1.23432e-06" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
3006 { 1.234321234321234e-5L, "1.23432e-05" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
3007 { 1.234321234321234e-4L, "0.000123432" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
3008 { 1.234321234321234e-3L, "0.00123432" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
3009 { 1.234321234321234e-2L, "0.0123432" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
3010 { 1.234321234321234e-1L, "0.123432" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
3011 { 1.234321234321234L, "1.23432" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
3012 { 1.234321234321234e1L, "12.3432" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
3013 { 1.234321234321234e2L, "123.432" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
3014 { 1.234321234321234e3L, "1234.32" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
3015 { 1.234321234321234e4L, "12343.2" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
3016 { 1.234321234321234e5L, "123432" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
3017 { 1.234321234321234e6L, "1.23432e+06" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
3018 { 1.234321234321234e7L, "1.23432e+07" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
3019 { 1.234321234321234e8L, "1.23432e+08" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
3020 { 1.234321234321234e9L, "1.23432e+09" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
3021 { 1.234321234321234e10L, "1.23432e+10" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
3022 { 1.234321234321234e11L, "1.23432e+11" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
3023 { 1.234321234321234e12L, "1.23432e+12" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
3024 { 1.234321234321234e13L, "1.23432e+13" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
3025 { 1.234321234321234e14L, "1.23432e+14" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
3026 { 1.234321234321234e15L, "1.23432e+15" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
3027 { 1.234321234321234e16L, "1.23432e+16" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
3028 { 1.234321234321234e17L, "1.23432e+17" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
3029 { 1.234321234321234e18L, "1.23432e+18" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
3030 { 1.234321234321234e19L, "1.23432e+19" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
3031 { 1.234321234321234e20L, "1.23432e+20" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
3032 { 1.234321234321234e21L, "1.23432e+21" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
3033 { 1.234321234321234e22L, "1.23432e+22" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
3034 { 1.234321234321234e23L, "1.23432e+23" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
3035 { 1.234321234321234e24L, "1.23432e+24" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
3036 { 1.234321234321234e25L, "1.23432e+25" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
3037 { 1.234321234321234e26L, "1.23432e+26" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
3038 { 1.234321234321234e27L, "1.23432e+27" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
3039 { 1.234321234321234e28L, "1.23432e+28" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
3040 { 1.234321234321234e29L, "1.23432e+29" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
3041 { 1.234321234321234e30L, "1.23432e+30" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
3042 { 1.234321234321234e31L, "1.23432e+31" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
3043 { 1.234321234321234e32L, "1.23432e+32" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
3044 { 1.234321234321234e33L, "1.23432e+33" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
3045 { 1.234321234321234e34L, "1.23432e+34" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
3046 { 1.234321234321234e35L, "1.23432e+35" },
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
3047 { 1.234321234321234e36L, "1.23432e+36" }
8836
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3048 };
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3049 size_t k;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3050 for (k = 0; k < SIZEOF (data); k++)
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3051 {
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
3052 char *result;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
3053 int retval =
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
3054 my_asprintf (&result, "%Lg", data[k].value);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
3055 const char *expected = data[k].string;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
3056 ASSERT (result != NULL);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
3057 ASSERT (strcmp (result, expected) == 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
3058 /* Some implementations produce exponents with 3 digits. */
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
3059 || (expected[strlen (expected) - 4] == 'e'
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
3060 && strlen (result) == strlen (expected) + 1
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
3061 && memcmp (result, expected, strlen (expected) - 2) == 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
3062 && result[strlen (expected) - 2] == '0'
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
3063 && strcmp (result + strlen (expected) - 1,
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
3064 expected + strlen (expected) - 2)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
3065 == 0));
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
3066 ASSERT (retval == strlen (result));
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
3067 free (result);
8836
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3068 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3069 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3070
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3071 { /* A negative number. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3072 char *result;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3073 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3074 my_asprintf (&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
3075 ASSERT (result != NULL);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3076 ASSERT (strcmp (result, "-0.03125 33") == 0);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3077 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3078 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3079 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3080
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3081 { /* Positive zero. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3082 char *result;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3083 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3084 my_asprintf (&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
3085 ASSERT (result != NULL);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3086 ASSERT (strcmp (result, "0 33") == 0);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3087 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3088 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3089 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3090
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3091 { /* Negative zero. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3092 char *result;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3093 int retval =
10601
ca053fa79cd3 Use a more portable replacement expression for -0.0L.
Bruno Haible <bruno@clisp.org>
parents: 10458
diff changeset
3094 my_asprintf (&result, "%Lg %d", minus_zerol, 33, 44, 55);
8836
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3095 ASSERT (result != NULL);
8852
df0b5e8ea770 Avoid test failures on platforms where -0.0 and 0.0 are identical.
Bruno Haible <bruno@clisp.org>
parents: 8850
diff changeset
3096 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
3097 ASSERT (strcmp (result, "-0 33") == 0);
8836
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3098 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3099 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3100 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3101
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3102 { /* Positive infinity. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3103 char *result;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3104 int retval =
15595
328819af1c02 Support for MSVC compiler: Avoid division by a literal 0.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
3105 my_asprintf (&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
3106 ASSERT (result != NULL);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3107 ASSERT (strcmp (result, "inf 33") == 0
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
3108 || strcmp (result, "infinity 33") == 0);
8836
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3109 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3110 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3111 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3112
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3113 { /* Negative infinity. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3114 char *result;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3115 int retval =
15595
328819af1c02 Support for MSVC compiler: Avoid division by a literal 0.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
3116 my_asprintf (&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
3117 ASSERT (result != NULL);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3118 ASSERT (strcmp (result, "-inf 33") == 0
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
3119 || strcmp (result, "-infinity 33") == 0);
8836
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3120 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3121 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3122 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3123
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3124 { /* NaN. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3125 char *result;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3126 int retval =
9854
baba3b346ab2 Use macros NaNf, NaNd, NaNl instead of NAN.
Bruno Haible <bruno@clisp.org>
parents: 9850
diff changeset
3127 my_asprintf (&result, "%Lg %d", NaNl (), 33, 44, 55);
8836
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3128 ASSERT (result != NULL);
8850
d1fe16dfbfee Avoid test failures on IRIX 6.5.
Bruno Haible <bruno@clisp.org>
parents: 8839
diff changeset
3129 ASSERT (strlen (result) >= 3 + 3
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
3130 && strisnan (result, 0, strlen (result) - 3, 0)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
3131 && 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
3132 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3133 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3134 }
15906
400649d35651 *printf-posix tests: Fix for platforms where 'long double' == 'double'.
Bruno Haible <bruno@clisp.org>
parents: 15595
diff changeset
3135 #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: 8891
diff changeset
3136 { /* Quiet NaN. */
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3137 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: 8891
diff changeset
3138 { 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: 8891
diff changeset
3139 char *result;
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3140 int retval =
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3141 my_asprintf (&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: 8891
diff changeset
3142 ASSERT (result != NULL);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3143 ASSERT (strlen (result) >= 3 + 3
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
3144 && strisnan (result, 0, strlen (result) - 3, 0)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
3145 && 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: 8891
diff changeset
3146 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: 8891
diff changeset
3147 free (result);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3148 }
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3149 {
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3150 /* Signalling NaN. */
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3151 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: 8891
diff changeset
3152 { 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: 8891
diff changeset
3153 char *result;
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3154 int retval =
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3155 my_asprintf (&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: 8891
diff changeset
3156 ASSERT (result != NULL);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3157 ASSERT (strlen (result) >= 3 + 3
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
3158 && strisnan (result, 0, strlen (result) - 3, 0)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
3159 && 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: 8891
diff changeset
3160 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: 8891
diff changeset
3161 free (result);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3162 }
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3163 /* The isnanl function should recognize Pseudo-NaNs, Pseudo-Infinities,
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3164 Pseudo-Zeroes, Unnormalized Numbers, and Pseudo-Denormals, as defined in
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3165 Intel IA-64 Architecture Software Developer's Manual, Volume 1:
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3166 Application Architecture.
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3167 Table 5-2 "Floating-Point Register Encodings"
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3168 Figure 5-6 "Memory to Floating-Point Register Data Translation"
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3169 */
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3170 { /* Pseudo-NaN. */
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3171 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: 8891
diff changeset
3172 { LDBL80_WORDS (0xFFFF, 0x40000001, 0x00000000) };
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3173 char *result;
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3174 int retval =
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3175 my_asprintf (&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: 8891
diff changeset
3176 ASSERT (result != NULL);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3177 ASSERT (strlen (result) >= 3 + 3
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
3178 && strisnan (result, 0, strlen (result) - 3, 0)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
3179 && 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: 8891
diff changeset
3180 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: 8891
diff changeset
3181 free (result);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3182 }
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3183 { /* Pseudo-Infinity. */
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3184 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: 8891
diff changeset
3185 { LDBL80_WORDS (0xFFFF, 0x00000000, 0x00000000) };
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3186 char *result;
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3187 int retval =
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3188 my_asprintf (&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: 8891
diff changeset
3189 ASSERT (result != NULL);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3190 ASSERT (strlen (result) >= 3 + 3
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
3191 && strisnan (result, 0, strlen (result) - 3, 0)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
3192 && 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: 8891
diff changeset
3193 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: 8891
diff changeset
3194 free (result);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3195 }
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3196 { /* Pseudo-Zero. */
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3197 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: 8891
diff changeset
3198 { 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: 8891
diff changeset
3199 char *result;
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3200 int retval =
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3201 my_asprintf (&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: 8891
diff changeset
3202 ASSERT (result != NULL);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3203 ASSERT (strlen (result) >= 3 + 3
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
3204 && strisnan (result, 0, strlen (result) - 3, 0)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
3205 && 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: 8891
diff changeset
3206 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: 8891
diff changeset
3207 free (result);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3208 }
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3209 { /* Unnormalized number. */
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3210 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: 8891
diff changeset
3211 { 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: 8891
diff changeset
3212 char *result;
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3213 int retval =
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3214 my_asprintf (&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: 8891
diff changeset
3215 ASSERT (result != NULL);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3216 ASSERT (strlen (result) >= 3 + 3
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
3217 && strisnan (result, 0, strlen (result) - 3, 0)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
3218 && 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: 8891
diff changeset
3219 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: 8891
diff changeset
3220 free (result);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3221 }
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3222 { /* Pseudo-Denormal. */
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3223 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: 8891
diff changeset
3224 { 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: 8891
diff changeset
3225 char *result;
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3226 int retval =
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3227 my_asprintf (&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: 8891
diff changeset
3228 ASSERT (result != NULL);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3229 ASSERT (strlen (result) >= 3 + 3
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
3230 && strisnan (result, 0, strlen (result) - 3, 0)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
3231 && 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: 8891
diff changeset
3232 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: 8891
diff changeset
3233 free (result);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3234 }
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3235 #endif
8836
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3236
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3237 { /* Width. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3238 char *result;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3239 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3240 my_asprintf (&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
3241 ASSERT (result != NULL);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3242 ASSERT (strcmp (result, " 1.75 33") == 0);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3243 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3244 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3245 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3246
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3247 { /* FLAG_LEFT. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3248 char *result;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3249 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3250 my_asprintf (&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
3251 ASSERT (result != NULL);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3252 ASSERT (strcmp (result, "1.75 33") == 0);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3253 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3254 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3255 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3256
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3257 { /* FLAG_SHOWSIGN. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3258 char *result;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3259 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3260 my_asprintf (&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
3261 ASSERT (result != NULL);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3262 ASSERT (strcmp (result, "+1.75 33") == 0);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3263 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3264 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3265 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3266
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3267 { /* FLAG_SPACE. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3268 char *result;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3269 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3270 my_asprintf (&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
3271 ASSERT (result != NULL);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3272 ASSERT (strcmp (result, " 1.75 33") == 0);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3273 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3274 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3275 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3276
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3277 { /* FLAG_ALT. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3278 char *result;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3279 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3280 my_asprintf (&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
3281 ASSERT (result != NULL);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3282 ASSERT (strcmp (result, "1.75000 33") == 0);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3283 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3284 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3285 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3286
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3287 { /* FLAG_ALT. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3288 char *result;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3289 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3290 my_asprintf (&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
3291 ASSERT (result != NULL);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3292 ASSERT (strcmp (result, "2. 33") == 0);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3293 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3294 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3295 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3296
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3297 { /* FLAG_ALT. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3298 char *result;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3299 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3300 my_asprintf (&result, "%#.Lg %d", 9.75L, 33, 44, 55);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3301 ASSERT (result != NULL);
10458
1cc9cffb9615 Allow 3-digit exponents in %e and %g results on 'long double'.
Bruno Haible <bruno@clisp.org>
parents: 10394
diff changeset
3302 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
3303 || 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
3304 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3305 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3306 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3307
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3308 { /* FLAG_ZERO with finite number. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3309 char *result;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3310 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3311 my_asprintf (&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
3312 ASSERT (result != NULL);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3313 ASSERT (strcmp (result, "0000001234 33") == 0);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3314 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3315 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3316 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3317
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3318 { /* FLAG_ZERO with infinite number. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3319 char *result;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3320 int retval =
15595
328819af1c02 Support for MSVC compiler: Avoid division by a literal 0.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
3321 my_asprintf (&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
3322 ASSERT (result != NULL);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3323 ASSERT (strcmp (result, " -inf 33") == 0
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
3324 || strcmp (result, " -infinity 33") == 0);
8836
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3325 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3326 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3327 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3328
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3329 { /* FLAG_ZERO with NaN. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3330 char *result;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3331 int retval =
9854
baba3b346ab2 Use macros NaNf, NaNd, NaNl instead of NAN.
Bruno Haible <bruno@clisp.org>
parents: 9850
diff changeset
3332 my_asprintf (&result, "%050Lg %d", NaNl (), 33, 44, 55);
8836
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3333 ASSERT (result != NULL);
8870
4e1f2ea486b4 Allow for a longer printed representation of NaN.
Bruno Haible <bruno@clisp.org>
parents: 8865
diff changeset
3334 ASSERT (strlen (result) == 50 + 3
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
3335 && strisnan (result, strspn (result, " "), strlen (result) - 3, 0)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
3336 && 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
3337 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3338 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3339 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3340
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3341 { /* Precision. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3342 char *result;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3343 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3344 my_asprintf (&result, "%.Lg %d", 1234.0L, 33, 44, 55);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3345 ASSERT (result != NULL);
10458
1cc9cffb9615 Allow 3-digit exponents in %e and %g results on 'long double'.
Bruno Haible <bruno@clisp.org>
parents: 10394
diff changeset
3346 ASSERT (strcmp (result, "1e+03 33") == 0
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
3347 || strcmp (result, "1e+003 33") == 0);
8836
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3348 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3349 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3350 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3351
9938
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
3352 { /* Precision with no rounding. */
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
3353 char *result;
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
3354 int retval =
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
3355 my_asprintf (&result, "%.5Lg %d", 999.951L, 33, 44, 55);
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
3356 ASSERT (result != NULL);
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
3357 ASSERT (strcmp (result, "999.95 33") == 0);
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
3358 ASSERT (retval == strlen (result));
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
3359 free (result);
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
3360 }
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
3361
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
3362 { /* Precision with rounding. */
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
3363 char *result;
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
3364 int retval =
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
3365 my_asprintf (&result, "%.5Lg %d", 999.996L, 33, 44, 55);
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
3366 ASSERT (result != NULL);
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
3367 ASSERT (strcmp (result, "1000 33") == 0);
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
3368 ASSERT (retval == strlen (result));
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
3369 free (result);
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
3370 }
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
3371
8342
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3372 /* Test the support of the %n format directive. */
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3373
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3374 {
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3375 int count = -1;
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3376 char *result;
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3377 int retval =
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3378 my_asprintf (&result, "%d %n", 123, &count, 33, 44, 55);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3379 ASSERT (result != NULL);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3380 ASSERT (strcmp (result, "123 ") == 0);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3381 ASSERT (retval == strlen (result));
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3382 ASSERT (count == 4);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3383 free (result);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3384 }
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3385
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3386 /* Test the support of the POSIX/XSI format strings with positions. */
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3387
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3388 {
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3389 char *result;
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3390 int retval =
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3391 my_asprintf (&result, "%2$d %1$d", 33, 55);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3392 ASSERT (result != NULL);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3393 ASSERT (strcmp (result, "55 33") == 0);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3394 ASSERT (retval == strlen (result));
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3395 free (result);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3396 }
8803
6c1d98929550 Work around lack of support of grouping flag.
Bruno Haible <bruno@clisp.org>
parents: 8754
diff changeset
3397
6c1d98929550 Work around lack of support of grouping flag.
Bruno Haible <bruno@clisp.org>
parents: 8754
diff changeset
3398 /* Test the support of the grouping flag. */
6c1d98929550 Work around lack of support of grouping flag.
Bruno Haible <bruno@clisp.org>
parents: 8754
diff changeset
3399
6c1d98929550 Work around lack of support of grouping flag.
Bruno Haible <bruno@clisp.org>
parents: 8754
diff changeset
3400 {
6c1d98929550 Work around lack of support of grouping flag.
Bruno Haible <bruno@clisp.org>
parents: 8754
diff changeset
3401 char *result;
6c1d98929550 Work around lack of support of grouping flag.
Bruno Haible <bruno@clisp.org>
parents: 8754
diff changeset
3402 int retval =
6c1d98929550 Work around lack of support of grouping flag.
Bruno Haible <bruno@clisp.org>
parents: 8754
diff changeset
3403 my_asprintf (&result, "%'d %d", 1234567, 99);
6c1d98929550 Work around lack of support of grouping flag.
Bruno Haible <bruno@clisp.org>
parents: 8754
diff changeset
3404 ASSERT (result != NULL);
6c1d98929550 Work around lack of support of grouping flag.
Bruno Haible <bruno@clisp.org>
parents: 8754
diff changeset
3405 ASSERT (result[strlen (result) - 1] == '9');
6c1d98929550 Work around lack of support of grouping flag.
Bruno Haible <bruno@clisp.org>
parents: 8754
diff changeset
3406 ASSERT (retval == strlen (result));
6c1d98929550 Work around lack of support of grouping flag.
Bruno Haible <bruno@clisp.org>
parents: 8754
diff changeset
3407 free (result);
6c1d98929550 Work around lack of support of grouping flag.
Bruno Haible <bruno@clisp.org>
parents: 8754
diff changeset
3408 }
9447
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3409
9674
b69f1141e94f Fix *printf behaviour regarding the left-adjust flag on HP-UX 10.20.
Bruno Haible <bruno@clisp.org>
parents: 9447
diff changeset
3410 /* 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
3411
b69f1141e94f Fix *printf behaviour regarding the left-adjust flag on HP-UX 10.20.
Bruno Haible <bruno@clisp.org>
parents: 9447
diff changeset
3412 {
b69f1141e94f Fix *printf behaviour regarding the left-adjust flag on HP-UX 10.20.
Bruno Haible <bruno@clisp.org>
parents: 9447
diff changeset
3413 char *result;
b69f1141e94f Fix *printf behaviour regarding the left-adjust flag on HP-UX 10.20.
Bruno Haible <bruno@clisp.org>
parents: 9447
diff changeset
3414 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
3415 my_asprintf (&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
3416 ASSERT (result != NULL);
b69f1141e94f Fix *printf behaviour regarding the left-adjust flag on HP-UX 10.20.
Bruno Haible <bruno@clisp.org>
parents: 9447
diff changeset
3417 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
3418 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
3419 free (result);
b69f1141e94f Fix *printf behaviour regarding the left-adjust flag on HP-UX 10.20.
Bruno Haible <bruno@clisp.org>
parents: 9447
diff changeset
3420 }
b69f1141e94f Fix *printf behaviour regarding the left-adjust flag on HP-UX 10.20.
Bruno Haible <bruno@clisp.org>
parents: 9447
diff changeset
3421
b69f1141e94f Fix *printf behaviour regarding the left-adjust flag on HP-UX 10.20.
Bruno Haible <bruno@clisp.org>
parents: 9447
diff changeset
3422 {
b69f1141e94f Fix *printf behaviour regarding the left-adjust flag on HP-UX 10.20.
Bruno Haible <bruno@clisp.org>
parents: 9447
diff changeset
3423 char *result;
b69f1141e94f Fix *printf behaviour regarding the left-adjust flag on HP-UX 10.20.
Bruno Haible <bruno@clisp.org>
parents: 9447
diff changeset
3424 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
3425 my_asprintf (&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
3426 ASSERT (result != NULL);
b69f1141e94f Fix *printf behaviour regarding the left-adjust flag on HP-UX 10.20.
Bruno Haible <bruno@clisp.org>
parents: 9447
diff changeset
3427 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
3428 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
3429 free (result);
b69f1141e94f Fix *printf behaviour regarding the left-adjust flag on HP-UX 10.20.
Bruno Haible <bruno@clisp.org>
parents: 9447
diff changeset
3430 }
b69f1141e94f Fix *printf behaviour regarding the left-adjust flag on HP-UX 10.20.
Bruno Haible <bruno@clisp.org>
parents: 9447
diff changeset
3431
b69f1141e94f Fix *printf behaviour regarding the left-adjust flag on HP-UX 10.20.
Bruno Haible <bruno@clisp.org>
parents: 9447
diff changeset
3432 {
b69f1141e94f Fix *printf behaviour regarding the left-adjust flag on HP-UX 10.20.
Bruno Haible <bruno@clisp.org>
parents: 9447
diff changeset
3433 char *result;
b69f1141e94f Fix *printf behaviour regarding the left-adjust flag on HP-UX 10.20.
Bruno Haible <bruno@clisp.org>
parents: 9447
diff changeset
3434 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
3435 my_asprintf (&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
3436 ASSERT (result != NULL);
b69f1141e94f Fix *printf behaviour regarding the left-adjust flag on HP-UX 10.20.
Bruno Haible <bruno@clisp.org>
parents: 9447
diff changeset
3437 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
3438 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
3439 free (result);
b69f1141e94f Fix *printf behaviour regarding the left-adjust flag on HP-UX 10.20.
Bruno Haible <bruno@clisp.org>
parents: 9447
diff changeset
3440 }
b69f1141e94f Fix *printf behaviour regarding the left-adjust flag on HP-UX 10.20.
Bruno Haible <bruno@clisp.org>
parents: 9447
diff changeset
3441
9447
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3442 /* Test the support of large precision. */
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3443
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3444 {
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3445 char *result;
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3446 int retval =
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3447 my_asprintf (&result, "%.4000d %d", 1234567, 99);
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3448 size_t i;
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3449 ASSERT (result != NULL);
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3450 for (i = 0; i < 4000 - 7; i++)
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3451 ASSERT (result[i] == '0');
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3452 ASSERT (strcmp (result + 4000 - 7, "1234567 99") == 0);
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3453 ASSERT (retval == strlen (result));
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3454 free (result);
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3455 }
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3456
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3457 {
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3458 char *result;
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3459 int retval =
10394
4b3ac67aa7bc vasnprintf-posix: handle large precision via %.*d
Eric Blake <ebb9@byu.net>
parents: 10296
diff changeset
3460 my_asprintf (&result, "%.*d %d", 4000, 1234567, 99);
4b3ac67aa7bc vasnprintf-posix: handle large precision via %.*d
Eric Blake <ebb9@byu.net>
parents: 10296
diff changeset
3461 size_t i;
4b3ac67aa7bc vasnprintf-posix: handle large precision via %.*d
Eric Blake <ebb9@byu.net>
parents: 10296
diff changeset
3462 ASSERT (result != NULL);
4b3ac67aa7bc vasnprintf-posix: handle large precision via %.*d
Eric Blake <ebb9@byu.net>
parents: 10296
diff changeset
3463 for (i = 0; i < 4000 - 7; i++)
4b3ac67aa7bc vasnprintf-posix: handle large precision via %.*d
Eric Blake <ebb9@byu.net>
parents: 10296
diff changeset
3464 ASSERT (result[i] == '0');
4b3ac67aa7bc vasnprintf-posix: handle large precision via %.*d
Eric Blake <ebb9@byu.net>
parents: 10296
diff changeset
3465 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
3466 ASSERT (retval == strlen (result));
4b3ac67aa7bc vasnprintf-posix: handle large precision via %.*d
Eric Blake <ebb9@byu.net>
parents: 10296
diff changeset
3467 free (result);
4b3ac67aa7bc vasnprintf-posix: handle large precision via %.*d
Eric Blake <ebb9@byu.net>
parents: 10296
diff changeset
3468 }
4b3ac67aa7bc vasnprintf-posix: handle large precision via %.*d
Eric Blake <ebb9@byu.net>
parents: 10296
diff changeset
3469
4b3ac67aa7bc vasnprintf-posix: handle large precision via %.*d
Eric Blake <ebb9@byu.net>
parents: 10296
diff changeset
3470 {
4b3ac67aa7bc vasnprintf-posix: handle large precision via %.*d
Eric Blake <ebb9@byu.net>
parents: 10296
diff changeset
3471 char *result;
4b3ac67aa7bc vasnprintf-posix: handle large precision via %.*d
Eric Blake <ebb9@byu.net>
parents: 10296
diff changeset
3472 int retval =
9447
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3473 my_asprintf (&result, "%.4000d %d", -1234567, 99);
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3474 size_t i;
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3475 ASSERT (result != NULL);
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3476 ASSERT (result[0] == '-');
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3477 for (i = 0; i < 4000 - 7; i++)
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3478 ASSERT (result[1 + i] == '0');
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3479 ASSERT (strcmp (result + 1 + 4000 - 7, "1234567 99") == 0);
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3480 ASSERT (retval == strlen (result));
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3481 free (result);
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3482 }
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3483
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3484 {
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3485 char *result;
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3486 int retval =
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3487 my_asprintf (&result, "%.4000u %d", 1234567, 99);
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3488 size_t i;
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3489 ASSERT (result != NULL);
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3490 for (i = 0; i < 4000 - 7; i++)
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3491 ASSERT (result[i] == '0');
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3492 ASSERT (strcmp (result + 4000 - 7, "1234567 99") == 0);
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3493 ASSERT (retval == strlen (result));
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3494 free (result);
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3495 }
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3496
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3497 {
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3498 char *result;
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3499 int retval =
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3500 my_asprintf (&result, "%.4000o %d", 1234567, 99);
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3501 size_t i;
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3502 ASSERT (result != NULL);
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3503 for (i = 0; i < 4000 - 7; i++)
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3504 ASSERT (result[i] == '0');
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3505 ASSERT (strcmp (result + 4000 - 7, "4553207 99") == 0);
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3506 ASSERT (retval == strlen (result));
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3507 free (result);
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3508 }
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3509
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3510 {
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3511 char *result;
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3512 int retval =
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3513 my_asprintf (&result, "%.4000x %d", 1234567, 99);
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3514 size_t i;
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3515 ASSERT (result != NULL);
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3516 for (i = 0; i < 4000 - 6; i++)
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3517 ASSERT (result[i] == '0');
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3518 ASSERT (strcmp (result + 4000 - 6, "12d687 99") == 0);
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3519 ASSERT (retval == strlen (result));
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3520 free (result);
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3521 }
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3522
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3523 {
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3524 char *result;
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3525 int retval =
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3526 my_asprintf (&result, "%#.4000x %d", 1234567, 99);
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3527 size_t i;
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3528 ASSERT (result != NULL);
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3529 ASSERT (result[0] == '0');
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3530 ASSERT (result[1] == 'x');
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3531 for (i = 0; i < 4000 - 6; i++)
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3532 ASSERT (result[2 + i] == '0');
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3533 ASSERT (strcmp (result + 2 + 4000 - 6, "12d687 99") == 0);
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3534 ASSERT (retval == strlen (result));
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3535 free (result);
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3536 }
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3537
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3538 {
13908
4b4e2b0d175e *printf-posix: Detect a bug on Solaris 10/x86.
Bruno Haible <bruno@clisp.org>
parents: 13834
diff changeset
3539 char *result;
4b4e2b0d175e *printf-posix: Detect a bug on Solaris 10/x86.
Bruno Haible <bruno@clisp.org>
parents: 13834
diff changeset
3540 int retval =
4b4e2b0d175e *printf-posix: Detect a bug on Solaris 10/x86.
Bruno Haible <bruno@clisp.org>
parents: 13834
diff changeset
3541 my_asprintf (&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
3542 size_t i;
4b4e2b0d175e *printf-posix: Detect a bug on Solaris 10/x86.
Bruno Haible <bruno@clisp.org>
parents: 13834
diff changeset
3543 ASSERT (result != NULL);
4b4e2b0d175e *printf-posix: Detect a bug on Solaris 10/x86.
Bruno Haible <bruno@clisp.org>
parents: 13834
diff changeset
3544 ASSERT (result[0] == '1');
4b4e2b0d175e *printf-posix: Detect a bug on Solaris 10/x86.
Bruno Haible <bruno@clisp.org>
parents: 13834
diff changeset
3545 ASSERT (result[1] == '.');
4b4e2b0d175e *printf-posix: Detect a bug on Solaris 10/x86.
Bruno Haible <bruno@clisp.org>
parents: 13834
diff changeset
3546 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
3547 ASSERT (result[2 + i] == '0');
4b4e2b0d175e *printf-posix: Detect a bug on Solaris 10/x86.
Bruno Haible <bruno@clisp.org>
parents: 13834
diff changeset
3548 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
3549 ASSERT (retval == strlen (result));
4b4e2b0d175e *printf-posix: Detect a bug on Solaris 10/x86.
Bruno Haible <bruno@clisp.org>
parents: 13834
diff changeset
3550 free (result);
4b4e2b0d175e *printf-posix: Detect a bug on Solaris 10/x86.
Bruno Haible <bruno@clisp.org>
parents: 13834
diff changeset
3551 }
4b4e2b0d175e *printf-posix: Detect a bug on Solaris 10/x86.
Bruno Haible <bruno@clisp.org>
parents: 13834
diff changeset
3552
4b4e2b0d175e *printf-posix: Detect a bug on Solaris 10/x86.
Bruno Haible <bruno@clisp.org>
parents: 13834
diff changeset
3553 {
14005
f585ecc144aa *printf: Detect large precisions bug on Solaris 10/SPARC.
Bruno Haible <bruno@clisp.org>
parents: 13908
diff changeset
3554 char *result;
f585ecc144aa *printf: Detect large precisions bug on Solaris 10/SPARC.
Bruno Haible <bruno@clisp.org>
parents: 13908
diff changeset
3555 int retval =
f585ecc144aa *printf: Detect large precisions bug on Solaris 10/SPARC.
Bruno Haible <bruno@clisp.org>
parents: 13908
diff changeset
3556 my_asprintf (&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
3557 size_t i;
f585ecc144aa *printf: Detect large precisions bug on Solaris 10/SPARC.
Bruno Haible <bruno@clisp.org>
parents: 13908
diff changeset
3558 ASSERT (result != NULL);
f585ecc144aa *printf: Detect large precisions bug on Solaris 10/SPARC.
Bruno Haible <bruno@clisp.org>
parents: 13908
diff changeset
3559 ASSERT (result[0] == '1');
f585ecc144aa *printf: Detect large precisions bug on Solaris 10/SPARC.
Bruno Haible <bruno@clisp.org>
parents: 13908
diff changeset
3560 ASSERT (result[1] == '.');
f585ecc144aa *printf: Detect large precisions bug on Solaris 10/SPARC.
Bruno Haible <bruno@clisp.org>
parents: 13908
diff changeset
3561 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
3562 ASSERT (result[2 + i] == '0');
f585ecc144aa *printf: Detect large precisions bug on Solaris 10/SPARC.
Bruno Haible <bruno@clisp.org>
parents: 13908
diff changeset
3563 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
3564 ASSERT (retval == strlen (result));
f585ecc144aa *printf: Detect large precisions bug on Solaris 10/SPARC.
Bruno Haible <bruno@clisp.org>
parents: 13908
diff changeset
3565 free (result);
f585ecc144aa *printf: Detect large precisions bug on Solaris 10/SPARC.
Bruno Haible <bruno@clisp.org>
parents: 13908
diff changeset
3566 }
f585ecc144aa *printf: Detect large precisions bug on Solaris 10/SPARC.
Bruno Haible <bruno@clisp.org>
parents: 13908
diff changeset
3567
f585ecc144aa *printf: Detect large precisions bug on Solaris 10/SPARC.
Bruno Haible <bruno@clisp.org>
parents: 13908
diff changeset
3568 {
9447
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3569 char input[5000];
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3570 char *result;
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3571 int retval;
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3572 size_t i;
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3573
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3574 for (i = 0; i < sizeof (input) - 1; i++)
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3575 input[i] = 'a' + ((1000000 / (i + 1)) % 26);
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3576 input[i] = '\0';
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3577 retval = my_asprintf (&result, "%.4000s %d", input, 99);
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3578 ASSERT (result != NULL);
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3579 ASSERT (memcmp (result, input, 4000) == 0);
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3580 ASSERT (strcmp (result + 4000, " 99") == 0);
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3581 ASSERT (retval == strlen (result));
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3582 free (result);
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3583 }
11207
4daf474e9033 vasnprintf: Fix invalid read past end of memory block.
Bruno Haible <bruno@clisp.org>
parents: 11002
diff changeset
3584
4daf474e9033 vasnprintf: Fix invalid read past end of memory block.
Bruno Haible <bruno@clisp.org>
parents: 11002
diff changeset
3585 /* 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
3586
4daf474e9033 vasnprintf: Fix invalid read past end of memory block.
Bruno Haible <bruno@clisp.org>
parents: 11002
diff changeset
3587 /* 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
3588 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
3589 or "valgrind --tool=memcheck". */
4daf474e9033 vasnprintf: Fix invalid read past end of memory block.
Bruno Haible <bruno@clisp.org>
parents: 11002
diff changeset
3590 {
4daf474e9033 vasnprintf: Fix invalid read past end of memory block.
Bruno Haible <bruno@clisp.org>
parents: 11002
diff changeset
3591 size_t i;
4daf474e9033 vasnprintf: Fix invalid read past end of memory block.
Bruno Haible <bruno@clisp.org>
parents: 11002
diff changeset
3592
4daf474e9033 vasnprintf: Fix invalid read past end of memory block.
Bruno Haible <bruno@clisp.org>
parents: 11002
diff changeset
3593 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
3594 {
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
3595 char *block;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
3596 char *result;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
3597 int retval;
11207
4daf474e9033 vasnprintf: Fix invalid read past end of memory block.
Bruno Haible <bruno@clisp.org>
parents: 11002
diff changeset
3598
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
3599 block = (char *) malloc (i);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
3600 memcpy (block, "abcdefgh", i);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
3601 retval = my_asprintf (&result, "%.*s", (int) i, block);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
3602 ASSERT (result != NULL);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
3603 ASSERT (memcmp (result, block, i) == 0);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
3604 ASSERT (result[i] == '\0');
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
3605 ASSERT (retval == strlen (result));
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
3606 free (result);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
3607 free (block);
11207
4daf474e9033 vasnprintf: Fix invalid read past end of memory block.
Bruno Haible <bruno@clisp.org>
parents: 11002
diff changeset
3608 }
4daf474e9033 vasnprintf: Fix invalid read past end of memory block.
Bruno Haible <bruno@clisp.org>
parents: 11002
diff changeset
3609 }
4daf474e9033 vasnprintf: Fix invalid read past end of memory block.
Bruno Haible <bruno@clisp.org>
parents: 11002
diff changeset
3610 #if HAVE_WCHAR_T
4daf474e9033 vasnprintf: Fix invalid read past end of memory block.
Bruno Haible <bruno@clisp.org>
parents: 11002
diff changeset
3611 {
4daf474e9033 vasnprintf: Fix invalid read past end of memory block.
Bruno Haible <bruno@clisp.org>
parents: 11002
diff changeset
3612 size_t i;
4daf474e9033 vasnprintf: Fix invalid read past end of memory block.
Bruno Haible <bruno@clisp.org>
parents: 11002
diff changeset
3613
4daf474e9033 vasnprintf: Fix invalid read past end of memory block.
Bruno Haible <bruno@clisp.org>
parents: 11002
diff changeset
3614 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
3615 {
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
3616 wchar_t *block;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
3617 size_t j;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
3618 char *result;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
3619 int retval;
11207
4daf474e9033 vasnprintf: Fix invalid read past end of memory block.
Bruno Haible <bruno@clisp.org>
parents: 11002
diff changeset
3620
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
3621 block = (wchar_t *) malloc (i * sizeof (wchar_t));
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
3622 for (j = 0; j < i; j++)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
3623 block[j] = "abcdefgh"[j];
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
3624 retval = my_asprintf (&result, "%.*ls", (int) i, block);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
3625 ASSERT (result != NULL);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
3626 ASSERT (memcmp (result, "abcdefgh", i) == 0);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
3627 ASSERT (result[i] == '\0');
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
3628 ASSERT (retval == strlen (result));
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
3629 free (result);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11207
diff changeset
3630 free (block);
11207
4daf474e9033 vasnprintf: Fix invalid read past end of memory block.
Bruno Haible <bruno@clisp.org>
parents: 11002
diff changeset
3631 }
4daf474e9033 vasnprintf: Fix invalid read past end of memory block.
Bruno Haible <bruno@clisp.org>
parents: 11002
diff changeset
3632 }
4daf474e9033 vasnprintf: Fix invalid read past end of memory block.
Bruno Haible <bruno@clisp.org>
parents: 11002
diff changeset
3633 #endif
8342
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3634 }
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3635
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3636 static int
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3637 my_asprintf (char **result, const char *format, ...)
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3638 {
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3639 va_list args;
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3640 int ret;
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3641
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3642 va_start (args, format);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3643 ret = vasprintf (result, format, args);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3644 va_end (args);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3645 return ret;
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3646 }
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3647
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3648 static void
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3649 test_vasprintf ()
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3650 {
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3651 test_function (my_asprintf);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3652 }
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3653
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3654 static void
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3655 test_asprintf ()
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3656 {
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3657 test_function (asprintf);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3658 }
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3659
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3660 int
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3661 main (int argc, char *argv[])
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3662 {
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3663 test_vasprintf ();
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3664 test_asprintf ();
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3665 return 0;
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3666 }