annotate tests/test-vasprintf-posix.c @ 9854:baba3b346ab2

Use macros NaNf, NaNd, NaNl instead of NAN.
author Bruno Haible <bruno@clisp.org>
date Wed, 02 Apr 2008 03:06:02 +0200
parents 7f3ed6b093be
children 0be6f1ab456d
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.
9674
b69f1141e94f Fix *printf behaviour regarding the left-adjust flag on HP-UX 10.20.
Bruno Haible <bruno@clisp.org>
parents: 9447
diff changeset
2 Copyright (C) 2007-2008 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>
8754
1f57552cdb11 Better ASSERT macro.
Bruno Haible <bruno@clisp.org>
parents: 8684
diff changeset
26 #include <stdio.h>
8342
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
27 #include <stdint.h>
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
28 #include <stdlib.h>
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
29 #include <string.h>
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
30
9854
baba3b346ab2 Use macros NaNf, NaNd, NaNl instead of NAN.
Bruno Haible <bruno@clisp.org>
parents: 9850
diff changeset
31 #include "nan.h"
baba3b346ab2 Use macros NaNf, NaNd, NaNl instead of NAN.
Bruno Haible <bruno@clisp.org>
parents: 9850
diff changeset
32
8834
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
33 #define SIZEOF(array) (sizeof (array) / sizeof (array[0]))
8754
1f57552cdb11 Better ASSERT macro.
Bruno Haible <bruno@clisp.org>
parents: 8684
diff changeset
34 #define ASSERT(expr) \
1f57552cdb11 Better ASSERT macro.
Bruno Haible <bruno@clisp.org>
parents: 8684
diff changeset
35 do \
1f57552cdb11 Better ASSERT macro.
Bruno Haible <bruno@clisp.org>
parents: 8684
diff changeset
36 { \
1f57552cdb11 Better ASSERT macro.
Bruno Haible <bruno@clisp.org>
parents: 8684
diff changeset
37 if (!(expr)) \
1f57552cdb11 Better ASSERT macro.
Bruno Haible <bruno@clisp.org>
parents: 8684
diff changeset
38 { \
1f57552cdb11 Better ASSERT macro.
Bruno Haible <bruno@clisp.org>
parents: 8684
diff changeset
39 fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \
1f57552cdb11 Better ASSERT macro.
Bruno Haible <bruno@clisp.org>
parents: 8684
diff changeset
40 abort (); \
1f57552cdb11 Better ASSERT macro.
Bruno Haible <bruno@clisp.org>
parents: 8684
diff changeset
41 } \
1f57552cdb11 Better ASSERT macro.
Bruno Haible <bruno@clisp.org>
parents: 8684
diff changeset
42 } \
1f57552cdb11 Better ASSERT macro.
Bruno Haible <bruno@clisp.org>
parents: 8684
diff changeset
43 while (0)
8342
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
44
8852
df0b5e8ea770 Avoid test failures on platforms where -0.0 and 0.0 are identical.
Bruno Haible <bruno@clisp.org>
parents: 8850
diff changeset
45 /* 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
46 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
47 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
48 {
df0b5e8ea770 Avoid test failures on platforms where -0.0 and 0.0 are identical.
Bruno Haible <bruno@clisp.org>
parents: 8850
diff changeset
49 static double plus_zero = 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
50 static double minus_zero = -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
51 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
52 }
df0b5e8ea770 Avoid test failures on platforms where -0.0 and 0.0 are identical.
Bruno Haible <bruno@clisp.org>
parents: 8850
diff changeset
53
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
54 /* 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
55 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
56 #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
57 # 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
58 { ((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
59 ((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
60 (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
61 }
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
62 #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
63 # 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
64 { 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
65 #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
66
8834
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
67 static int
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
68 strmatch (const char *pattern, const char *string)
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
69 {
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
70 if (strlen (pattern) != strlen (string))
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
71 return 0;
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
72 for (; *pattern != '\0'; pattern++, string++)
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
73 if (*pattern != '*' && *string != *pattern)
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
74 return 0;
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
75 return 1;
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
76 }
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
77
8865
9e203d8ade65 Stricter check for printf result for NaN arguments.
Bruno Haible <bruno@clisp.org>
parents: 8857
diff changeset
78 /* 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
79 representation of NaN. */
9e203d8ade65 Stricter check for printf result for NaN arguments.
Bruno Haible <bruno@clisp.org>
parents: 8857
diff changeset
80 static int
9e203d8ade65 Stricter check for printf result for NaN arguments.
Bruno Haible <bruno@clisp.org>
parents: 8857
diff changeset
81 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
82 {
9e203d8ade65 Stricter check for printf result for NaN arguments.
Bruno Haible <bruno@clisp.org>
parents: 8857
diff changeset
83 if (start_index < end_index)
9e203d8ade65 Stricter check for printf result for NaN arguments.
Bruno Haible <bruno@clisp.org>
parents: 8857
diff changeset
84 {
9e203d8ade65 Stricter check for printf result for NaN arguments.
Bruno Haible <bruno@clisp.org>
parents: 8857
diff changeset
85 if (string[start_index] == '-')
9e203d8ade65 Stricter check for printf result for NaN arguments.
Bruno Haible <bruno@clisp.org>
parents: 8857
diff changeset
86 start_index++;
9e203d8ade65 Stricter check for printf result for NaN arguments.
Bruno Haible <bruno@clisp.org>
parents: 8857
diff changeset
87 if (start_index + 3 <= end_index
9e203d8ade65 Stricter check for printf result for NaN arguments.
Bruno Haible <bruno@clisp.org>
parents: 8857
diff changeset
88 && memcmp (string + start_index, uppercase ? "NAN" : "nan", 3) == 0)
9e203d8ade65 Stricter check for printf result for NaN arguments.
Bruno Haible <bruno@clisp.org>
parents: 8857
diff changeset
89 {
9e203d8ade65 Stricter check for printf result for NaN arguments.
Bruno Haible <bruno@clisp.org>
parents: 8857
diff changeset
90 start_index += 3;
9e203d8ade65 Stricter check for printf result for NaN arguments.
Bruno Haible <bruno@clisp.org>
parents: 8857
diff changeset
91 if (start_index == end_index
9e203d8ade65 Stricter check for printf result for NaN arguments.
Bruno Haible <bruno@clisp.org>
parents: 8857
diff changeset
92 || (string[start_index] == '(' && string[end_index - 1] == ')'))
9e203d8ade65 Stricter check for printf result for NaN arguments.
Bruno Haible <bruno@clisp.org>
parents: 8857
diff changeset
93 return 1;
9e203d8ade65 Stricter check for printf result for NaN arguments.
Bruno Haible <bruno@clisp.org>
parents: 8857
diff changeset
94 }
9e203d8ade65 Stricter check for printf result for NaN arguments.
Bruno Haible <bruno@clisp.org>
parents: 8857
diff changeset
95 }
9e203d8ade65 Stricter check for printf result for NaN arguments.
Bruno Haible <bruno@clisp.org>
parents: 8857
diff changeset
96 return 0;
9e203d8ade65 Stricter check for printf result for NaN arguments.
Bruno Haible <bruno@clisp.org>
parents: 8857
diff changeset
97 }
9850
7f3ed6b093be Guarantee a definition of NAN.
Eric Blake <ebb9@byu.net>
parents: 9674
diff changeset
98
8342
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
99 static void
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
100 test_function (int (*my_asprintf) (char **, const char *, ...))
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
101 {
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
102 int repeat;
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
103
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
104 /* Test return value convention. */
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 for (repeat = 0; repeat <= 8; repeat++)
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 char *result;
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
109 int retval = asprintf (&result, "%d", 12345);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
110 ASSERT (retval == 5);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
111 ASSERT (result != NULL);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
112 ASSERT (strcmp (result, "12345") == 0);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
113 free (result);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
114 }
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
115
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
116 /* Test support of size specifiers as in C99. */
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, "%ju %d", (uintmax_t) 12345671, 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, "12345671 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, "%zu %d", (size_t) 12345672, 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, "12345672 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, "%tu %d", (ptrdiff_t) 12345673, 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, "12345673 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 {
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
149 char *result;
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
150 int retval =
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
151 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
152 ASSERT (result != NULL);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
153 ASSERT (strcmp (result, "1.5 33") == 0);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
154 ASSERT (retval == strlen (result));
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
155 free (result);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
156 }
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
157
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
158 /* 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
159 output of floating-point numbers. */
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
160
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
161 { /* A positive number. */
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
162 char *result;
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
163 int retval =
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
164 my_asprintf (&result, "%a %d", 3.1416015625, 33, 44, 55);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
165 ASSERT (result != NULL);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
166 ASSERT (strcmp (result, "0x1.922p+1 33") == 0
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
167 || strcmp (result, "0x3.244p+0 33") == 0
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
168 || strcmp (result, "0x6.488p-1 33") == 0
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
169 || strcmp (result, "0xc.91p-2 33") == 0);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
170 ASSERT (retval == strlen (result));
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
171 free (result);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
172 }
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
173
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
174 { /* A negative number. */
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
175 char *result;
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
176 int retval =
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
177 my_asprintf (&result, "%A %d", -3.1416015625, 33, 44, 55);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
178 ASSERT (result != NULL);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
179 ASSERT (strcmp (result, "-0X1.922P+1 33") == 0
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
180 || strcmp (result, "-0X3.244P+0 33") == 0
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
181 || strcmp (result, "-0X6.488P-1 33") == 0
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
182 || strcmp (result, "-0XC.91P-2 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 { /* Positive 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 =
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
190 my_asprintf (&result, "%a %d", 0.0, 33, 44, 55);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
191 ASSERT (result != NULL);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
192 ASSERT (strcmp (result, "0x0p+0 33") == 0);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
193 ASSERT (retval == strlen (result));
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
194 free (result);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
195 }
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 { /* Negative zero. */
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
198 char *result;
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
199 int retval =
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
200 my_asprintf (&result, "%a %d", -0.0, 33, 44, 55);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
201 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
202 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
203 ASSERT (strcmp (result, "-0x0p+0 33") == 0);
8342
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 { /* Positive 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 =
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
211 my_asprintf (&result, "%a %d", 1.0 / 0.0, 33, 44, 55);
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 { /* Negative infinity. */
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 =
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
221 my_asprintf (&result, "%a %d", -1.0 / 0.0, 33, 44, 55);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
222 ASSERT (result != NULL);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
223 ASSERT (strcmp (result, "-inf 33") == 0);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
224 ASSERT (retval == strlen (result));
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
225 free (result);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
226 }
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
227
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
228 { /* NaN. */
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
229 char *result;
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
230 int retval =
9854
baba3b346ab2 Use macros NaNf, NaNd, NaNl instead of NAN.
Bruno Haible <bruno@clisp.org>
parents: 9850
diff changeset
231 my_asprintf (&result, "%a %d", NaNd (), 33, 44, 55);
8342
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
232 ASSERT (result != NULL);
8850
d1fe16dfbfee Avoid test failures on IRIX 6.5.
Bruno Haible <bruno@clisp.org>
parents: 8839
diff changeset
233 ASSERT (strlen (result) >= 3 + 3
8865
9e203d8ade65 Stricter check for printf result for NaN arguments.
Bruno Haible <bruno@clisp.org>
parents: 8857
diff changeset
234 && strisnan (result, 0, strlen (result) - 3, 0)
8850
d1fe16dfbfee Avoid test failures on IRIX 6.5.
Bruno Haible <bruno@clisp.org>
parents: 8839
diff changeset
235 && strcmp (result + strlen (result) - 3, " 33") == 0);
8342
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
236 ASSERT (retval == strlen (result));
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
237 free (result);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
238 }
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
239
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
240 { /* Rounding near the decimal point. */
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
241 char *result;
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
242 int retval =
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
243 my_asprintf (&result, "%.0a %d", 1.5, 33, 44, 55);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
244 ASSERT (result != NULL);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
245 ASSERT (strcmp (result, "0x2p+0 33") == 0
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
246 || strcmp (result, "0x3p-1 33") == 0
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
247 || strcmp (result, "0x6p-2 33") == 0
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
248 || strcmp (result, "0xcp-3 33") == 0);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
249 ASSERT (retval == strlen (result));
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
250 free (result);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
251 }
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
252
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
253 { /* Rounding with precision 0. */
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
254 char *result;
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
255 int retval =
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
256 my_asprintf (&result, "%.0a %d", 1.51, 33, 44, 55);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
257 ASSERT (result != NULL);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
258 ASSERT (strcmp (result, "0x2p+0 33") == 0
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
259 || strcmp (result, "0x3p-1 33") == 0
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
260 || strcmp (result, "0x6p-2 33") == 0
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
261 || strcmp (result, "0xcp-3 33") == 0);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
262 ASSERT (retval == strlen (result));
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
263 free (result);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
264 }
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
265
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
266 { /* Rounding with precision 1. */
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
267 char *result;
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
268 int retval =
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
269 my_asprintf (&result, "%.1a %d", 1.51, 33, 44, 55);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
270 ASSERT (result != NULL);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
271 ASSERT (strcmp (result, "0x1.8p+0 33") == 0
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
272 || strcmp (result, "0x3.0p-1 33") == 0
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
273 || strcmp (result, "0x6.1p-2 33") == 0
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
274 || strcmp (result, "0xc.1p-3 33") == 0);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
275 ASSERT (retval == strlen (result));
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
276 free (result);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
277 }
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
278
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
279 { /* Rounding with precision 2. */
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
280 char *result;
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
281 int retval =
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
282 my_asprintf (&result, "%.2a %d", 1.51, 33, 44, 55);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
283 ASSERT (result != NULL);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
284 ASSERT (strcmp (result, "0x1.83p+0 33") == 0
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
285 || strcmp (result, "0x3.05p-1 33") == 0
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
286 || strcmp (result, "0x6.0ap-2 33") == 0
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
287 || strcmp (result, "0xc.14p-3 33") == 0);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
288 ASSERT (retval == strlen (result));
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
289 free (result);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
290 }
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
291
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
292 { /* Rounding with precision 3. */
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
293 char *result;
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
294 int retval =
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
295 my_asprintf (&result, "%.3a %d", 1.51, 33, 44, 55);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
296 ASSERT (result != NULL);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
297 ASSERT (strcmp (result, "0x1.829p+0 33") == 0
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
298 || strcmp (result, "0x3.052p-1 33") == 0
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
299 || strcmp (result, "0x6.0a4p-2 33") == 0
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
300 || strcmp (result, "0xc.148p-3 33") == 0);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
301 ASSERT (retval == strlen (result));
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
302 free (result);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
303 }
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
304
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
305 { /* Rounding can turn a ...FFF into a ...000. */
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
306 char *result;
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
307 int retval =
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
308 my_asprintf (&result, "%.3a %d", 1.49999, 33, 44, 55);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
309 ASSERT (result != NULL);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
310 ASSERT (strcmp (result, "0x1.800p+0 33") == 0
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
311 || strcmp (result, "0x3.000p-1 33") == 0
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
312 || strcmp (result, "0x6.000p-2 33") == 0
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
313 || strcmp (result, "0xc.000p-3 33") == 0);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
314 ASSERT (retval == strlen (result));
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
315 free (result);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
316 }
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
317
8344
c8055280f68e Test a corner case. Exclude two buggy implementations.
Bruno Haible <bruno@clisp.org>
parents: 8342
diff changeset
318 { /* Rounding can turn a ...FFF into a ...000.
c8055280f68e Test a corner case. Exclude two buggy implementations.
Bruno Haible <bruno@clisp.org>
parents: 8342
diff changeset
319 This shows a MacOS X 10.3.9 (Darwin 7.9) bug. */
c8055280f68e Test a corner case. Exclude two buggy implementations.
Bruno Haible <bruno@clisp.org>
parents: 8342
diff changeset
320 char *result;
c8055280f68e Test a corner case. Exclude two buggy implementations.
Bruno Haible <bruno@clisp.org>
parents: 8342
diff changeset
321 int retval =
c8055280f68e Test a corner case. Exclude two buggy implementations.
Bruno Haible <bruno@clisp.org>
parents: 8342
diff changeset
322 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
323 ASSERT (result != NULL);
c8055280f68e Test a corner case. Exclude two buggy implementations.
Bruno Haible <bruno@clisp.org>
parents: 8342
diff changeset
324 ASSERT (strcmp (result, "0x1.0p+1 33") == 0
c8055280f68e Test a corner case. Exclude two buggy implementations.
Bruno Haible <bruno@clisp.org>
parents: 8342
diff changeset
325 || strcmp (result, "0x2.0p+0 33") == 0
c8055280f68e Test a corner case. Exclude two buggy implementations.
Bruno Haible <bruno@clisp.org>
parents: 8342
diff changeset
326 || strcmp (result, "0x4.0p-1 33") == 0
c8055280f68e Test a corner case. Exclude two buggy implementations.
Bruno Haible <bruno@clisp.org>
parents: 8342
diff changeset
327 || strcmp (result, "0x8.0p-2 33") == 0);
c8055280f68e Test a corner case. Exclude two buggy implementations.
Bruno Haible <bruno@clisp.org>
parents: 8342
diff changeset
328 ASSERT (retval == strlen (result));
c8055280f68e Test a corner case. Exclude two buggy implementations.
Bruno Haible <bruno@clisp.org>
parents: 8342
diff changeset
329 free (result);
c8055280f68e Test a corner case. Exclude two buggy implementations.
Bruno Haible <bruno@clisp.org>
parents: 8342
diff changeset
330 }
c8055280f68e Test a corner case. Exclude two buggy implementations.
Bruno Haible <bruno@clisp.org>
parents: 8342
diff changeset
331
8342
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
332 { /* Width. */
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
333 char *result;
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
334 int retval =
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
335 my_asprintf (&result, "%10a %d", 1.75, 33, 44, 55);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
336 ASSERT (result != NULL);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
337 ASSERT (strcmp (result, " 0x1.cp+0 33") == 0
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
338 || strcmp (result, " 0x3.8p-1 33") == 0
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
339 || strcmp (result, " 0x7p-2 33") == 0
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
340 || strcmp (result, " 0xep-3 33") == 0);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
341 ASSERT (retval == strlen (result));
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
342 free (result);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
343 }
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
344
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
345 { /* Small precision. */
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
346 char *result;
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
347 int retval =
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
348 my_asprintf (&result, "%.10a %d", 1.75, 33, 44, 55);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
349 ASSERT (result != NULL);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
350 ASSERT (strcmp (result, "0x1.c000000000p+0 33") == 0
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
351 || strcmp (result, "0x3.8000000000p-1 33") == 0
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
352 || strcmp (result, "0x7.0000000000p-2 33") == 0
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
353 || strcmp (result, "0xe.0000000000p-3 33") == 0);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
354 ASSERT (retval == strlen (result));
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
355 free (result);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
356 }
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
357
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
358 { /* Large precision. */
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
359 char *result;
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
360 int retval =
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
361 my_asprintf (&result, "%.50a %d", 1.75, 33, 44, 55);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
362 ASSERT (result != NULL);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
363 ASSERT (strcmp (result, "0x1.c0000000000000000000000000000000000000000000000000p+0 33") == 0
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
364 || strcmp (result, "0x3.80000000000000000000000000000000000000000000000000p-1 33") == 0
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
365 || strcmp (result, "0x7.00000000000000000000000000000000000000000000000000p-2 33") == 0
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
366 || strcmp (result, "0xe.00000000000000000000000000000000000000000000000000p-3 33") == 0);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
367 ASSERT (retval == strlen (result));
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
368 free (result);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
369 }
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
370
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
371 { /* FLAG_LEFT. */
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
372 char *result;
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
373 int retval =
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
374 my_asprintf (&result, "%-10a %d", 1.75, 33, 44, 55);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
375 ASSERT (result != NULL);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
376 ASSERT (strcmp (result, "0x1.cp+0 33") == 0
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
377 || strcmp (result, "0x3.8p-1 33") == 0
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
378 || strcmp (result, "0x7p-2 33") == 0
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
379 || strcmp (result, "0xep-3 33") == 0);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
380 ASSERT (retval == strlen (result));
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
381 free (result);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
382 }
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
383
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
384 { /* FLAG_SHOWSIGN. */
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
385 char *result;
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
386 int retval =
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
387 my_asprintf (&result, "%+a %d", 1.75, 33, 44, 55);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
388 ASSERT (result != NULL);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
389 ASSERT (strcmp (result, "+0x1.cp+0 33") == 0
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
390 || strcmp (result, "+0x3.8p-1 33") == 0
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
391 || strcmp (result, "+0x7p-2 33") == 0
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
392 || strcmp (result, "+0xep-3 33") == 0);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
393 ASSERT (retval == strlen (result));
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
394 free (result);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
395 }
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
396
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
397 { /* FLAG_SPACE. */
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
398 char *result;
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
399 int retval =
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
400 my_asprintf (&result, "% a %d", 1.75, 33, 44, 55);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
401 ASSERT (result != NULL);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
402 ASSERT (strcmp (result, " 0x1.cp+0 33") == 0
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
403 || strcmp (result, " 0x3.8p-1 33") == 0
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
404 || strcmp (result, " 0x7p-2 33") == 0
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
405 || strcmp (result, " 0xep-3 33") == 0);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
406 ASSERT (retval == strlen (result));
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
407 free (result);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
408 }
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
409
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
410 { /* FLAG_ALT. */
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
411 char *result;
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
412 int retval =
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
413 my_asprintf (&result, "%#a %d", 1.75, 33, 44, 55);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
414 ASSERT (result != NULL);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
415 ASSERT (strcmp (result, "0x1.cp+0 33") == 0
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
416 || strcmp (result, "0x3.8p-1 33") == 0
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
417 || strcmp (result, "0x7.p-2 33") == 0
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
418 || strcmp (result, "0xe.p-3 33") == 0);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
419 ASSERT (retval == strlen (result));
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
420 free (result);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
421 }
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
422
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
423 { /* FLAG_ALT. */
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
424 char *result;
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
425 int retval =
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
426 my_asprintf (&result, "%#a %d", 1.0, 33, 44, 55);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
427 ASSERT (result != NULL);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
428 ASSERT (strcmp (result, "0x1.p+0 33") == 0
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
429 || strcmp (result, "0x2.p-1 33") == 0
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
430 || strcmp (result, "0x4.p-2 33") == 0
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
431 || strcmp (result, "0x8.p-3 33") == 0);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
432 ASSERT (retval == strlen (result));
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
433 free (result);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
434 }
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
435
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
436 { /* FLAG_ZERO with finite number. */
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
437 char *result;
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
438 int retval =
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
439 my_asprintf (&result, "%010a %d", 1.75, 33, 44, 55);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
440 ASSERT (result != NULL);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
441 ASSERT (strcmp (result, "0x001.cp+0 33") == 0
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
442 || strcmp (result, "0x003.8p-1 33") == 0
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
443 || strcmp (result, "0x00007p-2 33") == 0
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
444 || strcmp (result, "0x0000ep-3 33") == 0);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
445 ASSERT (retval == strlen (result));
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
446 free (result);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
447 }
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
448
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
449 { /* FLAG_ZERO with infinite number. */
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
450 char *result;
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
451 int retval =
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
452 my_asprintf (&result, "%010a %d", 1.0 / 0.0, 33, 44, 55);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
453 ASSERT (result != NULL);
8662
023aa5c883a7 Guard against FreeBSD 6.1 bug.
Bruno Haible <bruno@clisp.org>
parents: 8648
diff changeset
454 /* "0000000inf 33" is not a valid result; see
023aa5c883a7 Guard against FreeBSD 6.1 bug.
Bruno Haible <bruno@clisp.org>
parents: 8648
diff changeset
455 <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
456 ASSERT (strcmp (result, " inf 33") == 0);
8342
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
457 ASSERT (retval == strlen (result));
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
458 free (result);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
459 }
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
460
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
461 { /* FLAG_ZERO with NaN. */
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
462 char *result;
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
463 int retval =
9854
baba3b346ab2 Use macros NaNf, NaNd, NaNl instead of NAN.
Bruno Haible <bruno@clisp.org>
parents: 9850
diff changeset
464 my_asprintf (&result, "%050a %d", NaNd (), 33, 44, 55);
8342
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
465 ASSERT (result != NULL);
8662
023aa5c883a7 Guard against FreeBSD 6.1 bug.
Bruno Haible <bruno@clisp.org>
parents: 8648
diff changeset
466 /* "0000000nan 33" is not a valid result; see
023aa5c883a7 Guard against FreeBSD 6.1 bug.
Bruno Haible <bruno@clisp.org>
parents: 8648
diff changeset
467 <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
468 ASSERT (strlen (result) == 50 + 3
8865
9e203d8ade65 Stricter check for printf result for NaN arguments.
Bruno Haible <bruno@clisp.org>
parents: 8857
diff changeset
469 && strisnan (result, strspn (result, " "), strlen (result) - 3, 0)
8850
d1fe16dfbfee Avoid test failures on IRIX 6.5.
Bruno Haible <bruno@clisp.org>
parents: 8839
diff changeset
470 && strcmp (result + strlen (result) - 3, " 33") == 0);
8342
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
471 ASSERT (retval == strlen (result));
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
472 free (result);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
473 }
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
474
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
475 { /* A positive number. */
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
476 char *result;
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
477 int retval =
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
478 my_asprintf (&result, "%La %d", 3.1416015625L, 33, 44, 55);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
479 ASSERT (result != NULL);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
480 ASSERT (strcmp (result, "0x1.922p+1 33") == 0
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
481 || strcmp (result, "0x3.244p+0 33") == 0
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
482 || strcmp (result, "0x6.488p-1 33") == 0
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
483 || strcmp (result, "0xc.91p-2 33") == 0);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
484 ASSERT (retval == strlen (result));
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
485 free (result);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
486 }
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
487
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
488 { /* A negative number. */
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
489 char *result;
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
490 int retval =
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
491 my_asprintf (&result, "%LA %d", -3.1416015625L, 33, 44, 55);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
492 ASSERT (result != NULL);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
493 ASSERT (strcmp (result, "-0X1.922P+1 33") == 0
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
494 || strcmp (result, "-0X3.244P+0 33") == 0
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
495 || strcmp (result, "-0X6.488P-1 33") == 0
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
496 || strcmp (result, "-0XC.91P-2 33") == 0);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
497 ASSERT (retval == strlen (result));
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
498 free (result);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
499 }
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
500
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
501 { /* Positive zero. */
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
502 char *result;
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
503 int retval =
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
504 my_asprintf (&result, "%La %d", 0.0L, 33, 44, 55);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
505 ASSERT (result != NULL);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
506 ASSERT (strcmp (result, "0x0p+0 33") == 0);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
507 ASSERT (retval == strlen (result));
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
508 free (result);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
509 }
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
510
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
511 { /* Negative zero. */
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
512 char *result;
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
513 int retval =
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
514 my_asprintf (&result, "%La %d", -0.0L, 33, 44, 55);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
515 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
516 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
517 ASSERT (strcmp (result, "-0x0p+0 33") == 0);
8342
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
518 ASSERT (retval == strlen (result));
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
519 free (result);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
520 }
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
521
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
522 { /* Positive infinity. */
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
523 char *result;
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
524 int retval =
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
525 my_asprintf (&result, "%La %d", 1.0L / 0.0L, 33, 44, 55);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
526 ASSERT (result != NULL);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
527 ASSERT (strcmp (result, "inf 33") == 0);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
528 ASSERT (retval == strlen (result));
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
529 free (result);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
530 }
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
531
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
532 { /* Negative infinity. */
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
533 char *result;
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
534 int retval =
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
535 my_asprintf (&result, "%La %d", -1.0L / 0.0L, 33, 44, 55);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
536 ASSERT (result != NULL);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
537 ASSERT (strcmp (result, "-inf 33") == 0);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
538 ASSERT (retval == strlen (result));
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
539 free (result);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
540 }
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
541
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
542 { /* NaN. */
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
543 char *result;
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
544 int retval =
9854
baba3b346ab2 Use macros NaNf, NaNd, NaNl instead of NAN.
Bruno Haible <bruno@clisp.org>
parents: 9850
diff changeset
545 my_asprintf (&result, "%La %d", NaNl (), 33, 44, 55);
8342
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
546 ASSERT (result != NULL);
8850
d1fe16dfbfee Avoid test failures on IRIX 6.5.
Bruno Haible <bruno@clisp.org>
parents: 8839
diff changeset
547 ASSERT (strlen (result) >= 3 + 3
8865
9e203d8ade65 Stricter check for printf result for NaN arguments.
Bruno Haible <bruno@clisp.org>
parents: 8857
diff changeset
548 && strisnan (result, 0, strlen (result) - 3, 0)
8850
d1fe16dfbfee Avoid test failures on IRIX 6.5.
Bruno Haible <bruno@clisp.org>
parents: 8839
diff changeset
549 && strcmp (result + strlen (result) - 3, " 33") == 0);
8342
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
550 ASSERT (retval == strlen (result));
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
551 free (result);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
552 }
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
553 #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_))
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
554 { /* 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
555 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
556 { 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
557 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
558 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
559 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
560 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
561 ASSERT (strlen (result) >= 3 + 3
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 && strisnan (result, 0, strlen (result) - 3, 0)
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 && strcmp (result + strlen (result) - 3, " 33") == 0);
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 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
565 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
566 }
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 {
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
568 /* 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
569 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
570 { 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
571 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
572 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
573 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
574 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
575 ASSERT (strlen (result) >= 3 + 3
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 && strisnan (result, 0, strlen (result) - 3, 0)
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 && strcmp (result + strlen (result) - 3, " 33") == 0);
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 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
579 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
580 }
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 /* 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
582 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
583 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
584 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
585 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
586 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
587 */
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
588 { /* 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
589 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
590 { 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
591 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
592 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
593 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
594 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
595 ASSERT (strlen (result) >= 3 + 3
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 && strisnan (result, 0, strlen (result) - 3, 0)
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 && strcmp (result + strlen (result) - 3, " 33") == 0);
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 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
599 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
600 }
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
601 { /* 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
602 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
603 { 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
604 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
605 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
606 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
607 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
608 ASSERT (strlen (result) >= 3 + 3
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 && strisnan (result, 0, strlen (result) - 3, 0)
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 && strcmp (result + strlen (result) - 3, " 33") == 0);
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 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
612 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
613 }
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
614 { /* 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
615 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
616 { 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
617 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
618 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
619 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
620 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
621 ASSERT (strlen (result) >= 3 + 3
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 && strisnan (result, 0, strlen (result) - 3, 0)
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 && strcmp (result + strlen (result) - 3, " 33") == 0);
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 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
625 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
626 }
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
627 { /* 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
628 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
629 { 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
630 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
631 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
632 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
633 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
634 ASSERT (strlen (result) >= 3 + 3
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 && strisnan (result, 0, strlen (result) - 3, 0)
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 && strcmp (result + strlen (result) - 3, " 33") == 0);
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 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
638 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
639 }
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
640 { /* 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
641 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
642 { 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
643 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
644 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
645 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
646 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
647 ASSERT (strlen (result) >= 3 + 3
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
648 && strisnan (result, 0, strlen (result) - 3, 0)
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
649 && strcmp (result + strlen (result) - 3, " 33") == 0);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
650 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
651 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
652 }
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
653 #endif
8342
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
654
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
655 { /* Rounding near the decimal point. */
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
656 char *result;
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
657 int retval =
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
658 my_asprintf (&result, "%.0La %d", 1.5L, 33, 44, 55);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
659 ASSERT (result != NULL);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
660 ASSERT (strcmp (result, "0x2p+0 33") == 0
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
661 || strcmp (result, "0x3p-1 33") == 0
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
662 || strcmp (result, "0x6p-2 33") == 0
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
663 || strcmp (result, "0xcp-3 33") == 0);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
664 ASSERT (retval == strlen (result));
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
665 free (result);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
666 }
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
667
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
668 { /* Rounding with precision 0. */
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
669 char *result;
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
670 int retval =
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
671 my_asprintf (&result, "%.0La %d", 1.51L, 33, 44, 55);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
672 ASSERT (result != NULL);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
673 ASSERT (strcmp (result, "0x2p+0 33") == 0
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
674 || strcmp (result, "0x3p-1 33") == 0
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
675 || strcmp (result, "0x6p-2 33") == 0
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
676 || strcmp (result, "0xcp-3 33") == 0);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
677 ASSERT (retval == strlen (result));
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
678 free (result);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
679 }
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
680
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
681 { /* Rounding with precision 1. */
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
682 char *result;
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
683 int retval =
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
684 my_asprintf (&result, "%.1La %d", 1.51L, 33, 44, 55);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
685 ASSERT (result != NULL);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
686 ASSERT (strcmp (result, "0x1.8p+0 33") == 0
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
687 || strcmp (result, "0x3.0p-1 33") == 0
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
688 || strcmp (result, "0x6.1p-2 33") == 0
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
689 || strcmp (result, "0xc.1p-3 33") == 0);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
690 ASSERT (retval == strlen (result));
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
691 free (result);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
692 }
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
693
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
694 { /* Rounding with precision 2. */
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
695 char *result;
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
696 int retval =
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
697 my_asprintf (&result, "%.2La %d", 1.51L, 33, 44, 55);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
698 ASSERT (result != NULL);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
699 ASSERT (strcmp (result, "0x1.83p+0 33") == 0
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
700 || strcmp (result, "0x3.05p-1 33") == 0
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
701 || strcmp (result, "0x6.0ap-2 33") == 0
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
702 || strcmp (result, "0xc.14p-3 33") == 0);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
703 ASSERT (retval == strlen (result));
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
704 free (result);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
705 }
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
706
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
707 { /* Rounding with precision 3. */
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
708 char *result;
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
709 int retval =
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
710 my_asprintf (&result, "%.3La %d", 1.51L, 33, 44, 55);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
711 ASSERT (result != NULL);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
712 ASSERT (strcmp (result, "0x1.829p+0 33") == 0
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
713 || strcmp (result, "0x3.052p-1 33") == 0
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
714 || strcmp (result, "0x6.0a4p-2 33") == 0
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
715 || strcmp (result, "0xc.148p-3 33") == 0);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
716 ASSERT (retval == strlen (result));
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
717 free (result);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
718 }
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
719
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
720 { /* Rounding can turn a ...FFF into a ...000. */
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
721 char *result;
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
722 int retval =
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
723 my_asprintf (&result, "%.3La %d", 1.49999L, 33, 44, 55);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
724 ASSERT (result != NULL);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
725 ASSERT (strcmp (result, "0x1.800p+0 33") == 0
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
726 || strcmp (result, "0x3.000p-1 33") == 0
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
727 || strcmp (result, "0x6.000p-2 33") == 0
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
728 || strcmp (result, "0xc.000p-3 33") == 0);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
729 ASSERT (retval == strlen (result));
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
730 free (result);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
731 }
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
732
8344
c8055280f68e Test a corner case. Exclude two buggy implementations.
Bruno Haible <bruno@clisp.org>
parents: 8342
diff changeset
733 { /* Rounding can turn a ...FFF into a ...000.
c8055280f68e Test a corner case. Exclude two buggy implementations.
Bruno Haible <bruno@clisp.org>
parents: 8342
diff changeset
734 This shows a MacOS X 10.3.9 (Darwin 7.9) bug and a
c8055280f68e Test a corner case. Exclude two buggy implementations.
Bruno Haible <bruno@clisp.org>
parents: 8342
diff changeset
735 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
736 char *result;
c8055280f68e Test a corner case. Exclude two buggy implementations.
Bruno Haible <bruno@clisp.org>
parents: 8342
diff changeset
737 int retval =
c8055280f68e Test a corner case. Exclude two buggy implementations.
Bruno Haible <bruno@clisp.org>
parents: 8342
diff changeset
738 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
739 ASSERT (result != NULL);
c8055280f68e Test a corner case. Exclude two buggy implementations.
Bruno Haible <bruno@clisp.org>
parents: 8342
diff changeset
740 ASSERT (strcmp (result, "0x1.0p+1 33") == 0
c8055280f68e Test a corner case. Exclude two buggy implementations.
Bruno Haible <bruno@clisp.org>
parents: 8342
diff changeset
741 || strcmp (result, "0x2.0p+0 33") == 0
c8055280f68e Test a corner case. Exclude two buggy implementations.
Bruno Haible <bruno@clisp.org>
parents: 8342
diff changeset
742 || strcmp (result, "0x4.0p-1 33") == 0
c8055280f68e Test a corner case. Exclude two buggy implementations.
Bruno Haible <bruno@clisp.org>
parents: 8342
diff changeset
743 || strcmp (result, "0x8.0p-2 33") == 0);
c8055280f68e Test a corner case. Exclude two buggy implementations.
Bruno Haible <bruno@clisp.org>
parents: 8342
diff changeset
744 ASSERT (retval == strlen (result));
c8055280f68e Test a corner case. Exclude two buggy implementations.
Bruno Haible <bruno@clisp.org>
parents: 8342
diff changeset
745 free (result);
c8055280f68e Test a corner case. Exclude two buggy implementations.
Bruno Haible <bruno@clisp.org>
parents: 8342
diff changeset
746 }
c8055280f68e Test a corner case. Exclude two buggy implementations.
Bruno Haible <bruno@clisp.org>
parents: 8342
diff changeset
747
8342
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
748 { /* Width. */
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
749 char *result;
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
750 int retval =
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
751 my_asprintf (&result, "%10La %d", 1.75L, 33, 44, 55);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
752 ASSERT (result != NULL);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
753 ASSERT (strcmp (result, " 0x1.cp+0 33") == 0
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
754 || strcmp (result, " 0x3.8p-1 33") == 0
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
755 || strcmp (result, " 0x7p-2 33") == 0
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
756 || strcmp (result, " 0xep-3 33") == 0);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
757 ASSERT (retval == strlen (result));
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
758 free (result);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
759 }
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
760
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
761 { /* Small precision. */
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
762 char *result;
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
763 int retval =
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
764 my_asprintf (&result, "%.10La %d", 1.75L, 33, 44, 55);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
765 ASSERT (result != NULL);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
766 ASSERT (strcmp (result, "0x1.c000000000p+0 33") == 0
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
767 || strcmp (result, "0x3.8000000000p-1 33") == 0
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
768 || strcmp (result, "0x7.0000000000p-2 33") == 0
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
769 || strcmp (result, "0xe.0000000000p-3 33") == 0);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
770 ASSERT (retval == strlen (result));
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
771 free (result);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
772 }
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
773
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
774 { /* Large precision. */
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
775 char *result;
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
776 int retval =
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
777 my_asprintf (&result, "%.50La %d", 1.75L, 33, 44, 55);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
778 ASSERT (result != NULL);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
779 ASSERT (strcmp (result, "0x1.c0000000000000000000000000000000000000000000000000p+0 33") == 0
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
780 || strcmp (result, "0x3.80000000000000000000000000000000000000000000000000p-1 33") == 0
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
781 || strcmp (result, "0x7.00000000000000000000000000000000000000000000000000p-2 33") == 0
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
782 || strcmp (result, "0xe.00000000000000000000000000000000000000000000000000p-3 33") == 0);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
783 ASSERT (retval == strlen (result));
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
784 free (result);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
785 }
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
786
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
787 { /* FLAG_LEFT. */
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
788 char *result;
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
789 int retval =
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
790 my_asprintf (&result, "%-10La %d", 1.75L, 33, 44, 55);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
791 ASSERT (result != NULL);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
792 ASSERT (strcmp (result, "0x1.cp+0 33") == 0
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
793 || strcmp (result, "0x3.8p-1 33") == 0
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
794 || strcmp (result, "0x7p-2 33") == 0
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
795 || strcmp (result, "0xep-3 33") == 0);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
796 ASSERT (retval == strlen (result));
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
797 free (result);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
798 }
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
799
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
800 { /* FLAG_SHOWSIGN. */
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
801 char *result;
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
802 int retval =
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
803 my_asprintf (&result, "%+La %d", 1.75L, 33, 44, 55);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
804 ASSERT (result != NULL);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
805 ASSERT (strcmp (result, "+0x1.cp+0 33") == 0
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
806 || strcmp (result, "+0x3.8p-1 33") == 0
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
807 || strcmp (result, "+0x7p-2 33") == 0
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
808 || strcmp (result, "+0xep-3 33") == 0);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
809 ASSERT (retval == strlen (result));
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
810 free (result);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
811 }
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
812
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
813 { /* FLAG_SPACE. */
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
814 char *result;
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
815 int retval =
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
816 my_asprintf (&result, "% La %d", 1.75L, 33, 44, 55);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
817 ASSERT (result != NULL);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
818 ASSERT (strcmp (result, " 0x1.cp+0 33") == 0
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
819 || strcmp (result, " 0x3.8p-1 33") == 0
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
820 || strcmp (result, " 0x7p-2 33") == 0
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
821 || strcmp (result, " 0xep-3 33") == 0);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
822 ASSERT (retval == strlen (result));
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
823 free (result);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
824 }
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
825
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
826 { /* FLAG_ALT. */
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
827 char *result;
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
828 int retval =
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
829 my_asprintf (&result, "%#La %d", 1.75L, 33, 44, 55);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
830 ASSERT (result != NULL);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
831 ASSERT (strcmp (result, "0x1.cp+0 33") == 0
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
832 || strcmp (result, "0x3.8p-1 33") == 0
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
833 || strcmp (result, "0x7.p-2 33") == 0
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
834 || strcmp (result, "0xe.p-3 33") == 0);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
835 ASSERT (retval == strlen (result));
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
836 free (result);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
837 }
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
838
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
839 { /* FLAG_ALT. */
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
840 char *result;
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
841 int retval =
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
842 my_asprintf (&result, "%#La %d", 1.0L, 33, 44, 55);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
843 ASSERT (result != NULL);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
844 ASSERT (strcmp (result, "0x1.p+0 33") == 0
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
845 || strcmp (result, "0x2.p-1 33") == 0
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
846 || strcmp (result, "0x4.p-2 33") == 0
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
847 || strcmp (result, "0x8.p-3 33") == 0);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
848 ASSERT (retval == strlen (result));
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
849 free (result);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
850 }
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
851
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
852 { /* FLAG_ZERO with finite number. */
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
853 char *result;
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
854 int retval =
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
855 my_asprintf (&result, "%010La %d", 1.75L, 33, 44, 55);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
856 ASSERT (result != NULL);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
857 ASSERT (strcmp (result, "0x001.cp+0 33") == 0
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
858 || strcmp (result, "0x003.8p-1 33") == 0
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
859 || strcmp (result, "0x00007p-2 33") == 0
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
860 || strcmp (result, "0x0000ep-3 33") == 0);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
861 ASSERT (retval == strlen (result));
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
862 free (result);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
863 }
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
864
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
865 { /* FLAG_ZERO with infinite number. */
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
866 char *result;
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
867 int retval =
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
868 my_asprintf (&result, "%010La %d", 1.0L / 0.0L, 33, 44, 55);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
869 ASSERT (result != NULL);
8662
023aa5c883a7 Guard against FreeBSD 6.1 bug.
Bruno Haible <bruno@clisp.org>
parents: 8648
diff changeset
870 /* "0000000inf 33" is not a valid result; see
023aa5c883a7 Guard against FreeBSD 6.1 bug.
Bruno Haible <bruno@clisp.org>
parents: 8648
diff changeset
871 <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
872 ASSERT (strcmp (result, " inf 33") == 0);
8342
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
873 ASSERT (retval == strlen (result));
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
874 free (result);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
875 }
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
876
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
877 { /* FLAG_ZERO with NaN. */
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
878 char *result;
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
879 int retval =
9854
baba3b346ab2 Use macros NaNf, NaNd, NaNl instead of NAN.
Bruno Haible <bruno@clisp.org>
parents: 9850
diff changeset
880 my_asprintf (&result, "%050La %d", NaNl (), 33, 44, 55);
8342
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
881 ASSERT (result != NULL);
8662
023aa5c883a7 Guard against FreeBSD 6.1 bug.
Bruno Haible <bruno@clisp.org>
parents: 8648
diff changeset
882 /* "0000000nan 33" is not a valid result; see
023aa5c883a7 Guard against FreeBSD 6.1 bug.
Bruno Haible <bruno@clisp.org>
parents: 8648
diff changeset
883 <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
884 ASSERT (strlen (result) == 50 + 3
8865
9e203d8ade65 Stricter check for printf result for NaN arguments.
Bruno Haible <bruno@clisp.org>
parents: 8857
diff changeset
885 && strisnan (result, strspn (result, " "), strlen (result) - 3, 0)
8850
d1fe16dfbfee Avoid test failures on IRIX 6.5.
Bruno Haible <bruno@clisp.org>
parents: 8839
diff changeset
886 && strcmp (result + strlen (result) - 3, " 33") == 0);
8342
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
887 ASSERT (retval == strlen (result));
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
888 free (result);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
889 }
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
890
8684
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
891 /* 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
892
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
893 { /* A positive number. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
894 char *result;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
895 int retval =
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
896 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
897 ASSERT (result != NULL);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
898 ASSERT (strcmp (result, "12.750000 33") == 0);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
899 ASSERT (retval == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
900 free (result);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
901 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
902
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
903 { /* A larger positive number. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
904 char *result;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
905 int retval =
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
906 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
907 ASSERT (result != NULL);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
908 ASSERT (strcmp (result, "1234567.000000 33") == 0);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
909 ASSERT (retval == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
910 free (result);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
911 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
912
8834
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
913 { /* Small and large positive numbers. */
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
914 static struct { double value; const char *string; } data[] =
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
915 {
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
916 { 1.234321234321234e-37, "0.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
917 { 1.234321234321234e-36, "0.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
918 { 1.234321234321234e-35, "0.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
919 { 1.234321234321234e-34, "0.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
920 { 1.234321234321234e-33, "0.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
921 { 1.234321234321234e-32, "0.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
922 { 1.234321234321234e-31, "0.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
923 { 1.234321234321234e-30, "0.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
924 { 1.234321234321234e-29, "0.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
925 { 1.234321234321234e-28, "0.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
926 { 1.234321234321234e-27, "0.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
927 { 1.234321234321234e-26, "0.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
928 { 1.234321234321234e-25, "0.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
929 { 1.234321234321234e-24, "0.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
930 { 1.234321234321234e-23, "0.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
931 { 1.234321234321234e-22, "0.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
932 { 1.234321234321234e-21, "0.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
933 { 1.234321234321234e-20, "0.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
934 { 1.234321234321234e-19, "0.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
935 { 1.234321234321234e-18, "0.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
936 { 1.234321234321234e-17, "0.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
937 { 1.234321234321234e-16, "0.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
938 { 1.234321234321234e-15, "0.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
939 { 1.234321234321234e-14, "0.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
940 { 1.234321234321234e-13, "0.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
941 { 1.234321234321234e-12, "0.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
942 { 1.234321234321234e-11, "0.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
943 { 1.234321234321234e-10, "0.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
944 { 1.234321234321234e-9, "0.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
945 { 1.234321234321234e-8, "0.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
946 { 1.234321234321234e-7, "0.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
947 { 1.234321234321234e-6, "0.000001" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
948 { 1.234321234321234e-5, "0.000012" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
949 { 1.234321234321234e-4, "0.000123" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
950 { 1.234321234321234e-3, "0.001234" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
951 { 1.234321234321234e-2, "0.012343" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
952 { 1.234321234321234e-1, "0.123432" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
953 { 1.234321234321234, "1.234321" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
954 { 1.234321234321234e1, "12.343212" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
955 { 1.234321234321234e2, "123.432123" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
956 { 1.234321234321234e3, "1234.321234" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
957 { 1.234321234321234e4, "12343.212343" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
958 { 1.234321234321234e5, "123432.123432" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
959 { 1.234321234321234e6, "1234321.234321" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
960 { 1.234321234321234e7, "12343212.343212" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
961 { 1.234321234321234e8, "123432123.432123" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
962 { 1.234321234321234e9, "1234321234.321234" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
963 { 1.234321234321234e10, "12343212343.2123**" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
964 { 1.234321234321234e11, "123432123432.123***" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
965 { 1.234321234321234e12, "1234321234321.23****" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
966 { 1.234321234321234e13, "12343212343212.3*****" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
967 { 1.234321234321234e14, "123432123432123.******" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
968 { 1.234321234321234e15, "1234321234321234.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
969 { 1.234321234321234e16, "123432123432123**.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
970 { 1.234321234321234e17, "123432123432123***.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
971 { 1.234321234321234e18, "123432123432123****.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
972 { 1.234321234321234e19, "123432123432123*****.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
973 { 1.234321234321234e20, "123432123432123******.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
974 { 1.234321234321234e21, "123432123432123*******.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
975 { 1.234321234321234e22, "123432123432123********.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
976 { 1.234321234321234e23, "123432123432123*********.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
977 { 1.234321234321234e24, "123432123432123**********.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
978 { 1.234321234321234e25, "123432123432123***********.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
979 { 1.234321234321234e26, "123432123432123************.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
980 { 1.234321234321234e27, "123432123432123*************.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
981 { 1.234321234321234e28, "123432123432123**************.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
982 { 1.234321234321234e29, "123432123432123***************.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
983 { 1.234321234321234e30, "123432123432123****************.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
984 { 1.234321234321234e31, "123432123432123*****************.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
985 { 1.234321234321234e32, "123432123432123******************.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
986 { 1.234321234321234e33, "123432123432123*******************.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
987 { 1.234321234321234e34, "123432123432123********************.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
988 { 1.234321234321234e35, "123432123432123*********************.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
989 { 1.234321234321234e36, "123432123432123**********************.000000" }
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
990 };
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
991 size_t k;
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
992 for (k = 0; k < SIZEOF (data); k++)
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 char *result;
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
995 int retval =
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
996 my_asprintf (&result, "%f", data[k].value);
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
997 ASSERT (result != NULL);
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
998 ASSERT (strmatch (data[k].string, result));
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
999 ASSERT (retval == strlen (result));
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1000 free (result);
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1001 }
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1002 }
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1003
8684
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1004 { /* A negative number. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1005 char *result;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1006 int retval =
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1007 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
1008 ASSERT (result != NULL);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1009 ASSERT (strcmp (result, "-0.031250 33") == 0);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1010 ASSERT (retval == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1011 free (result);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1012 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1013
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1014 { /* Positive zero. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1015 char *result;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1016 int retval =
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1017 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
1018 ASSERT (result != NULL);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1019 ASSERT (strcmp (result, "0.000000 33") == 0);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1020 ASSERT (retval == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1021 free (result);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1022 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1023
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1024 { /* Negative zero. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1025 char *result;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1026 int retval =
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1027 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
1028 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
1029 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
1030 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
1031 ASSERT (retval == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1032 free (result);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1033 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1034
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1035 { /* Positive infinity. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1036 char *result;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1037 int retval =
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1038 my_asprintf (&result, "%f %d", 1.0 / 0.0, 33, 44, 55);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1039 ASSERT (result != NULL);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1040 ASSERT (strcmp (result, "inf 33") == 0
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1041 || strcmp (result, "infinity 33") == 0);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1042 ASSERT (retval == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1043 free (result);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1044 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1045
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1046 { /* Negative infinity. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1047 char *result;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1048 int retval =
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1049 my_asprintf (&result, "%f %d", -1.0 / 0.0, 33, 44, 55);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1050 ASSERT (result != NULL);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1051 ASSERT (strcmp (result, "-inf 33") == 0
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1052 || strcmp (result, "-infinity 33") == 0);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1053 ASSERT (retval == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1054 free (result);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1055 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1056
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1057 { /* NaN. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1058 char *result;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1059 int retval =
9854
baba3b346ab2 Use macros NaNf, NaNd, NaNl instead of NAN.
Bruno Haible <bruno@clisp.org>
parents: 9850
diff changeset
1060 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
1061 ASSERT (result != NULL);
8850
d1fe16dfbfee Avoid test failures on IRIX 6.5.
Bruno Haible <bruno@clisp.org>
parents: 8839
diff changeset
1062 ASSERT (strlen (result) >= 3 + 3
8865
9e203d8ade65 Stricter check for printf result for NaN arguments.
Bruno Haible <bruno@clisp.org>
parents: 8857
diff changeset
1063 && strisnan (result, 0, strlen (result) - 3, 0)
8850
d1fe16dfbfee Avoid test failures on IRIX 6.5.
Bruno Haible <bruno@clisp.org>
parents: 8839
diff changeset
1064 && 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
1065 ASSERT (retval == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1066 free (result);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1067 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1068
8804
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1069 { /* Width. */
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1070 char *result;
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1071 int retval =
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1072 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
1073 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
1074 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
1075 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
1076 free (result);
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1077 }
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1078
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1079 { /* FLAG_LEFT. */
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1080 char *result;
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1081 int retval =
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1082 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
1083 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
1084 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
1085 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
1086 free (result);
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1087 }
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1088
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1089 { /* FLAG_SHOWSIGN. */
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1090 char *result;
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1091 int retval =
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1092 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
1093 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
1094 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
1095 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
1096 free (result);
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1097 }
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1098
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1099 { /* FLAG_SPACE. */
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1100 char *result;
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1101 int retval =
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1102 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
1103 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
1104 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
1105 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
1106 free (result);
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1107 }
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1108
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1109 { /* FLAG_ALT. */
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1110 char *result;
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1111 int retval =
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1112 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
1113 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
1114 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
1115 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
1116 free (result);
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1117 }
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1118
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1119 { /* FLAG_ALT. */
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1120 char *result;
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1121 int retval =
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1122 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
1123 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
1124 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
1125 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
1126 free (result);
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1127 }
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1128
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1129 { /* FLAG_ZERO with finite number. */
8684
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1130 char *result;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1131 int retval =
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1132 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
1133 ASSERT (result != NULL);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1134 ASSERT (strcmp (result, "00001234.000000 33") == 0);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1135 ASSERT (retval == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1136 free (result);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1137 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1138
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1139 { /* FLAG_ZERO with infinite number. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1140 char *result;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1141 int retval =
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1142 my_asprintf (&result, "%015f %d", -1.0 / 0.0, 33, 44, 55);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1143 ASSERT (result != NULL);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1144 ASSERT (strcmp (result, " -inf 33") == 0
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1145 || strcmp (result, " -infinity 33") == 0);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1146 ASSERT (retval == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1147 free (result);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1148 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1149
8804
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1150 { /* 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
1151 char *result;
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1152 int retval =
9854
baba3b346ab2 Use macros NaNf, NaNd, NaNl instead of NAN.
Bruno Haible <bruno@clisp.org>
parents: 9850
diff changeset
1153 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
1154 ASSERT (result != NULL);
8870
4e1f2ea486b4 Allow for a longer printed representation of NaN.
Bruno Haible <bruno@clisp.org>
parents: 8865
diff changeset
1155 ASSERT (strlen (result) == 50 + 3
8865
9e203d8ade65 Stricter check for printf result for NaN arguments.
Bruno Haible <bruno@clisp.org>
parents: 8857
diff changeset
1156 && strisnan (result, strspn (result, " "), strlen (result) - 3, 0)
8850
d1fe16dfbfee Avoid test failures on IRIX 6.5.
Bruno Haible <bruno@clisp.org>
parents: 8839
diff changeset
1157 && 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
1158 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
1159 free (result);
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1160 }
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1161
8684
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1162 { /* Precision. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1163 char *result;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1164 int retval =
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1165 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
1166 ASSERT (result != NULL);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1167 ASSERT (strcmp (result, "1234 33") == 0);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1168 ASSERT (retval == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1169 free (result);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1170 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1171
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1172 { /* A positive number. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1173 char *result;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1174 int retval =
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1175 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
1176 ASSERT (result != NULL);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1177 ASSERT (strcmp (result, "12.750000 33") == 0);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1178 ASSERT (retval == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1179 free (result);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1180 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1181
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1182 { /* A larger positive number. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1183 char *result;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1184 int retval =
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1185 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
1186 ASSERT (result != NULL);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1187 ASSERT (strcmp (result, "1234567.000000 33") == 0);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1188 ASSERT (retval == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1189 free (result);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1190 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1191
8834
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1192 { /* Small and large positive numbers. */
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1193 static struct { long double value; const char *string; } data[] =
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1194 {
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1195 { 1.234321234321234e-37L, "0.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1196 { 1.234321234321234e-36L, "0.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1197 { 1.234321234321234e-35L, "0.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1198 { 1.234321234321234e-34L, "0.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1199 { 1.234321234321234e-33L, "0.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1200 { 1.234321234321234e-32L, "0.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1201 { 1.234321234321234e-31L, "0.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1202 { 1.234321234321234e-30L, "0.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1203 { 1.234321234321234e-29L, "0.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1204 { 1.234321234321234e-28L, "0.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1205 { 1.234321234321234e-27L, "0.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1206 { 1.234321234321234e-26L, "0.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1207 { 1.234321234321234e-25L, "0.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1208 { 1.234321234321234e-24L, "0.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1209 { 1.234321234321234e-23L, "0.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1210 { 1.234321234321234e-22L, "0.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1211 { 1.234321234321234e-21L, "0.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1212 { 1.234321234321234e-20L, "0.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1213 { 1.234321234321234e-19L, "0.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1214 { 1.234321234321234e-18L, "0.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1215 { 1.234321234321234e-17L, "0.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1216 { 1.234321234321234e-16L, "0.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1217 { 1.234321234321234e-15L, "0.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1218 { 1.234321234321234e-14L, "0.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1219 { 1.234321234321234e-13L, "0.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1220 { 1.234321234321234e-12L, "0.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1221 { 1.234321234321234e-11L, "0.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1222 { 1.234321234321234e-10L, "0.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1223 { 1.234321234321234e-9L, "0.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1224 { 1.234321234321234e-8L, "0.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1225 { 1.234321234321234e-7L, "0.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1226 { 1.234321234321234e-6L, "0.000001" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1227 { 1.234321234321234e-5L, "0.000012" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1228 { 1.234321234321234e-4L, "0.000123" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1229 { 1.234321234321234e-3L, "0.001234" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1230 { 1.234321234321234e-2L, "0.012343" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1231 { 1.234321234321234e-1L, "0.123432" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1232 { 1.234321234321234L, "1.234321" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1233 { 1.234321234321234e1L, "12.343212" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1234 { 1.234321234321234e2L, "123.432123" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1235 { 1.234321234321234e3L, "1234.321234" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1236 { 1.234321234321234e4L, "12343.212343" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1237 { 1.234321234321234e5L, "123432.123432" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1238 { 1.234321234321234e6L, "1234321.234321" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1239 { 1.234321234321234e7L, "12343212.343212" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1240 { 1.234321234321234e8L, "123432123.432123" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1241 { 1.234321234321234e9L, "1234321234.321234" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1242 { 1.234321234321234e10L, "12343212343.2123**" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1243 { 1.234321234321234e11L, "123432123432.123***" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1244 { 1.234321234321234e12L, "1234321234321.23****" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1245 { 1.234321234321234e13L, "12343212343212.3*****" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1246 { 1.234321234321234e14L, "123432123432123.******" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1247 { 1.234321234321234e15L, "1234321234321234.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1248 { 1.234321234321234e16L, "123432123432123**.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1249 { 1.234321234321234e17L, "123432123432123***.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1250 { 1.234321234321234e18L, "123432123432123****.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1251 { 1.234321234321234e19L, "123432123432123*****.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1252 { 1.234321234321234e20L, "123432123432123******.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1253 { 1.234321234321234e21L, "123432123432123*******.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1254 { 1.234321234321234e22L, "123432123432123********.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1255 { 1.234321234321234e23L, "123432123432123*********.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1256 { 1.234321234321234e24L, "123432123432123**********.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1257 { 1.234321234321234e25L, "123432123432123***********.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1258 { 1.234321234321234e26L, "123432123432123************.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1259 { 1.234321234321234e27L, "123432123432123*************.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1260 { 1.234321234321234e28L, "123432123432123**************.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1261 { 1.234321234321234e29L, "123432123432123***************.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1262 { 1.234321234321234e30L, "123432123432123****************.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1263 { 1.234321234321234e31L, "123432123432123*****************.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1264 { 1.234321234321234e32L, "123432123432123******************.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1265 { 1.234321234321234e33L, "123432123432123*******************.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1266 { 1.234321234321234e34L, "123432123432123********************.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1267 { 1.234321234321234e35L, "123432123432123*********************.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1268 { 1.234321234321234e36L, "123432123432123**********************.000000" }
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1269 };
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1270 size_t k;
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1271 for (k = 0; k < SIZEOF (data); k++)
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1272 {
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1273 char *result;
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1274 int retval =
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1275 my_asprintf (&result, "%Lf", data[k].value);
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1276 ASSERT (result != NULL);
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1277 ASSERT (strmatch (data[k].string, result));
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1278 ASSERT (retval == strlen (result));
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1279 free (result);
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1280 }
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
8684
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1283 { /* A negative number. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1284 char *result;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1285 int retval =
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1286 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
1287 ASSERT (result != NULL);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1288 ASSERT (strcmp (result, "-0.031250 33") == 0);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1289 ASSERT (retval == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1290 free (result);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1291 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1292
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1293 { /* Positive zero. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1294 char *result;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1295 int retval =
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1296 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
1297 ASSERT (result != NULL);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1298 ASSERT (strcmp (result, "0.000000 33") == 0);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1299 ASSERT (retval == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1300 free (result);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1301 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1302
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1303 { /* Negative zero. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1304 char *result;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1305 int retval =
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1306 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
1307 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
1308 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
1309 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
1310 ASSERT (retval == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1311 free (result);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1312 }
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 { /* Positive infinity. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1315 char *result;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1316 int retval =
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1317 my_asprintf (&result, "%Lf %d", 1.0L / 0.0L, 33, 44, 55);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1318 ASSERT (result != NULL);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1319 ASSERT (strcmp (result, "inf 33") == 0
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1320 || strcmp (result, "infinity 33") == 0);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1321 ASSERT (retval == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1322 free (result);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1323 }
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 { /* Negative infinity. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1326 char *result;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1327 int retval =
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1328 my_asprintf (&result, "%Lf %d", -1.0L / 0.0L, 33, 44, 55);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1329 ASSERT (result != NULL);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1330 ASSERT (strcmp (result, "-inf 33") == 0
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1331 || strcmp (result, "-infinity 33") == 0);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1332 ASSERT (retval == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1333 free (result);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1334 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1335
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1336 { /* NaN. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1337 char *result;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1338 int retval =
9854
baba3b346ab2 Use macros NaNf, NaNd, NaNl instead of NAN.
Bruno Haible <bruno@clisp.org>
parents: 9850
diff changeset
1339 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
1340 ASSERT (result != NULL);
8850
d1fe16dfbfee Avoid test failures on IRIX 6.5.
Bruno Haible <bruno@clisp.org>
parents: 8839
diff changeset
1341 ASSERT (strlen (result) >= 3 + 3
8865
9e203d8ade65 Stricter check for printf result for NaN arguments.
Bruno Haible <bruno@clisp.org>
parents: 8857
diff changeset
1342 && strisnan (result, 0, strlen (result) - 3, 0)
8850
d1fe16dfbfee Avoid test failures on IRIX 6.5.
Bruno Haible <bruno@clisp.org>
parents: 8839
diff changeset
1343 && 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
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 }
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
1347 #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_))
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
1348 { /* 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
1349 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
1350 { 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
1351 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
1352 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
1353 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
1354 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
1355 ASSERT (strlen (result) >= 3 + 3
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
1356 && strisnan (result, 0, strlen (result) - 3, 0)
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
1357 && strcmp (result + strlen (result) - 3, " 33") == 0);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
1358 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
1359 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
1360 }
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 {
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 /* 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
1363 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
1364 { 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
1365 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
1366 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
1367 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
1368 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
1369 ASSERT (strlen (result) >= 3 + 3
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 && strisnan (result, 0, strlen (result) - 3, 0)
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 && strcmp (result + strlen (result) - 3, " 33") == 0);
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 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
1373 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
1374 }
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 /* 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
1376 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
1377 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
1378 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
1379 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
1380 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
1381 */
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
1382 { /* 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
1383 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
1384 { 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
1385 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
1386 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
1387 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
1388 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
1389 ASSERT (strlen (result) >= 3 + 3
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 && strisnan (result, 0, strlen (result) - 3, 0)
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 && strcmp (result + strlen (result) - 3, " 33") == 0);
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 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
1393 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
1394 }
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 { /* 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
1396 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
1397 { 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
1398 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
1399 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
1400 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
1401 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
1402 ASSERT (strlen (result) >= 3 + 3
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
1403 && strisnan (result, 0, strlen (result) - 3, 0)
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 && strcmp (result + strlen (result) - 3, " 33") == 0);
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 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
1406 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
1407 }
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 { /* 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
1409 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
1410 { 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
1411 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
1412 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
1413 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
1414 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
1415 ASSERT (strlen (result) >= 3 + 3
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
1416 && strisnan (result, 0, strlen (result) - 3, 0)
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 && strcmp (result + strlen (result) - 3, " 33") == 0);
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 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
1419 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
1420 }
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 { /* 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
1422 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
1423 { 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
1424 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
1425 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
1426 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
1427 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
1428 ASSERT (strlen (result) >= 3 + 3
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
1429 && strisnan (result, 0, strlen (result) - 3, 0)
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 && strcmp (result + strlen (result) - 3, " 33") == 0);
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 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
1432 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
1433 }
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 { /* 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
1435 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
1436 { 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
1437 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
1438 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
1439 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
1440 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
1441 ASSERT (strlen (result) >= 3 + 3
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
1442 && strisnan (result, 0, strlen (result) - 3, 0)
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 && strcmp (result + strlen (result) - 3, " 33") == 0);
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 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
1445 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
1446 }
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 #endif
8684
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1448
8804
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1449 { /* Width. */
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1450 char *result;
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1451 int retval =
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1452 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
1453 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
1454 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
1455 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
1456 free (result);
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1457 }
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1458
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1459 { /* FLAG_LEFT. */
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1460 char *result;
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1461 int retval =
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1462 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
1463 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
1464 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
1465 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
1466 free (result);
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1467 }
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1468
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1469 { /* FLAG_SHOWSIGN. */
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1470 char *result;
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1471 int retval =
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1472 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
1473 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
1474 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
1475 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
1476 free (result);
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1477 }
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1478
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1479 { /* FLAG_SPACE. */
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1480 char *result;
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1481 int retval =
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1482 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
1483 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
1484 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
1485 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
1486 free (result);
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1487 }
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1488
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1489 { /* FLAG_ALT. */
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1490 char *result;
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1491 int retval =
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1492 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
1493 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
1494 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
1495 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
1496 free (result);
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1497 }
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1498
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1499 { /* FLAG_ALT. */
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1500 char *result;
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1501 int retval =
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1502 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
1503 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
1504 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
1505 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
1506 free (result);
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1507 }
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1508
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1509 { /* FLAG_ZERO with finite number. */
8684
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1510 char *result;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1511 int retval =
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1512 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
1513 ASSERT (result != NULL);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1514 ASSERT (strcmp (result, "00001234.000000 33") == 0);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1515 ASSERT (retval == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1516 free (result);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1517 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1518
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1519 { /* FLAG_ZERO with infinite number. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1520 char *result;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1521 int retval =
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1522 my_asprintf (&result, "%015Lf %d", -1.0L / 0.0L, 33, 44, 55);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1523 ASSERT (result != NULL);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1524 ASSERT (strcmp (result, " -inf 33") == 0
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1525 || strcmp (result, " -infinity 33") == 0);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1526 ASSERT (retval == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1527 free (result);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1528 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1529
8804
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1530 { /* 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
1531 char *result;
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1532 int retval =
9854
baba3b346ab2 Use macros NaNf, NaNd, NaNl instead of NAN.
Bruno Haible <bruno@clisp.org>
parents: 9850
diff changeset
1533 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
1534 ASSERT (result != NULL);
8870
4e1f2ea486b4 Allow for a longer printed representation of NaN.
Bruno Haible <bruno@clisp.org>
parents: 8865
diff changeset
1535 ASSERT (strlen (result) == 50 + 3
8865
9e203d8ade65 Stricter check for printf result for NaN arguments.
Bruno Haible <bruno@clisp.org>
parents: 8857
diff changeset
1536 && strisnan (result, strspn (result, " "), strlen (result) - 3, 0)
8850
d1fe16dfbfee Avoid test failures on IRIX 6.5.
Bruno Haible <bruno@clisp.org>
parents: 8839
diff changeset
1537 && 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
1538 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
1539 free (result);
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1540 }
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1541
8684
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1542 { /* Precision. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1543 char *result;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1544 int retval =
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1545 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
1546 ASSERT (result != NULL);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1547 ASSERT (strcmp (result, "1234 33") == 0);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1548 ASSERT (retval == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1549 free (result);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1550 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1551
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1552 /* 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
1553
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1554 { /* A positive number. */
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, "%F %d", 12.75, 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, "12.750000 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
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1564 { /* A larger positive number. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1565 char *result;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1566 int retval =
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1567 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
1568 ASSERT (result != NULL);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1569 ASSERT (strcmp (result, "1234567.000000 33") == 0);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1570 ASSERT (retval == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1571 free (result);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1572 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1573
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1574 { /* A negative number. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1575 char *result;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1576 int retval =
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1577 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
1578 ASSERT (result != NULL);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1579 ASSERT (strcmp (result, "-0.031250 33") == 0);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1580 ASSERT (retval == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1581 free (result);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1582 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1583
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1584 { /* Positive zero. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1585 char *result;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1586 int retval =
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1587 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
1588 ASSERT (result != NULL);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1589 ASSERT (strcmp (result, "0.000000 33") == 0);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1590 ASSERT (retval == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1591 free (result);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1592 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1593
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1594 { /* Negative zero. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1595 char *result;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1596 int retval =
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1597 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
1598 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
1599 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
1600 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
1601 ASSERT (retval == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1602 free (result);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1603 }
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 { /* Positive infinity. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1606 char *result;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1607 int retval =
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1608 my_asprintf (&result, "%F %d", 1.0 / 0.0, 33, 44, 55);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1609 ASSERT (result != NULL);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1610 ASSERT (strcmp (result, "INF 33") == 0
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1611 || strcmp (result, "INFINITY 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 { /* Negative infinity. */
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", -1.0 / 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, "-INF 33") == 0
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1622 || strcmp (result, "-INFINITY 33") == 0);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1623 ASSERT (retval == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1624 free (result);
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
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1627 { /* NaN. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1628 char *result;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1629 int retval =
9854
baba3b346ab2 Use macros NaNf, NaNd, NaNl instead of NAN.
Bruno Haible <bruno@clisp.org>
parents: 9850
diff changeset
1630 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
1631 ASSERT (result != NULL);
8850
d1fe16dfbfee Avoid test failures on IRIX 6.5.
Bruno Haible <bruno@clisp.org>
parents: 8839
diff changeset
1632 ASSERT (strlen (result) >= 3 + 3
8865
9e203d8ade65 Stricter check for printf result for NaN arguments.
Bruno Haible <bruno@clisp.org>
parents: 8857
diff changeset
1633 && strisnan (result, 0, strlen (result) - 3, 1)
8850
d1fe16dfbfee Avoid test failures on IRIX 6.5.
Bruno Haible <bruno@clisp.org>
parents: 8839
diff changeset
1634 && 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
1635 ASSERT (retval == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1636 free (result);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1637 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1638
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1639 { /* FLAG_ZERO. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1640 char *result;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1641 int retval =
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1642 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
1643 ASSERT (result != NULL);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1644 ASSERT (strcmp (result, "00001234.000000 33") == 0);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1645 ASSERT (retval == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1646 free (result);
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
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1649 { /* FLAG_ZERO with infinite number. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1650 char *result;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1651 int retval =
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1652 my_asprintf (&result, "%015F %d", -1.0 / 0.0, 33, 44, 55);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1653 ASSERT (result != NULL);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1654 ASSERT (strcmp (result, " -INF 33") == 0
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1655 || strcmp (result, " -INFINITY 33") == 0);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1656 ASSERT (retval == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1657 free (result);
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
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1660 { /* Precision. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1661 char *result;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1662 int retval =
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1663 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
1664 ASSERT (result != NULL);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1665 ASSERT (strcmp (result, "1234 33") == 0);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1666 ASSERT (retval == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1667 free (result);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1668 }
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 { /* A positive number. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1671 char *result;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1672 int retval =
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1673 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
1674 ASSERT (result != NULL);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1675 ASSERT (strcmp (result, "12.750000 33") == 0);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1676 ASSERT (retval == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1677 free (result);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1678 }
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 { /* A larger positive number. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1681 char *result;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1682 int retval =
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1683 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
1684 ASSERT (result != NULL);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1685 ASSERT (strcmp (result, "1234567.000000 33") == 0);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1686 ASSERT (retval == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1687 free (result);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1688 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1689
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1690 { /* A negative number. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1691 char *result;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1692 int retval =
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1693 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
1694 ASSERT (result != NULL);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1695 ASSERT (strcmp (result, "-0.031250 33") == 0);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1696 ASSERT (retval == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1697 free (result);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1698 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1699
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1700 { /* Positive zero. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1701 char *result;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1702 int retval =
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1703 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
1704 ASSERT (result != NULL);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1705 ASSERT (strcmp (result, "0.000000 33") == 0);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1706 ASSERT (retval == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1707 free (result);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1708 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1709
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1710 { /* Negative zero. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1711 char *result;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1712 int retval =
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1713 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
1714 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
1715 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
1716 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
1717 ASSERT (retval == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1718 free (result);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1719 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1720
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1721 { /* Positive infinity. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1722 char *result;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1723 int retval =
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1724 my_asprintf (&result, "%LF %d", 1.0L / 0.0L, 33, 44, 55);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1725 ASSERT (result != NULL);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1726 ASSERT (strcmp (result, "INF 33") == 0
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1727 || strcmp (result, "INFINITY 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 { /* Negative infinity. */
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", -1.0L / 0.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, "-INF 33") == 0
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1738 || strcmp (result, "-INFINITY 33") == 0);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1739 ASSERT (retval == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1740 free (result);
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
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1743 { /* NaN. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1744 char *result;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1745 int retval =
9854
baba3b346ab2 Use macros NaNf, NaNd, NaNl instead of NAN.
Bruno Haible <bruno@clisp.org>
parents: 9850
diff changeset
1746 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
1747 ASSERT (result != NULL);
8850
d1fe16dfbfee Avoid test failures on IRIX 6.5.
Bruno Haible <bruno@clisp.org>
parents: 8839
diff changeset
1748 ASSERT (strlen (result) >= 3 + 3
8865
9e203d8ade65 Stricter check for printf result for NaN arguments.
Bruno Haible <bruno@clisp.org>
parents: 8857
diff changeset
1749 && strisnan (result, 0, strlen (result) - 3, 1)
8850
d1fe16dfbfee Avoid test failures on IRIX 6.5.
Bruno Haible <bruno@clisp.org>
parents: 8839
diff changeset
1750 && 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
1751 ASSERT (retval == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1752 free (result);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1753 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1754
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1755 { /* FLAG_ZERO. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1756 char *result;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1757 int retval =
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1758 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
1759 ASSERT (result != NULL);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1760 ASSERT (strcmp (result, "00001234.000000 33") == 0);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1761 ASSERT (retval == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1762 free (result);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1763 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1764
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1765 { /* FLAG_ZERO with infinite number. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1766 char *result;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1767 int retval =
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1768 my_asprintf (&result, "%015LF %d", -1.0L / 0.0L, 33, 44, 55);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1769 ASSERT (result != NULL);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1770 ASSERT (strcmp (result, " -INF 33") == 0
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1771 || strcmp (result, " -INFINITY 33") == 0);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1772 ASSERT (retval == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1773 free (result);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1774 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1775
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1776 { /* Precision. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1777 char *result;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1778 int retval =
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1779 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
1780 ASSERT (result != NULL);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1781 ASSERT (strcmp (result, "1234 33") == 0);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1782 ASSERT (retval == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1783 free (result);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1784 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1785
8836
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1786 /* 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
1787
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1788 { /* A positive number. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1789 char *result;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1790 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1791 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
1792 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
1793 ASSERT (strcmp (result, "1.275000e+01 33") == 0
5efc1d668039 Accomodate for implementations that produce 3 exponent digits in %e and %g.
Bruno Haible <bruno@clisp.org>
parents: 8836
diff changeset
1794 || 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
1795 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1796 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1797 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1798
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1799 { /* A larger positive number. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1800 char *result;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1801 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1802 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
1803 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
1804 ASSERT (strcmp (result, "1.234567e+06 33") == 0
5efc1d668039 Accomodate for implementations that produce 3 exponent digits in %e and %g.
Bruno Haible <bruno@clisp.org>
parents: 8836
diff changeset
1805 || 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
1806 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1807 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1808 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1809
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1810 { /* Small and large positive numbers. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1811 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
1812 {
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1813 { 1.234321234321234e-37, "1.234321e-37" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1814 { 1.234321234321234e-36, "1.234321e-36" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1815 { 1.234321234321234e-35, "1.234321e-35" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1816 { 1.234321234321234e-34, "1.234321e-34" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1817 { 1.234321234321234e-33, "1.234321e-33" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1818 { 1.234321234321234e-32, "1.234321e-32" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1819 { 1.234321234321234e-31, "1.234321e-31" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1820 { 1.234321234321234e-30, "1.234321e-30" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1821 { 1.234321234321234e-29, "1.234321e-29" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1822 { 1.234321234321234e-28, "1.234321e-28" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1823 { 1.234321234321234e-27, "1.234321e-27" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1824 { 1.234321234321234e-26, "1.234321e-26" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1825 { 1.234321234321234e-25, "1.234321e-25" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1826 { 1.234321234321234e-24, "1.234321e-24" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1827 { 1.234321234321234e-23, "1.234321e-23" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1828 { 1.234321234321234e-22, "1.234321e-22" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1829 { 1.234321234321234e-21, "1.234321e-21" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1830 { 1.234321234321234e-20, "1.234321e-20" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1831 { 1.234321234321234e-19, "1.234321e-19" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1832 { 1.234321234321234e-18, "1.234321e-18" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1833 { 1.234321234321234e-17, "1.234321e-17" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1834 { 1.234321234321234e-16, "1.234321e-16" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1835 { 1.234321234321234e-15, "1.234321e-15" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1836 { 1.234321234321234e-14, "1.234321e-14" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1837 { 1.234321234321234e-13, "1.234321e-13" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1838 { 1.234321234321234e-12, "1.234321e-12" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1839 { 1.234321234321234e-11, "1.234321e-11" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1840 { 1.234321234321234e-10, "1.234321e-10" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1841 { 1.234321234321234e-9, "1.234321e-09" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1842 { 1.234321234321234e-8, "1.234321e-08" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1843 { 1.234321234321234e-7, "1.234321e-07" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1844 { 1.234321234321234e-6, "1.234321e-06" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1845 { 1.234321234321234e-5, "1.234321e-05" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1846 { 1.234321234321234e-4, "1.234321e-04" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1847 { 1.234321234321234e-3, "1.234321e-03" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1848 { 1.234321234321234e-2, "1.234321e-02" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1849 { 1.234321234321234e-1, "1.234321e-01" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1850 { 1.234321234321234, "1.234321e+00" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1851 { 1.234321234321234e1, "1.234321e+01" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1852 { 1.234321234321234e2, "1.234321e+02" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1853 { 1.234321234321234e3, "1.234321e+03" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1854 { 1.234321234321234e4, "1.234321e+04" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1855 { 1.234321234321234e5, "1.234321e+05" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1856 { 1.234321234321234e6, "1.234321e+06" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1857 { 1.234321234321234e7, "1.234321e+07" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1858 { 1.234321234321234e8, "1.234321e+08" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1859 { 1.234321234321234e9, "1.234321e+09" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1860 { 1.234321234321234e10, "1.234321e+10" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1861 { 1.234321234321234e11, "1.234321e+11" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1862 { 1.234321234321234e12, "1.234321e+12" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1863 { 1.234321234321234e13, "1.234321e+13" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1864 { 1.234321234321234e14, "1.234321e+14" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1865 { 1.234321234321234e15, "1.234321e+15" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1866 { 1.234321234321234e16, "1.234321e+16" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1867 { 1.234321234321234e17, "1.234321e+17" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1868 { 1.234321234321234e18, "1.234321e+18" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1869 { 1.234321234321234e19, "1.234321e+19" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1870 { 1.234321234321234e20, "1.234321e+20" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1871 { 1.234321234321234e21, "1.234321e+21" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1872 { 1.234321234321234e22, "1.234321e+22" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1873 { 1.234321234321234e23, "1.234321e+23" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1874 { 1.234321234321234e24, "1.234321e+24" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1875 { 1.234321234321234e25, "1.234321e+25" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1876 { 1.234321234321234e26, "1.234321e+26" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1877 { 1.234321234321234e27, "1.234321e+27" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1878 { 1.234321234321234e28, "1.234321e+28" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1879 { 1.234321234321234e29, "1.234321e+29" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1880 { 1.234321234321234e30, "1.234321e+30" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1881 { 1.234321234321234e31, "1.234321e+31" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1882 { 1.234321234321234e32, "1.234321e+32" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1883 { 1.234321234321234e33, "1.234321e+33" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1884 { 1.234321234321234e34, "1.234321e+34" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1885 { 1.234321234321234e35, "1.234321e+35" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1886 { 1.234321234321234e36, "1.234321e+36" }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1887 };
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1888 size_t k;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1889 for (k = 0; k < SIZEOF (data); k++)
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1890 {
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1891 char *result;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1892 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1893 my_asprintf (&result, "%e", data[k].value);
8839
5efc1d668039 Accomodate for implementations that produce 3 exponent digits in %e and %g.
Bruno Haible <bruno@clisp.org>
parents: 8836
diff changeset
1894 const char *expected = data[k].string;
8836
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1895 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
1896 ASSERT (strcmp (result, expected) == 0
5efc1d668039 Accomodate for implementations that produce 3 exponent digits in %e and %g.
Bruno Haible <bruno@clisp.org>
parents: 8836
diff changeset
1897 /* Some implementations produce exponents with 3 digits. */
5efc1d668039 Accomodate for implementations that produce 3 exponent digits in %e and %g.
Bruno Haible <bruno@clisp.org>
parents: 8836
diff changeset
1898 || (strlen (result) == strlen (expected) + 1
5efc1d668039 Accomodate for implementations that produce 3 exponent digits in %e and %g.
Bruno Haible <bruno@clisp.org>
parents: 8836
diff changeset
1899 && memcmp (result, expected, strlen (expected) - 2) == 0
5efc1d668039 Accomodate for implementations that produce 3 exponent digits in %e and %g.
Bruno Haible <bruno@clisp.org>
parents: 8836
diff changeset
1900 && result[strlen (expected) - 2] == '0'
5efc1d668039 Accomodate for implementations that produce 3 exponent digits in %e and %g.
Bruno Haible <bruno@clisp.org>
parents: 8836
diff changeset
1901 && strcmp (result + strlen (expected) - 1,
5efc1d668039 Accomodate for implementations that produce 3 exponent digits in %e and %g.
Bruno Haible <bruno@clisp.org>
parents: 8836
diff changeset
1902 expected + strlen (expected) - 2)
5efc1d668039 Accomodate for implementations that produce 3 exponent digits in %e and %g.
Bruno Haible <bruno@clisp.org>
parents: 8836
diff changeset
1903 == 0));
8836
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1904 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1905 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1906 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1907 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1908
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1909 { /* A negative number. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1910 char *result;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1911 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1912 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
1913 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
1914 ASSERT (strcmp (result, "-3.125000e-02 33") == 0
5efc1d668039 Accomodate for implementations that produce 3 exponent digits in %e and %g.
Bruno Haible <bruno@clisp.org>
parents: 8836
diff changeset
1915 || 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
1916 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1917 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1918 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1919
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1920 { /* Positive zero. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1921 char *result;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1922 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1923 my_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
1924 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
1925 ASSERT (strcmp (result, "0.000000e+00 33") == 0
5efc1d668039 Accomodate for implementations that produce 3 exponent digits in %e and %g.
Bruno Haible <bruno@clisp.org>
parents: 8836
diff changeset
1926 || 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
1927 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1928 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1929 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1930
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1931 { /* Negative zero. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1932 char *result;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1933 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1934 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
1935 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
1936 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
1937 ASSERT (strcmp (result, "-0.000000e+00 33") == 0
df0b5e8ea770 Avoid test failures on platforms where -0.0 and 0.0 are identical.
Bruno Haible <bruno@clisp.org>
parents: 8850
diff changeset
1938 || 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
1939 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1940 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1941 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1942
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1943 { /* Positive infinity. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1944 char *result;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1945 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1946 my_asprintf (&result, "%e %d", 1.0 / 0.0, 33, 44, 55);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1947 ASSERT (result != NULL);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1948 ASSERT (strcmp (result, "inf 33") == 0
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1949 || strcmp (result, "infinity 33") == 0);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1950 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1951 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1952 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1953
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1954 { /* Negative infinity. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1955 char *result;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1956 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1957 my_asprintf (&result, "%e %d", -1.0 / 0.0, 33, 44, 55);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1958 ASSERT (result != NULL);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1959 ASSERT (strcmp (result, "-inf 33") == 0
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1960 || strcmp (result, "-infinity 33") == 0);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1961 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1962 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1963 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1964
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1965 { /* NaN. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1966 char *result;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1967 int retval =
9854
baba3b346ab2 Use macros NaNf, NaNd, NaNl instead of NAN.
Bruno Haible <bruno@clisp.org>
parents: 9850
diff changeset
1968 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
1969 ASSERT (result != NULL);
8850
d1fe16dfbfee Avoid test failures on IRIX 6.5.
Bruno Haible <bruno@clisp.org>
parents: 8839
diff changeset
1970 ASSERT (strlen (result) >= 3 + 3
8865
9e203d8ade65 Stricter check for printf result for NaN arguments.
Bruno Haible <bruno@clisp.org>
parents: 8857
diff changeset
1971 && strisnan (result, 0, strlen (result) - 3, 0)
8850
d1fe16dfbfee Avoid test failures on IRIX 6.5.
Bruno Haible <bruno@clisp.org>
parents: 8839
diff changeset
1972 && 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
1973 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1974 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1975 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1976
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1977 { /* Width. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1978 char *result;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1979 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1980 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
1981 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
1982 ASSERT (strcmp (result, " 1.750000e+00 33") == 0
5efc1d668039 Accomodate for implementations that produce 3 exponent digits in %e and %g.
Bruno Haible <bruno@clisp.org>
parents: 8836
diff changeset
1983 || 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
1984 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1985 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1986 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1987
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1988 { /* FLAG_LEFT. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1989 char *result;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1990 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1991 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
1992 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
1993 ASSERT (strcmp (result, "1.750000e+00 33") == 0
5efc1d668039 Accomodate for implementations that produce 3 exponent digits in %e and %g.
Bruno Haible <bruno@clisp.org>
parents: 8836
diff changeset
1994 || 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
1995 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1996 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1997 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1998
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1999 { /* FLAG_SHOWSIGN. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2000 char *result;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2001 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2002 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
2003 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
2004 ASSERT (strcmp (result, "+1.750000e+00 33") == 0
5efc1d668039 Accomodate for implementations that produce 3 exponent digits in %e and %g.
Bruno Haible <bruno@clisp.org>
parents: 8836
diff changeset
2005 || 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
2006 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2007 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2008 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2009
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2010 { /* FLAG_SPACE. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2011 char *result;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2012 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2013 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
2014 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
2015 ASSERT (strcmp (result, " 1.750000e+00 33") == 0
5efc1d668039 Accomodate for implementations that produce 3 exponent digits in %e and %g.
Bruno Haible <bruno@clisp.org>
parents: 8836
diff changeset
2016 || 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
2017 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2018 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2019 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2020
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2021 { /* FLAG_ALT. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2022 char *result;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2023 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2024 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
2025 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
2026 ASSERT (strcmp (result, "1.750000e+00 33") == 0
5efc1d668039 Accomodate for implementations that produce 3 exponent digits in %e and %g.
Bruno Haible <bruno@clisp.org>
parents: 8836
diff changeset
2027 || 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
2028 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2029 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2030 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2031
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2032 { /* FLAG_ALT. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2033 char *result;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2034 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2035 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
2036 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
2037 ASSERT (strcmp (result, "2.e+00 33") == 0
5efc1d668039 Accomodate for implementations that produce 3 exponent digits in %e and %g.
Bruno Haible <bruno@clisp.org>
parents: 8836
diff changeset
2038 || 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
2039 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2040 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2041 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2042
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2043 { /* FLAG_ALT. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2044 char *result;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2045 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2046 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
2047 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
2048 ASSERT (strcmp (result, "1.e+01 33") == 0
5efc1d668039 Accomodate for implementations that produce 3 exponent digits in %e and %g.
Bruno Haible <bruno@clisp.org>
parents: 8836
diff changeset
2049 || 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
2050 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2051 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2052 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2053
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2054 { /* FLAG_ZERO with finite number. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2055 char *result;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2056 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2057 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
2058 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
2059 ASSERT (strcmp (result, "0001.234000e+03 33") == 0
5efc1d668039 Accomodate for implementations that produce 3 exponent digits in %e and %g.
Bruno Haible <bruno@clisp.org>
parents: 8836
diff changeset
2060 || 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
2061 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2062 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2063 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2064
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2065 { /* FLAG_ZERO with infinite number. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2066 char *result;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2067 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2068 my_asprintf (&result, "%015e %d", -1.0 / 0.0, 33, 44, 55);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2069 ASSERT (result != NULL);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2070 ASSERT (strcmp (result, " -inf 33") == 0
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2071 || strcmp (result, " -infinity 33") == 0);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2072 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2073 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2074 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2075
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2076 { /* FLAG_ZERO with NaN. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2077 char *result;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2078 int retval =
9854
baba3b346ab2 Use macros NaNf, NaNd, NaNl instead of NAN.
Bruno Haible <bruno@clisp.org>
parents: 9850
diff changeset
2079 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
2080 ASSERT (result != NULL);
8870
4e1f2ea486b4 Allow for a longer printed representation of NaN.
Bruno Haible <bruno@clisp.org>
parents: 8865
diff changeset
2081 ASSERT (strlen (result) == 50 + 3
8865
9e203d8ade65 Stricter check for printf result for NaN arguments.
Bruno Haible <bruno@clisp.org>
parents: 8857
diff changeset
2082 && strisnan (result, strspn (result, " "), strlen (result) - 3, 0)
8850
d1fe16dfbfee Avoid test failures on IRIX 6.5.
Bruno Haible <bruno@clisp.org>
parents: 8839
diff changeset
2083 && 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
2084 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2085 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2086 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2087
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2088 { /* Precision. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2089 char *result;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2090 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2091 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
2092 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
2093 ASSERT (strcmp (result, "1e+03 33") == 0
5efc1d668039 Accomodate for implementations that produce 3 exponent digits in %e and %g.
Bruno Haible <bruno@clisp.org>
parents: 8836
diff changeset
2094 || strcmp (result, "1e+003 33") == 0);
8836
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2095 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2096 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2097 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2098
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2099 { /* A positive number. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2100 char *result;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2101 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2102 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
2103 ASSERT (result != NULL);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2104 ASSERT (strcmp (result, "1.275000e+01 33") == 0);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2105 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2106 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2107 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2108
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2109 { /* A larger positive number. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2110 char *result;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2111 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2112 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
2113 ASSERT (result != NULL);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2114 ASSERT (strcmp (result, "1.234567e+06 33") == 0);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2115 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2116 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2117 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2118
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2119 { /* Small and large positive numbers. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2120 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
2121 {
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2122 { 1.234321234321234e-37L, "1.234321e-37" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2123 { 1.234321234321234e-36L, "1.234321e-36" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2124 { 1.234321234321234e-35L, "1.234321e-35" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2125 { 1.234321234321234e-34L, "1.234321e-34" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2126 { 1.234321234321234e-33L, "1.234321e-33" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2127 { 1.234321234321234e-32L, "1.234321e-32" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2128 { 1.234321234321234e-31L, "1.234321e-31" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2129 { 1.234321234321234e-30L, "1.234321e-30" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2130 { 1.234321234321234e-29L, "1.234321e-29" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2131 { 1.234321234321234e-28L, "1.234321e-28" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2132 { 1.234321234321234e-27L, "1.234321e-27" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2133 { 1.234321234321234e-26L, "1.234321e-26" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2134 { 1.234321234321234e-25L, "1.234321e-25" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2135 { 1.234321234321234e-24L, "1.234321e-24" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2136 { 1.234321234321234e-23L, "1.234321e-23" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2137 { 1.234321234321234e-22L, "1.234321e-22" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2138 { 1.234321234321234e-21L, "1.234321e-21" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2139 { 1.234321234321234e-20L, "1.234321e-20" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2140 { 1.234321234321234e-19L, "1.234321e-19" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2141 { 1.234321234321234e-18L, "1.234321e-18" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2142 { 1.234321234321234e-17L, "1.234321e-17" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2143 { 1.234321234321234e-16L, "1.234321e-16" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2144 { 1.234321234321234e-15L, "1.234321e-15" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2145 { 1.234321234321234e-14L, "1.234321e-14" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2146 { 1.234321234321234e-13L, "1.234321e-13" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2147 { 1.234321234321234e-12L, "1.234321e-12" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2148 { 1.234321234321234e-11L, "1.234321e-11" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2149 { 1.234321234321234e-10L, "1.234321e-10" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2150 { 1.234321234321234e-9L, "1.234321e-09" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2151 { 1.234321234321234e-8L, "1.234321e-08" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2152 { 1.234321234321234e-7L, "1.234321e-07" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2153 { 1.234321234321234e-6L, "1.234321e-06" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2154 { 1.234321234321234e-5L, "1.234321e-05" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2155 { 1.234321234321234e-4L, "1.234321e-04" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2156 { 1.234321234321234e-3L, "1.234321e-03" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2157 { 1.234321234321234e-2L, "1.234321e-02" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2158 { 1.234321234321234e-1L, "1.234321e-01" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2159 { 1.234321234321234L, "1.234321e+00" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2160 { 1.234321234321234e1L, "1.234321e+01" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2161 { 1.234321234321234e2L, "1.234321e+02" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2162 { 1.234321234321234e3L, "1.234321e+03" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2163 { 1.234321234321234e4L, "1.234321e+04" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2164 { 1.234321234321234e5L, "1.234321e+05" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2165 { 1.234321234321234e6L, "1.234321e+06" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2166 { 1.234321234321234e7L, "1.234321e+07" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2167 { 1.234321234321234e8L, "1.234321e+08" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2168 { 1.234321234321234e9L, "1.234321e+09" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2169 { 1.234321234321234e10L, "1.234321e+10" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2170 { 1.234321234321234e11L, "1.234321e+11" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2171 { 1.234321234321234e12L, "1.234321e+12" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2172 { 1.234321234321234e13L, "1.234321e+13" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2173 { 1.234321234321234e14L, "1.234321e+14" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2174 { 1.234321234321234e15L, "1.234321e+15" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2175 { 1.234321234321234e16L, "1.234321e+16" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2176 { 1.234321234321234e17L, "1.234321e+17" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2177 { 1.234321234321234e18L, "1.234321e+18" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2178 { 1.234321234321234e19L, "1.234321e+19" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2179 { 1.234321234321234e20L, "1.234321e+20" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2180 { 1.234321234321234e21L, "1.234321e+21" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2181 { 1.234321234321234e22L, "1.234321e+22" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2182 { 1.234321234321234e23L, "1.234321e+23" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2183 { 1.234321234321234e24L, "1.234321e+24" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2184 { 1.234321234321234e25L, "1.234321e+25" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2185 { 1.234321234321234e26L, "1.234321e+26" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2186 { 1.234321234321234e27L, "1.234321e+27" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2187 { 1.234321234321234e28L, "1.234321e+28" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2188 { 1.234321234321234e29L, "1.234321e+29" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2189 { 1.234321234321234e30L, "1.234321e+30" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2190 { 1.234321234321234e31L, "1.234321e+31" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2191 { 1.234321234321234e32L, "1.234321e+32" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2192 { 1.234321234321234e33L, "1.234321e+33" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2193 { 1.234321234321234e34L, "1.234321e+34" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2194 { 1.234321234321234e35L, "1.234321e+35" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2195 { 1.234321234321234e36L, "1.234321e+36" }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2196 };
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2197 size_t k;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2198 for (k = 0; k < SIZEOF (data); k++)
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2199 {
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2200 char *result;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2201 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2202 my_asprintf (&result, "%Le", data[k].value);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2203 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
2204 ASSERT (strcmp (result, data[k].string) == 0);
8836
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2205 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2206 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2207 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2208 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2209
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2210 { /* A negative number. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2211 char *result;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2212 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2213 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
2214 ASSERT (result != NULL);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2215 ASSERT (strcmp (result, "-3.125000e-02 33") == 0);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2216 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2217 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2218 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2219
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2220 { /* Positive zero. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2221 char *result;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2222 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2223 my_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
2224 ASSERT (result != NULL);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2225 ASSERT (strcmp (result, "0.000000e+00 33") == 0);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2226 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2227 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2228 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2229
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2230 { /* Negative zero. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2231 char *result;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2232 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2233 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
2234 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
2235 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
2236 ASSERT (strcmp (result, "-0.000000e+00 33") == 0);
8836
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2237 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2238 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2239 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2240
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2241 { /* Positive infinity. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2242 char *result;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2243 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2244 my_asprintf (&result, "%Le %d", 1.0L / 0.0L, 33, 44, 55);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2245 ASSERT (result != NULL);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2246 ASSERT (strcmp (result, "inf 33") == 0
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2247 || strcmp (result, "infinity 33") == 0);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2248 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2249 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2250 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2251
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2252 { /* Negative infinity. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2253 char *result;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2254 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2255 my_asprintf (&result, "%Le %d", -1.0L / 0.0L, 33, 44, 55);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2256 ASSERT (result != NULL);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2257 ASSERT (strcmp (result, "-inf 33") == 0
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2258 || strcmp (result, "-infinity 33") == 0);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2259 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2260 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2261 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2262
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2263 { /* NaN. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2264 char *result;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2265 int retval =
9854
baba3b346ab2 Use macros NaNf, NaNd, NaNl instead of NAN.
Bruno Haible <bruno@clisp.org>
parents: 9850
diff changeset
2266 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
2267 ASSERT (result != NULL);
8850
d1fe16dfbfee Avoid test failures on IRIX 6.5.
Bruno Haible <bruno@clisp.org>
parents: 8839
diff changeset
2268 ASSERT (strlen (result) >= 3 + 3
8865
9e203d8ade65 Stricter check for printf result for NaN arguments.
Bruno Haible <bruno@clisp.org>
parents: 8857
diff changeset
2269 && strisnan (result, 0, strlen (result) - 3, 0)
8850
d1fe16dfbfee Avoid test failures on IRIX 6.5.
Bruno Haible <bruno@clisp.org>
parents: 8839
diff changeset
2270 && 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
2271 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2272 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2273 }
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
2274 #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_))
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2275 { /* 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
2276 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
2277 { 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
2278 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
2279 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
2280 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
2281 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
2282 ASSERT (strlen (result) >= 3 + 3
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2283 && strisnan (result, 0, strlen (result) - 3, 0)
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2284 && strcmp (result + strlen (result) - 3, " 33") == 0);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2285 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
2286 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
2287 }
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2288 {
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2289 /* 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
2290 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
2291 { 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
2292 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
2293 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
2294 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
2295 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
2296 ASSERT (strlen (result) >= 3 + 3
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2297 && strisnan (result, 0, strlen (result) - 3, 0)
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2298 && strcmp (result + strlen (result) - 3, " 33") == 0);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2299 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
2300 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
2301 }
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2302 /* 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
2303 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
2304 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
2305 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
2306 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
2307 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
2308 */
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2309 { /* 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
2310 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
2311 { 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
2312 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
2313 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
2314 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
2315 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
2316 ASSERT (strlen (result) >= 3 + 3
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2317 && strisnan (result, 0, strlen (result) - 3, 0)
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2318 && strcmp (result + strlen (result) - 3, " 33") == 0);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2319 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
2320 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
2321 }
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2322 { /* 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
2323 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
2324 { 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
2325 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
2326 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
2327 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
2328 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
2329 ASSERT (strlen (result) >= 3 + 3
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2330 && strisnan (result, 0, strlen (result) - 3, 0)
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2331 && strcmp (result + strlen (result) - 3, " 33") == 0);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2332 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
2333 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
2334 }
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2335 { /* 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
2336 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
2337 { 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
2338 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
2339 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
2340 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
2341 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
2342 ASSERT (strlen (result) >= 3 + 3
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2343 && strisnan (result, 0, strlen (result) - 3, 0)
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2344 && strcmp (result + strlen (result) - 3, " 33") == 0);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2345 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
2346 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
2347 }
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2348 { /* 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
2349 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
2350 { 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
2351 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
2352 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
2353 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
2354 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
2355 ASSERT (strlen (result) >= 3 + 3
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2356 && strisnan (result, 0, strlen (result) - 3, 0)
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2357 && strcmp (result + strlen (result) - 3, " 33") == 0);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2358 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
2359 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
2360 }
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2361 { /* 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
2362 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
2363 { 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
2364 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
2365 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
2366 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
2367 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
2368 ASSERT (strlen (result) >= 3 + 3
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2369 && strisnan (result, 0, strlen (result) - 3, 0)
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2370 && strcmp (result + strlen (result) - 3, " 33") == 0);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2371 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
2372 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
2373 }
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2374 #endif
8836
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2375
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2376 { /* Width. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2377 char *result;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2378 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2379 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
2380 ASSERT (result != NULL);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2381 ASSERT (strcmp (result, " 1.750000e+00 33") == 0);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2382 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2383 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2384 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2385
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2386 { /* FLAG_LEFT. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2387 char *result;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2388 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2389 my_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
2390 ASSERT (result != NULL);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2391 ASSERT (strcmp (result, "1.750000e+00 33") == 0);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2392 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2393 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2394 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2395
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2396 { /* FLAG_SHOWSIGN. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2397 char *result;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2398 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2399 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
2400 ASSERT (result != NULL);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2401 ASSERT (strcmp (result, "+1.750000e+00 33") == 0);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2402 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2403 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2404 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2405
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2406 { /* FLAG_SPACE. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2407 char *result;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2408 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2409 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
2410 ASSERT (result != NULL);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2411 ASSERT (strcmp (result, " 1.750000e+00 33") == 0);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2412 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2413 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2414 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2415
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2416 { /* FLAG_ALT. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2417 char *result;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2418 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2419 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
2420 ASSERT (result != NULL);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2421 ASSERT (strcmp (result, "1.750000e+00 33") == 0);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2422 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2423 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2424 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2425
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2426 { /* FLAG_ALT. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2427 char *result;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2428 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2429 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
2430 ASSERT (result != NULL);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2431 ASSERT (strcmp (result, "2.e+00 33") == 0);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2432 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2433 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2434 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2435
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2436 { /* FLAG_ALT. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2437 char *result;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2438 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2439 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
2440 ASSERT (result != NULL);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2441 ASSERT (strcmp (result, "1.e+01 33") == 0);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2442 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2443 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2444 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2445
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2446 { /* FLAG_ZERO with finite number. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2447 char *result;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2448 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2449 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
2450 ASSERT (result != NULL);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2451 ASSERT (strcmp (result, "0001.234000e+03 33") == 0);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2452 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2453 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2454 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2455
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2456 { /* FLAG_ZERO with infinite number. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2457 char *result;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2458 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2459 my_asprintf (&result, "%015Le %d", -1.0L / 0.0L, 33, 44, 55);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2460 ASSERT (result != NULL);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2461 ASSERT (strcmp (result, " -inf 33") == 0
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2462 || strcmp (result, " -infinity 33") == 0);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2463 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2464 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2465 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2466
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2467 { /* FLAG_ZERO with NaN. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2468 char *result;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2469 int retval =
9854
baba3b346ab2 Use macros NaNf, NaNd, NaNl instead of NAN.
Bruno Haible <bruno@clisp.org>
parents: 9850
diff changeset
2470 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
2471 ASSERT (result != NULL);
8870
4e1f2ea486b4 Allow for a longer printed representation of NaN.
Bruno Haible <bruno@clisp.org>
parents: 8865
diff changeset
2472 ASSERT (strlen (result) == 50 + 3
8865
9e203d8ade65 Stricter check for printf result for NaN arguments.
Bruno Haible <bruno@clisp.org>
parents: 8857
diff changeset
2473 && strisnan (result, strspn (result, " "), strlen (result) - 3, 0)
8850
d1fe16dfbfee Avoid test failures on IRIX 6.5.
Bruno Haible <bruno@clisp.org>
parents: 8839
diff changeset
2474 && 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
2475 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2476 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2477 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2478
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2479 { /* Precision. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2480 char *result;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2481 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2482 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
2483 ASSERT (result != NULL);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2484 ASSERT (strcmp (result, "1e+03 33") == 0);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2485 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2486 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2487 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2488
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2489 /* 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
2490
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2491 { /* A positive number. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2492 char *result;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2493 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2494 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
2495 ASSERT (result != NULL);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2496 ASSERT (strcmp (result, "12.75 33") == 0);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2497 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2498 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2499 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2500
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2501 { /* A larger positive number. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2502 char *result;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2503 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2504 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
2505 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
2506 ASSERT (strcmp (result, "1.23457e+06 33") == 0
5efc1d668039 Accomodate for implementations that produce 3 exponent digits in %e and %g.
Bruno Haible <bruno@clisp.org>
parents: 8836
diff changeset
2507 || 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
2508 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2509 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2510 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2511
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2512 { /* Small and large positive numbers. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2513 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
2514 {
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2515 { 1.234321234321234e-37, "1.23432e-37" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2516 { 1.234321234321234e-36, "1.23432e-36" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2517 { 1.234321234321234e-35, "1.23432e-35" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2518 { 1.234321234321234e-34, "1.23432e-34" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2519 { 1.234321234321234e-33, "1.23432e-33" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2520 { 1.234321234321234e-32, "1.23432e-32" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2521 { 1.234321234321234e-31, "1.23432e-31" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2522 { 1.234321234321234e-30, "1.23432e-30" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2523 { 1.234321234321234e-29, "1.23432e-29" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2524 { 1.234321234321234e-28, "1.23432e-28" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2525 { 1.234321234321234e-27, "1.23432e-27" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2526 { 1.234321234321234e-26, "1.23432e-26" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2527 { 1.234321234321234e-25, "1.23432e-25" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2528 { 1.234321234321234e-24, "1.23432e-24" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2529 { 1.234321234321234e-23, "1.23432e-23" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2530 { 1.234321234321234e-22, "1.23432e-22" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2531 { 1.234321234321234e-21, "1.23432e-21" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2532 { 1.234321234321234e-20, "1.23432e-20" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2533 { 1.234321234321234e-19, "1.23432e-19" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2534 { 1.234321234321234e-18, "1.23432e-18" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2535 { 1.234321234321234e-17, "1.23432e-17" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2536 { 1.234321234321234e-16, "1.23432e-16" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2537 { 1.234321234321234e-15, "1.23432e-15" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2538 { 1.234321234321234e-14, "1.23432e-14" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2539 { 1.234321234321234e-13, "1.23432e-13" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2540 { 1.234321234321234e-12, "1.23432e-12" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2541 { 1.234321234321234e-11, "1.23432e-11" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2542 { 1.234321234321234e-10, "1.23432e-10" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2543 { 1.234321234321234e-9, "1.23432e-09" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2544 { 1.234321234321234e-8, "1.23432e-08" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2545 { 1.234321234321234e-7, "1.23432e-07" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2546 { 1.234321234321234e-6, "1.23432e-06" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2547 { 1.234321234321234e-5, "1.23432e-05" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2548 { 1.234321234321234e-4, "0.000123432" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2549 { 1.234321234321234e-3, "0.00123432" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2550 { 1.234321234321234e-2, "0.0123432" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2551 { 1.234321234321234e-1, "0.123432" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2552 { 1.234321234321234, "1.23432" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2553 { 1.234321234321234e1, "12.3432" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2554 { 1.234321234321234e2, "123.432" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2555 { 1.234321234321234e3, "1234.32" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2556 { 1.234321234321234e4, "12343.2" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2557 { 1.234321234321234e5, "123432" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2558 { 1.234321234321234e6, "1.23432e+06" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2559 { 1.234321234321234e7, "1.23432e+07" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2560 { 1.234321234321234e8, "1.23432e+08" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2561 { 1.234321234321234e9, "1.23432e+09" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2562 { 1.234321234321234e10, "1.23432e+10" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2563 { 1.234321234321234e11, "1.23432e+11" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2564 { 1.234321234321234e12, "1.23432e+12" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2565 { 1.234321234321234e13, "1.23432e+13" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2566 { 1.234321234321234e14, "1.23432e+14" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2567 { 1.234321234321234e15, "1.23432e+15" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2568 { 1.234321234321234e16, "1.23432e+16" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2569 { 1.234321234321234e17, "1.23432e+17" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2570 { 1.234321234321234e18, "1.23432e+18" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2571 { 1.234321234321234e19, "1.23432e+19" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2572 { 1.234321234321234e20, "1.23432e+20" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2573 { 1.234321234321234e21, "1.23432e+21" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2574 { 1.234321234321234e22, "1.23432e+22" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2575 { 1.234321234321234e23, "1.23432e+23" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2576 { 1.234321234321234e24, "1.23432e+24" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2577 { 1.234321234321234e25, "1.23432e+25" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2578 { 1.234321234321234e26, "1.23432e+26" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2579 { 1.234321234321234e27, "1.23432e+27" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2580 { 1.234321234321234e28, "1.23432e+28" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2581 { 1.234321234321234e29, "1.23432e+29" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2582 { 1.234321234321234e30, "1.23432e+30" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2583 { 1.234321234321234e31, "1.23432e+31" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2584 { 1.234321234321234e32, "1.23432e+32" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2585 { 1.234321234321234e33, "1.23432e+33" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2586 { 1.234321234321234e34, "1.23432e+34" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2587 { 1.234321234321234e35, "1.23432e+35" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2588 { 1.234321234321234e36, "1.23432e+36" }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2589 };
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2590 size_t k;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2591 for (k = 0; k < SIZEOF (data); k++)
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 char *result;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2594 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2595 my_asprintf (&result, "%g", data[k].value);
8839
5efc1d668039 Accomodate for implementations that produce 3 exponent digits in %e and %g.
Bruno Haible <bruno@clisp.org>
parents: 8836
diff changeset
2596 const char *expected = data[k].string;
8836
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2597 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
2598 ASSERT (strcmp (result, expected) == 0
5efc1d668039 Accomodate for implementations that produce 3 exponent digits in %e and %g.
Bruno Haible <bruno@clisp.org>
parents: 8836
diff changeset
2599 /* Some implementations produce exponents with 3 digits. */
5efc1d668039 Accomodate for implementations that produce 3 exponent digits in %e and %g.
Bruno Haible <bruno@clisp.org>
parents: 8836
diff changeset
2600 || (expected[strlen (expected) - 4] == 'e'
5efc1d668039 Accomodate for implementations that produce 3 exponent digits in %e and %g.
Bruno Haible <bruno@clisp.org>
parents: 8836
diff changeset
2601 && strlen (result) == strlen (expected) + 1
5efc1d668039 Accomodate for implementations that produce 3 exponent digits in %e and %g.
Bruno Haible <bruno@clisp.org>
parents: 8836
diff changeset
2602 && memcmp (result, expected, strlen (expected) - 2) == 0
5efc1d668039 Accomodate for implementations that produce 3 exponent digits in %e and %g.
Bruno Haible <bruno@clisp.org>
parents: 8836
diff changeset
2603 && result[strlen (expected) - 2] == '0'
5efc1d668039 Accomodate for implementations that produce 3 exponent digits in %e and %g.
Bruno Haible <bruno@clisp.org>
parents: 8836
diff changeset
2604 && strcmp (result + strlen (expected) - 1,
5efc1d668039 Accomodate for implementations that produce 3 exponent digits in %e and %g.
Bruno Haible <bruno@clisp.org>
parents: 8836
diff changeset
2605 expected + strlen (expected) - 2)
5efc1d668039 Accomodate for implementations that produce 3 exponent digits in %e and %g.
Bruno Haible <bruno@clisp.org>
parents: 8836
diff changeset
2606 == 0));
8836
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2607 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2608 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2609 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2610 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2611
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2612 { /* A negative number. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2613 char *result;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2614 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2615 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
2616 ASSERT (result != NULL);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2617 ASSERT (strcmp (result, "-0.03125 33") == 0);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2618 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2619 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2620 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2621
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2622 { /* Positive zero. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2623 char *result;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2624 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2625 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
2626 ASSERT (result != NULL);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2627 ASSERT (strcmp (result, "0 33") == 0);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2628 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2629 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2630 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2631
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2632 { /* Negative zero. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2633 char *result;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2634 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2635 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
2636 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
2637 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
2638 ASSERT (strcmp (result, "-0 33") == 0);
8836
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2639 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2640 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2641 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2642
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2643 { /* Positive infinity. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2644 char *result;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2645 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2646 my_asprintf (&result, "%g %d", 1.0 / 0.0, 33, 44, 55);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2647 ASSERT (result != NULL);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2648 ASSERT (strcmp (result, "inf 33") == 0
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2649 || strcmp (result, "infinity 33") == 0);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2650 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2651 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2652 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2653
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2654 { /* Negative infinity. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2655 char *result;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2656 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2657 my_asprintf (&result, "%g %d", -1.0 / 0.0, 33, 44, 55);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2658 ASSERT (result != NULL);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2659 ASSERT (strcmp (result, "-inf 33") == 0
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2660 || strcmp (result, "-infinity 33") == 0);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2661 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2662 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2663 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2664
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2665 { /* NaN. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2666 char *result;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2667 int retval =
9854
baba3b346ab2 Use macros NaNf, NaNd, NaNl instead of NAN.
Bruno Haible <bruno@clisp.org>
parents: 9850
diff changeset
2668 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
2669 ASSERT (result != NULL);
8850
d1fe16dfbfee Avoid test failures on IRIX 6.5.
Bruno Haible <bruno@clisp.org>
parents: 8839
diff changeset
2670 ASSERT (strlen (result) >= 3 + 3
8865
9e203d8ade65 Stricter check for printf result for NaN arguments.
Bruno Haible <bruno@clisp.org>
parents: 8857
diff changeset
2671 && strisnan (result, 0, strlen (result) - 3, 0)
8850
d1fe16dfbfee Avoid test failures on IRIX 6.5.
Bruno Haible <bruno@clisp.org>
parents: 8839
diff changeset
2672 && 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
2673 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2674 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2675 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2676
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2677 { /* Width. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2678 char *result;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2679 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2680 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
2681 ASSERT (result != NULL);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2682 ASSERT (strcmp (result, " 1.75 33") == 0);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2683 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2684 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2685 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2686
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2687 { /* FLAG_LEFT. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2688 char *result;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2689 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2690 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
2691 ASSERT (result != NULL);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2692 ASSERT (strcmp (result, "1.75 33") == 0);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2693 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2694 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2695 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2696
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2697 { /* FLAG_SHOWSIGN. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2698 char *result;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2699 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2700 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
2701 ASSERT (result != NULL);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2702 ASSERT (strcmp (result, "+1.75 33") == 0);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2703 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2704 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2705 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2706
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2707 { /* FLAG_SPACE. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2708 char *result;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2709 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2710 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
2711 ASSERT (result != NULL);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2712 ASSERT (strcmp (result, " 1.75 33") == 0);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2713 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2714 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2715 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2716
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2717 { /* FLAG_ALT. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2718 char *result;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2719 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2720 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
2721 ASSERT (result != NULL);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2722 ASSERT (strcmp (result, "1.75000 33") == 0);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2723 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2724 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2725 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2726
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2727 { /* FLAG_ALT. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2728 char *result;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2729 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2730 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
2731 ASSERT (result != NULL);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2732 ASSERT (strcmp (result, "2. 33") == 0);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2733 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2734 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2735 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2736
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2737 { /* FLAG_ALT. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2738 char *result;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2739 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2740 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
2741 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
2742 ASSERT (strcmp (result, "1.e+01 33") == 0
5efc1d668039 Accomodate for implementations that produce 3 exponent digits in %e and %g.
Bruno Haible <bruno@clisp.org>
parents: 8836
diff changeset
2743 || 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
2744 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2745 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2746 }
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 { /* FLAG_ZERO with finite number. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2749 char *result;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2750 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2751 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
2752 ASSERT (result != NULL);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2753 ASSERT (strcmp (result, "0000001234 33") == 0);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2754 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2755 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2756 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2757
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2758 { /* FLAG_ZERO with infinite number. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2759 char *result;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2760 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2761 my_asprintf (&result, "%015g %d", -1.0 / 0.0, 33, 44, 55);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2762 ASSERT (result != NULL);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2763 ASSERT (strcmp (result, " -inf 33") == 0
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2764 || strcmp (result, " -infinity 33") == 0);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2765 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2766 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2767 }
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 { /* FLAG_ZERO with NaN. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2770 char *result;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2771 int retval =
9854
baba3b346ab2 Use macros NaNf, NaNd, NaNl instead of NAN.
Bruno Haible <bruno@clisp.org>
parents: 9850
diff changeset
2772 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
2773 ASSERT (result != NULL);
8870
4e1f2ea486b4 Allow for a longer printed representation of NaN.
Bruno Haible <bruno@clisp.org>
parents: 8865
diff changeset
2774 ASSERT (strlen (result) == 50 + 3
8865
9e203d8ade65 Stricter check for printf result for NaN arguments.
Bruno Haible <bruno@clisp.org>
parents: 8857
diff changeset
2775 && strisnan (result, strspn (result, " "), strlen (result) - 3, 0)
8850
d1fe16dfbfee Avoid test failures on IRIX 6.5.
Bruno Haible <bruno@clisp.org>
parents: 8839
diff changeset
2776 && 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
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 { /* Precision. */
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 =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2784 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
2785 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
2786 ASSERT (strcmp (result, "1e+03 33") == 0
5efc1d668039 Accomodate for implementations that produce 3 exponent digits in %e and %g.
Bruno Haible <bruno@clisp.org>
parents: 8836
diff changeset
2787 || strcmp (result, "1e+003 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 { /* A positive number. */
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 =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2795 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
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, "12.75 33") == 0);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2798 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2799 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2800 }
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 { /* A larger positive number. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2803 char *result;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2804 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2805 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
2806 ASSERT (result != NULL);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2807 ASSERT (strcmp (result, "1.23457e+06 33") == 0);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2808 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2809 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2810 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2811
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2812 { /* Small and large positive numbers. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2813 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
2814 {
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2815 { 1.234321234321234e-37L, "1.23432e-37" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2816 { 1.234321234321234e-36L, "1.23432e-36" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2817 { 1.234321234321234e-35L, "1.23432e-35" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2818 { 1.234321234321234e-34L, "1.23432e-34" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2819 { 1.234321234321234e-33L, "1.23432e-33" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2820 { 1.234321234321234e-32L, "1.23432e-32" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2821 { 1.234321234321234e-31L, "1.23432e-31" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2822 { 1.234321234321234e-30L, "1.23432e-30" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2823 { 1.234321234321234e-29L, "1.23432e-29" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2824 { 1.234321234321234e-28L, "1.23432e-28" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2825 { 1.234321234321234e-27L, "1.23432e-27" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2826 { 1.234321234321234e-26L, "1.23432e-26" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2827 { 1.234321234321234e-25L, "1.23432e-25" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2828 { 1.234321234321234e-24L, "1.23432e-24" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2829 { 1.234321234321234e-23L, "1.23432e-23" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2830 { 1.234321234321234e-22L, "1.23432e-22" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2831 { 1.234321234321234e-21L, "1.23432e-21" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2832 { 1.234321234321234e-20L, "1.23432e-20" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2833 { 1.234321234321234e-19L, "1.23432e-19" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2834 { 1.234321234321234e-18L, "1.23432e-18" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2835 { 1.234321234321234e-17L, "1.23432e-17" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2836 { 1.234321234321234e-16L, "1.23432e-16" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2837 { 1.234321234321234e-15L, "1.23432e-15" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2838 { 1.234321234321234e-14L, "1.23432e-14" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2839 { 1.234321234321234e-13L, "1.23432e-13" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2840 { 1.234321234321234e-12L, "1.23432e-12" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2841 { 1.234321234321234e-11L, "1.23432e-11" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2842 { 1.234321234321234e-10L, "1.23432e-10" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2843 { 1.234321234321234e-9L, "1.23432e-09" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2844 { 1.234321234321234e-8L, "1.23432e-08" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2845 { 1.234321234321234e-7L, "1.23432e-07" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2846 { 1.234321234321234e-6L, "1.23432e-06" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2847 { 1.234321234321234e-5L, "1.23432e-05" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2848 { 1.234321234321234e-4L, "0.000123432" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2849 { 1.234321234321234e-3L, "0.00123432" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2850 { 1.234321234321234e-2L, "0.0123432" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2851 { 1.234321234321234e-1L, "0.123432" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2852 { 1.234321234321234L, "1.23432" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2853 { 1.234321234321234e1L, "12.3432" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2854 { 1.234321234321234e2L, "123.432" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2855 { 1.234321234321234e3L, "1234.32" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2856 { 1.234321234321234e4L, "12343.2" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2857 { 1.234321234321234e5L, "123432" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2858 { 1.234321234321234e6L, "1.23432e+06" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2859 { 1.234321234321234e7L, "1.23432e+07" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2860 { 1.234321234321234e8L, "1.23432e+08" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2861 { 1.234321234321234e9L, "1.23432e+09" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2862 { 1.234321234321234e10L, "1.23432e+10" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2863 { 1.234321234321234e11L, "1.23432e+11" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2864 { 1.234321234321234e12L, "1.23432e+12" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2865 { 1.234321234321234e13L, "1.23432e+13" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2866 { 1.234321234321234e14L, "1.23432e+14" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2867 { 1.234321234321234e15L, "1.23432e+15" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2868 { 1.234321234321234e16L, "1.23432e+16" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2869 { 1.234321234321234e17L, "1.23432e+17" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2870 { 1.234321234321234e18L, "1.23432e+18" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2871 { 1.234321234321234e19L, "1.23432e+19" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2872 { 1.234321234321234e20L, "1.23432e+20" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2873 { 1.234321234321234e21L, "1.23432e+21" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2874 { 1.234321234321234e22L, "1.23432e+22" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2875 { 1.234321234321234e23L, "1.23432e+23" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2876 { 1.234321234321234e24L, "1.23432e+24" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2877 { 1.234321234321234e25L, "1.23432e+25" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2878 { 1.234321234321234e26L, "1.23432e+26" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2879 { 1.234321234321234e27L, "1.23432e+27" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2880 { 1.234321234321234e28L, "1.23432e+28" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2881 { 1.234321234321234e29L, "1.23432e+29" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2882 { 1.234321234321234e30L, "1.23432e+30" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2883 { 1.234321234321234e31L, "1.23432e+31" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2884 { 1.234321234321234e32L, "1.23432e+32" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2885 { 1.234321234321234e33L, "1.23432e+33" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2886 { 1.234321234321234e34L, "1.23432e+34" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2887 { 1.234321234321234e35L, "1.23432e+35" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2888 { 1.234321234321234e36L, "1.23432e+36" }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2889 };
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2890 size_t k;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2891 for (k = 0; k < SIZEOF (data); k++)
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2892 {
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2893 char *result;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2894 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2895 my_asprintf (&result, "%Lg", data[k].value);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2896 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
2897 ASSERT (strcmp (result, data[k].string) == 0);
8836
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2898 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2899 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2900 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2901 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2902
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2903 { /* A negative number. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2904 char *result;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2905 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2906 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
2907 ASSERT (result != NULL);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2908 ASSERT (strcmp (result, "-0.03125 33") == 0);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2909 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2910 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2911 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2912
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2913 { /* Positive zero. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2914 char *result;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2915 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2916 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
2917 ASSERT (result != NULL);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2918 ASSERT (strcmp (result, "0 33") == 0);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2919 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2920 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2921 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2922
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2923 { /* Negative zero. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2924 char *result;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2925 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2926 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
2927 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
2928 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
2929 ASSERT (strcmp (result, "-0 33") == 0);
8836
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2930 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2931 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2932 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2933
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2934 { /* Positive infinity. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2935 char *result;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2936 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2937 my_asprintf (&result, "%Lg %d", 1.0L / 0.0L, 33, 44, 55);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2938 ASSERT (result != NULL);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2939 ASSERT (strcmp (result, "inf 33") == 0
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2940 || strcmp (result, "infinity 33") == 0);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2941 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2942 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2943 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2944
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2945 { /* Negative infinity. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2946 char *result;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2947 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2948 my_asprintf (&result, "%Lg %d", -1.0L / 0.0L, 33, 44, 55);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2949 ASSERT (result != NULL);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2950 ASSERT (strcmp (result, "-inf 33") == 0
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2951 || strcmp (result, "-infinity 33") == 0);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2952 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2953 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2954 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2955
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2956 { /* NaN. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2957 char *result;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2958 int retval =
9854
baba3b346ab2 Use macros NaNf, NaNd, NaNl instead of NAN.
Bruno Haible <bruno@clisp.org>
parents: 9850
diff changeset
2959 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
2960 ASSERT (result != NULL);
8850
d1fe16dfbfee Avoid test failures on IRIX 6.5.
Bruno Haible <bruno@clisp.org>
parents: 8839
diff changeset
2961 ASSERT (strlen (result) >= 3 + 3
8865
9e203d8ade65 Stricter check for printf result for NaN arguments.
Bruno Haible <bruno@clisp.org>
parents: 8857
diff changeset
2962 && strisnan (result, 0, strlen (result) - 3, 0)
8850
d1fe16dfbfee Avoid test failures on IRIX 6.5.
Bruno Haible <bruno@clisp.org>
parents: 8839
diff changeset
2963 && 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
2964 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2965 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2966 }
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
2967 #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_))
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2968 { /* 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
2969 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
2970 { 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
2971 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
2972 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
2973 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
2974 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
2975 ASSERT (strlen (result) >= 3 + 3
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2976 && strisnan (result, 0, strlen (result) - 3, 0)
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2977 && strcmp (result + strlen (result) - 3, " 33") == 0);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2978 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
2979 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
2980 }
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2981 {
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2982 /* 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
2983 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
2984 { 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
2985 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
2986 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
2987 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
2988 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
2989 ASSERT (strlen (result) >= 3 + 3
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2990 && strisnan (result, 0, strlen (result) - 3, 0)
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2991 && strcmp (result + strlen (result) - 3, " 33") == 0);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2992 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
2993 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
2994 }
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2995 /* 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
2996 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
2997 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
2998 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
2999 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
3000 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
3001 */
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3002 { /* 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
3003 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
3004 { 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
3005 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
3006 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
3007 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
3008 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
3009 ASSERT (strlen (result) >= 3 + 3
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3010 && strisnan (result, 0, strlen (result) - 3, 0)
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3011 && strcmp (result + strlen (result) - 3, " 33") == 0);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3012 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
3013 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
3014 }
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3015 { /* 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
3016 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
3017 { 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
3018 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
3019 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
3020 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
3021 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
3022 ASSERT (strlen (result) >= 3 + 3
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3023 && strisnan (result, 0, strlen (result) - 3, 0)
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3024 && strcmp (result + strlen (result) - 3, " 33") == 0);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3025 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
3026 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
3027 }
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3028 { /* 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
3029 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
3030 { 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
3031 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
3032 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
3033 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
3034 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
3035 ASSERT (strlen (result) >= 3 + 3
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3036 && strisnan (result, 0, strlen (result) - 3, 0)
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3037 && strcmp (result + strlen (result) - 3, " 33") == 0);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3038 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
3039 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
3040 }
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3041 { /* 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
3042 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
3043 { 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
3044 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
3045 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
3046 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
3047 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
3048 ASSERT (strlen (result) >= 3 + 3
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3049 && strisnan (result, 0, strlen (result) - 3, 0)
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3050 && strcmp (result + strlen (result) - 3, " 33") == 0);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3051 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
3052 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
3053 }
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3054 { /* 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
3055 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
3056 { 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
3057 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
3058 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
3059 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
3060 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
3061 ASSERT (strlen (result) >= 3 + 3
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3062 && strisnan (result, 0, strlen (result) - 3, 0)
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3063 && strcmp (result + strlen (result) - 3, " 33") == 0);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3064 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
3065 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
3066 }
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3067 #endif
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 { /* Width. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3070 char *result;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3071 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3072 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
3073 ASSERT (result != NULL);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3074 ASSERT (strcmp (result, " 1.75 33") == 0);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3075 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3076 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3077 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3078
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3079 { /* FLAG_LEFT. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3080 char *result;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3081 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3082 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
3083 ASSERT (result != NULL);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3084 ASSERT (strcmp (result, "1.75 33") == 0);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3085 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3086 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3087 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3088
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3089 { /* FLAG_SHOWSIGN. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3090 char *result;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3091 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3092 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
3093 ASSERT (result != NULL);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3094 ASSERT (strcmp (result, "+1.75 33") == 0);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3095 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3096 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3097 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3098
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3099 { /* FLAG_SPACE. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3100 char *result;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3101 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3102 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
3103 ASSERT (result != NULL);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3104 ASSERT (strcmp (result, " 1.75 33") == 0);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3105 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3106 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3107 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3108
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3109 { /* FLAG_ALT. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3110 char *result;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3111 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3112 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
3113 ASSERT (result != NULL);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3114 ASSERT (strcmp (result, "1.75000 33") == 0);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3115 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3116 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3117 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3118
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3119 { /* FLAG_ALT. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3120 char *result;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3121 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3122 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
3123 ASSERT (result != NULL);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3124 ASSERT (strcmp (result, "2. 33") == 0);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3125 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3126 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3127 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3128
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3129 { /* FLAG_ALT. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3130 char *result;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3131 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3132 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
3133 ASSERT (result != NULL);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3134 ASSERT (strcmp (result, "1.e+01 33") == 0);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3135 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3136 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3137 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3138
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3139 { /* FLAG_ZERO with finite number. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3140 char *result;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3141 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3142 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
3143 ASSERT (result != NULL);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3144 ASSERT (strcmp (result, "0000001234 33") == 0);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3145 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3146 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3147 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3148
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3149 { /* FLAG_ZERO with infinite number. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3150 char *result;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3151 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3152 my_asprintf (&result, "%015Lg %d", -1.0L / 0.0L, 33, 44, 55);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3153 ASSERT (result != NULL);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3154 ASSERT (strcmp (result, " -inf 33") == 0
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3155 || strcmp (result, " -infinity 33") == 0);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3156 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3157 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3158 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3159
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3160 { /* FLAG_ZERO with NaN. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3161 char *result;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3162 int retval =
9854
baba3b346ab2 Use macros NaNf, NaNd, NaNl instead of NAN.
Bruno Haible <bruno@clisp.org>
parents: 9850
diff changeset
3163 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
3164 ASSERT (result != NULL);
8870
4e1f2ea486b4 Allow for a longer printed representation of NaN.
Bruno Haible <bruno@clisp.org>
parents: 8865
diff changeset
3165 ASSERT (strlen (result) == 50 + 3
8865
9e203d8ade65 Stricter check for printf result for NaN arguments.
Bruno Haible <bruno@clisp.org>
parents: 8857
diff changeset
3166 && strisnan (result, strspn (result, " "), strlen (result) - 3, 0)
8850
d1fe16dfbfee Avoid test failures on IRIX 6.5.
Bruno Haible <bruno@clisp.org>
parents: 8839
diff changeset
3167 && 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
3168 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3169 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3170 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3171
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3172 { /* Precision. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3173 char *result;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3174 int retval =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3175 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
3176 ASSERT (result != NULL);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3177 ASSERT (strcmp (result, "1e+03 33") == 0);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3178 ASSERT (retval == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3179 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3180 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3181
8342
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3182 /* Test the support of the %n format directive. */
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3183
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3184 {
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3185 int count = -1;
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3186 char *result;
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3187 int retval =
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3188 my_asprintf (&result, "%d %n", 123, &count, 33, 44, 55);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3189 ASSERT (result != NULL);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3190 ASSERT (strcmp (result, "123 ") == 0);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3191 ASSERT (retval == strlen (result));
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3192 ASSERT (count == 4);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3193 free (result);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3194 }
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3195
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3196 /* 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
3197
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3198 {
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3199 char *result;
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3200 int retval =
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3201 my_asprintf (&result, "%2$d %1$d", 33, 55);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3202 ASSERT (result != NULL);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3203 ASSERT (strcmp (result, "55 33") == 0);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3204 ASSERT (retval == strlen (result));
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3205 free (result);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3206 }
8803
6c1d98929550 Work around lack of support of grouping flag.
Bruno Haible <bruno@clisp.org>
parents: 8754
diff changeset
3207
6c1d98929550 Work around lack of support of grouping flag.
Bruno Haible <bruno@clisp.org>
parents: 8754
diff changeset
3208 /* 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
3209
6c1d98929550 Work around lack of support of grouping flag.
Bruno Haible <bruno@clisp.org>
parents: 8754
diff changeset
3210 {
6c1d98929550 Work around lack of support of grouping flag.
Bruno Haible <bruno@clisp.org>
parents: 8754
diff changeset
3211 char *result;
6c1d98929550 Work around lack of support of grouping flag.
Bruno Haible <bruno@clisp.org>
parents: 8754
diff changeset
3212 int retval =
6c1d98929550 Work around lack of support of grouping flag.
Bruno Haible <bruno@clisp.org>
parents: 8754
diff changeset
3213 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
3214 ASSERT (result != NULL);
6c1d98929550 Work around lack of support of grouping flag.
Bruno Haible <bruno@clisp.org>
parents: 8754
diff changeset
3215 ASSERT (result[strlen (result) - 1] == '9');
6c1d98929550 Work around lack of support of grouping flag.
Bruno Haible <bruno@clisp.org>
parents: 8754
diff changeset
3216 ASSERT (retval == strlen (result));
6c1d98929550 Work around lack of support of grouping flag.
Bruno Haible <bruno@clisp.org>
parents: 8754
diff changeset
3217 free (result);
6c1d98929550 Work around lack of support of grouping flag.
Bruno Haible <bruno@clisp.org>
parents: 8754
diff changeset
3218 }
9447
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3219
9674
b69f1141e94f Fix *printf behaviour regarding the left-adjust flag on HP-UX 10.20.
Bruno Haible <bruno@clisp.org>
parents: 9447
diff changeset
3220 /* 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
3221
b69f1141e94f Fix *printf behaviour regarding the left-adjust flag on HP-UX 10.20.
Bruno Haible <bruno@clisp.org>
parents: 9447
diff changeset
3222 {
b69f1141e94f Fix *printf behaviour regarding the left-adjust flag on HP-UX 10.20.
Bruno Haible <bruno@clisp.org>
parents: 9447
diff changeset
3223 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
3224 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
3225 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
3226 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
3227 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
3228 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
3229 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
3230 }
b69f1141e94f Fix *printf behaviour regarding the left-adjust flag on HP-UX 10.20.
Bruno Haible <bruno@clisp.org>
parents: 9447
diff changeset
3231
b69f1141e94f Fix *printf behaviour regarding the left-adjust flag on HP-UX 10.20.
Bruno Haible <bruno@clisp.org>
parents: 9447
diff changeset
3232 {
b69f1141e94f Fix *printf behaviour regarding the left-adjust flag on HP-UX 10.20.
Bruno Haible <bruno@clisp.org>
parents: 9447
diff changeset
3233 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
3234 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
3235 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
3236 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
3237 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
3238 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
3239 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
3240 }
b69f1141e94f Fix *printf behaviour regarding the left-adjust flag on HP-UX 10.20.
Bruno Haible <bruno@clisp.org>
parents: 9447
diff changeset
3241
b69f1141e94f Fix *printf behaviour regarding the left-adjust flag on HP-UX 10.20.
Bruno Haible <bruno@clisp.org>
parents: 9447
diff changeset
3242 {
b69f1141e94f Fix *printf behaviour regarding the left-adjust flag on HP-UX 10.20.
Bruno Haible <bruno@clisp.org>
parents: 9447
diff changeset
3243 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
3244 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
3245 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
3246 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
3247 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
3248 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
3249 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
3250 }
b69f1141e94f Fix *printf behaviour regarding the left-adjust flag on HP-UX 10.20.
Bruno Haible <bruno@clisp.org>
parents: 9447
diff changeset
3251
9447
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3252 /* Test the support of large precision. */
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3253
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3254 {
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3255 char *result;
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3256 int retval =
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3257 my_asprintf (&result, "%.4000d %d", 1234567, 99);
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3258 size_t i;
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3259 ASSERT (result != NULL);
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3260 for (i = 0; i < 4000 - 7; i++)
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3261 ASSERT (result[i] == '0');
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3262 ASSERT (strcmp (result + 4000 - 7, "1234567 99") == 0);
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3263 ASSERT (retval == strlen (result));
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3264 free (result);
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3265 }
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3266
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3267 {
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3268 char *result;
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3269 int retval =
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3270 my_asprintf (&result, "%.4000d %d", -1234567, 99);
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3271 size_t i;
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3272 ASSERT (result != NULL);
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3273 ASSERT (result[0] == '-');
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3274 for (i = 0; i < 4000 - 7; i++)
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3275 ASSERT (result[1 + i] == '0');
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3276 ASSERT (strcmp (result + 1 + 4000 - 7, "1234567 99") == 0);
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3277 ASSERT (retval == strlen (result));
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3278 free (result);
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3279 }
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3280
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3281 {
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3282 char *result;
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3283 int retval =
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3284 my_asprintf (&result, "%.4000u %d", 1234567, 99);
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3285 size_t i;
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3286 ASSERT (result != NULL);
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3287 for (i = 0; i < 4000 - 7; i++)
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3288 ASSERT (result[i] == '0');
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3289 ASSERT (strcmp (result + 4000 - 7, "1234567 99") == 0);
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3290 ASSERT (retval == strlen (result));
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3291 free (result);
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3292 }
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3293
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3294 {
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3295 char *result;
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3296 int retval =
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3297 my_asprintf (&result, "%.4000o %d", 1234567, 99);
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3298 size_t i;
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3299 ASSERT (result != NULL);
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3300 for (i = 0; i < 4000 - 7; i++)
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3301 ASSERT (result[i] == '0');
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3302 ASSERT (strcmp (result + 4000 - 7, "4553207 99") == 0);
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3303 ASSERT (retval == strlen (result));
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3304 free (result);
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3305 }
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3306
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3307 {
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3308 char *result;
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3309 int retval =
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3310 my_asprintf (&result, "%.4000x %d", 1234567, 99);
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3311 size_t i;
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3312 ASSERT (result != NULL);
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3313 for (i = 0; i < 4000 - 6; i++)
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3314 ASSERT (result[i] == '0');
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3315 ASSERT (strcmp (result + 4000 - 6, "12d687 99") == 0);
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3316 ASSERT (retval == strlen (result));
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3317 free (result);
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3318 }
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3319
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3320 {
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3321 char *result;
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3322 int retval =
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3323 my_asprintf (&result, "%#.4000x %d", 1234567, 99);
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3324 size_t i;
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3325 ASSERT (result != NULL);
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3326 ASSERT (result[0] == '0');
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3327 ASSERT (result[1] == 'x');
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3328 for (i = 0; i < 4000 - 6; i++)
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3329 ASSERT (result[2 + i] == '0');
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3330 ASSERT (strcmp (result + 2 + 4000 - 6, "12d687 99") == 0);
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3331 ASSERT (retval == strlen (result));
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3332 free (result);
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3333 }
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3334
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3335 {
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3336 char input[5000];
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3337 char *result;
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3338 int retval;
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3339 size_t i;
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3340
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3341 for (i = 0; i < sizeof (input) - 1; i++)
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3342 input[i] = 'a' + ((1000000 / (i + 1)) % 26);
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3343 input[i] = '\0';
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3344 retval = my_asprintf (&result, "%.4000s %d", input, 99);
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3345 ASSERT (result != NULL);
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3346 ASSERT (memcmp (result, input, 4000) == 0);
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3347 ASSERT (strcmp (result + 4000, " 99") == 0);
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3348 ASSERT (retval == strlen (result));
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3349 free (result);
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3350 }
8342
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3351 }
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3352
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3353 static int
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3354 my_asprintf (char **result, const char *format, ...)
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3355 {
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3356 va_list args;
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3357 int ret;
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3358
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3359 va_start (args, format);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3360 ret = vasprintf (result, format, args);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3361 va_end (args);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3362 return ret;
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3363 }
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3364
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3365 static void
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3366 test_vasprintf ()
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3367 {
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3368 test_function (my_asprintf);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3369 }
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3370
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3371 static void
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3372 test_asprintf ()
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 test_function (asprintf);
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3375 }
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3376
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3377 int
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3378 main (int argc, char *argv[])
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3379 {
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3380 test_vasprintf ();
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3381 test_asprintf ();
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3382 return 0;
504f056f113a Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3383 }