annotate tests/test-vasprintf-posix.c @ 8857:61fd30fa9b3f

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