annotate tests/test-vasnprintf-posix.c @ 9938:9f8c455639fc

Fix rounding when a precision is given.
author Bruno Haible <bruno@clisp.org>
date Sat, 19 Apr 2008 17:26:36 +0200
parents 0be6f1ab456d
children 06a4179ed804
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8336
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1 /* Test of POSIX compatible vasnprintf() and asnprintf() functions.
9674
b69f1141e94f Fix *printf behaviour regarding the left-adjust flag on HP-UX 10.20.
Bruno Haible <bruno@clisp.org>
parents: 9447
diff changeset
2 Copyright (C) 2007-2008 Free Software Foundation, Inc.
8336
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3
9309
bbbbbf4cd1c5 Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 8919
diff changeset
4 This program is free software: you can redistribute it and/or modify
8336
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
5 it under the terms of the GNU General Public License as published by
9309
bbbbbf4cd1c5 Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 8919
diff changeset
6 the Free Software Foundation; either version 3 of the License, or
bbbbbf4cd1c5 Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 8919
diff changeset
7 (at your option) any later version.
8336
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
8
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
9 This program is distributed in the hope that it will be useful,
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
12 GNU General Public License for more details.
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
13
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
14 You should have received a copy of the GNU General Public License
9309
bbbbbf4cd1c5 Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 8919
diff changeset
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
8336
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
16
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
17 /* Written by Bruno Haible <bruno@clisp.org>, 2007. */
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
18
8891
633babea5f62 Unconditionally include <config.h> in unit tests.
Eric Blake <ebb9@byu.net>
parents: 8870
diff changeset
19 #include <config.h>
8336
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
20
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
21 #include "vasnprintf.h"
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
22
8919
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
23 #include <float.h>
8336
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
24 #include <stdarg.h>
8354
81b3f885ff9d Include <stddef.h>, for ptrdiff_t.
Bruno Haible <bruno@clisp.org>
parents: 8344
diff changeset
25 #include <stddef.h>
8754
1f57552cdb11 Better ASSERT macro.
Bruno Haible <bruno@clisp.org>
parents: 8684
diff changeset
26 #include <stdio.h>
8336
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
27 #include <stdint.h>
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
28 #include <stdlib.h>
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
29 #include <string.h>
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
30
9854
baba3b346ab2 Use macros NaNf, NaNd, NaNl instead of NAN.
Bruno Haible <bruno@clisp.org>
parents: 9850
diff changeset
31 #include "nan.h"
baba3b346ab2 Use macros NaNf, NaNd, NaNl instead of NAN.
Bruno Haible <bruno@clisp.org>
parents: 9850
diff changeset
32
8834
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
33 #define SIZEOF(array) (sizeof (array) / sizeof (array[0]))
8754
1f57552cdb11 Better ASSERT macro.
Bruno Haible <bruno@clisp.org>
parents: 8684
diff changeset
34 #define ASSERT(expr) \
1f57552cdb11 Better ASSERT macro.
Bruno Haible <bruno@clisp.org>
parents: 8684
diff changeset
35 do \
1f57552cdb11 Better ASSERT macro.
Bruno Haible <bruno@clisp.org>
parents: 8684
diff changeset
36 { \
1f57552cdb11 Better ASSERT macro.
Bruno Haible <bruno@clisp.org>
parents: 8684
diff changeset
37 if (!(expr)) \
1f57552cdb11 Better ASSERT macro.
Bruno Haible <bruno@clisp.org>
parents: 8684
diff changeset
38 { \
1f57552cdb11 Better ASSERT macro.
Bruno Haible <bruno@clisp.org>
parents: 8684
diff changeset
39 fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \
9889
0be6f1ab456d Flush the standard error stream before aborting.
Bruno Haible <bruno@clisp.org>
parents: 9854
diff changeset
40 fflush (stderr); \
8754
1f57552cdb11 Better ASSERT macro.
Bruno Haible <bruno@clisp.org>
parents: 8684
diff changeset
41 abort (); \
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 } \
1f57552cdb11 Better ASSERT macro.
Bruno Haible <bruno@clisp.org>
parents: 8684
diff changeset
44 while (0)
8336
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
45
8852
df0b5e8ea770 Avoid test failures on platforms where -0.0 and 0.0 are identical.
Bruno Haible <bruno@clisp.org>
parents: 8850
diff changeset
46 /* 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
47 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
48 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
49 {
df0b5e8ea770 Avoid test failures on platforms where -0.0 and 0.0 are identical.
Bruno Haible <bruno@clisp.org>
parents: 8850
diff changeset
50 static double 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
51 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
52 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
53 }
df0b5e8ea770 Avoid test failures on platforms where -0.0 and 0.0 are identical.
Bruno Haible <bruno@clisp.org>
parents: 8850
diff changeset
54
8919
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
55 /* Representation of an 80-bit 'long double' as an initializer for a sequence
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
56 of 'unsigned int' words. */
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
57 #ifdef WORDS_BIGENDIAN
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
58 # define LDBL80_WORDS(exponent,manthi,mantlo) \
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
59 { ((unsigned int) (exponent) << 16) | ((unsigned int) (manthi) >> 16), \
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
60 ((unsigned int) (manthi) << 16) | (unsigned int) (mantlo) >> 16), \
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
61 (unsigned int) (mantlo) << 16 \
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
62 }
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
63 #else
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
64 # define LDBL80_WORDS(exponent,manthi,mantlo) \
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
65 { mantlo, manthi, exponent }
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
66 #endif
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
67
8834
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
68 static int
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
69 strmatch (const char *pattern, const char *string)
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
70 {
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
71 if (strlen (pattern) != strlen (string))
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
72 return 0;
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
73 for (; *pattern != '\0'; pattern++, string++)
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
74 if (*pattern != '*' && *string != *pattern)
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
75 return 0;
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
76 return 1;
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
77 }
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
78
8865
9e203d8ade65 Stricter check for printf result for NaN arguments.
Bruno Haible <bruno@clisp.org>
parents: 8857
diff changeset
79 /* Test whether string[start_index..end_index-1] is a valid textual
9e203d8ade65 Stricter check for printf result for NaN arguments.
Bruno Haible <bruno@clisp.org>
parents: 8857
diff changeset
80 representation of NaN. */
9e203d8ade65 Stricter check for printf result for NaN arguments.
Bruno Haible <bruno@clisp.org>
parents: 8857
diff changeset
81 static int
9e203d8ade65 Stricter check for printf result for NaN arguments.
Bruno Haible <bruno@clisp.org>
parents: 8857
diff changeset
82 strisnan (const char *string, size_t start_index, size_t end_index, int uppercase)
9e203d8ade65 Stricter check for printf result for NaN arguments.
Bruno Haible <bruno@clisp.org>
parents: 8857
diff changeset
83 {
9e203d8ade65 Stricter check for printf result for NaN arguments.
Bruno Haible <bruno@clisp.org>
parents: 8857
diff changeset
84 if (start_index < end_index)
9e203d8ade65 Stricter check for printf result for NaN arguments.
Bruno Haible <bruno@clisp.org>
parents: 8857
diff changeset
85 {
9e203d8ade65 Stricter check for printf result for NaN arguments.
Bruno Haible <bruno@clisp.org>
parents: 8857
diff changeset
86 if (string[start_index] == '-')
9e203d8ade65 Stricter check for printf result for NaN arguments.
Bruno Haible <bruno@clisp.org>
parents: 8857
diff changeset
87 start_index++;
9e203d8ade65 Stricter check for printf result for NaN arguments.
Bruno Haible <bruno@clisp.org>
parents: 8857
diff changeset
88 if (start_index + 3 <= end_index
9e203d8ade65 Stricter check for printf result for NaN arguments.
Bruno Haible <bruno@clisp.org>
parents: 8857
diff changeset
89 && memcmp (string + start_index, uppercase ? "NAN" : "nan", 3) == 0)
9e203d8ade65 Stricter check for printf result for NaN arguments.
Bruno Haible <bruno@clisp.org>
parents: 8857
diff changeset
90 {
9e203d8ade65 Stricter check for printf result for NaN arguments.
Bruno Haible <bruno@clisp.org>
parents: 8857
diff changeset
91 start_index += 3;
9e203d8ade65 Stricter check for printf result for NaN arguments.
Bruno Haible <bruno@clisp.org>
parents: 8857
diff changeset
92 if (start_index == end_index
9e203d8ade65 Stricter check for printf result for NaN arguments.
Bruno Haible <bruno@clisp.org>
parents: 8857
diff changeset
93 || (string[start_index] == '(' && string[end_index - 1] == ')'))
9e203d8ade65 Stricter check for printf result for NaN arguments.
Bruno Haible <bruno@clisp.org>
parents: 8857
diff changeset
94 return 1;
9e203d8ade65 Stricter check for printf result for NaN arguments.
Bruno Haible <bruno@clisp.org>
parents: 8857
diff changeset
95 }
9e203d8ade65 Stricter check for printf result for NaN arguments.
Bruno Haible <bruno@clisp.org>
parents: 8857
diff changeset
96 }
9e203d8ade65 Stricter check for printf result for NaN arguments.
Bruno Haible <bruno@clisp.org>
parents: 8857
diff changeset
97 return 0;
9e203d8ade65 Stricter check for printf result for NaN arguments.
Bruno Haible <bruno@clisp.org>
parents: 8857
diff changeset
98 }
9850
7f3ed6b093be Guarantee a definition of NAN.
Eric Blake <ebb9@byu.net>
parents: 9674
diff changeset
99
8336
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
100 static void
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
101 test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...))
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
102 {
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
103 char buf[8];
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
104 int size;
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
105
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
106 /* Test return value convention. */
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
107
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
108 for (size = 0; size <= 8; size++)
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
109 {
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
110 size_t length = size;
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
111 char *result = my_asnprintf (NULL, &length, "%d", 12345);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
112 ASSERT (result != NULL);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
113 ASSERT (strcmp (result, "12345") == 0);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
114 ASSERT (length == 5);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
115 free (result);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
116 }
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
117
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
118 for (size = 0; size <= 8; size++)
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
119 {
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
120 size_t length;
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
121 char *result;
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
122
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
123 memcpy (buf, "DEADBEEF", 8);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
124 length = size;
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
125 result = my_asnprintf (buf, &length, "%d", 12345);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
126 ASSERT (result != NULL);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
127 ASSERT (strcmp (result, "12345") == 0);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
128 ASSERT (length == 5);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
129 if (size < 6)
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
130 ASSERT (result != buf);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
131 ASSERT (memcmp (buf + size, "DEADBEEF" + size, 8 - size) == 0);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
132 if (result != buf)
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
133 free (result);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
134 }
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
135
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
136 /* Test support of size specifiers as in C99. */
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
137
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
138 {
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
139 size_t length;
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
140 char *result =
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
141 my_asnprintf (NULL, &length, "%ju %d", (uintmax_t) 12345671, 33, 44, 55);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
142 ASSERT (result != NULL);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
143 ASSERT (strcmp (result, "12345671 33") == 0);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
144 ASSERT (length == strlen (result));
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
145 free (result);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
146 }
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
147
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
148 {
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
149 size_t length;
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
150 char *result =
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
151 my_asnprintf (NULL, &length, "%zu %d", (size_t) 12345672, 33, 44, 55);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
152 ASSERT (result != NULL);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
153 ASSERT (strcmp (result, "12345672 33") == 0);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
154 ASSERT (length == strlen (result));
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
155 free (result);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
156 }
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
157
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
158 {
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
159 size_t length;
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
160 char *result =
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
161 my_asnprintf (NULL, &length, "%tu %d", (ptrdiff_t) 12345673, 33, 44, 55);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
162 ASSERT (result != NULL);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
163 ASSERT (strcmp (result, "12345673 33") == 0);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
164 ASSERT (length == strlen (result));
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
165 free (result);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
166 }
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
167
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
168 {
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
169 size_t length;
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
170 char *result =
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
171 my_asnprintf (NULL, &length, "%Lg %d", (long double) 1.5, 33, 44, 55);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
172 ASSERT (result != NULL);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
173 ASSERT (strcmp (result, "1.5 33") == 0);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
174 ASSERT (length == strlen (result));
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
175 free (result);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
176 }
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
177
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
178 /* Test the support of the 'a' and 'A' conversion specifier for hexadecimal
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
179 output of floating-point numbers. */
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
180
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
181 { /* A positive number. */
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
182 size_t length;
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
183 char *result =
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
184 my_asnprintf (NULL, &length, "%a %d", 3.1416015625, 33, 44, 55);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
185 ASSERT (result != NULL);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
186 ASSERT (strcmp (result, "0x1.922p+1 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
187 || strcmp (result, "0x3.244p+0 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
188 || strcmp (result, "0x6.488p-1 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
189 || strcmp (result, "0xc.91p-2 33") == 0);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
190 ASSERT (length == strlen (result));
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
191 free (result);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
192 }
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
193
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
194 { /* A negative number. */
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
195 size_t length;
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
196 char *result =
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
197 my_asnprintf (NULL, &length, "%A %d", -3.1416015625, 33, 44, 55);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
198 ASSERT (result != NULL);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
199 ASSERT (strcmp (result, "-0X1.922P+1 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
200 || strcmp (result, "-0X3.244P+0 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
201 || strcmp (result, "-0X6.488P-1 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
202 || strcmp (result, "-0XC.91P-2 33") == 0);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
203 ASSERT (length == strlen (result));
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
204 free (result);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
205 }
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
206
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
207 { /* Positive zero. */
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
208 size_t length;
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
209 char *result =
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
210 my_asnprintf (NULL, &length, "%a %d", 0.0, 33, 44, 55);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
211 ASSERT (result != NULL);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
212 ASSERT (strcmp (result, "0x0p+0 33") == 0);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
213 ASSERT (length == strlen (result));
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
214 free (result);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
215 }
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
216
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
217 { /* Negative zero. */
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
218 size_t length;
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
219 char *result =
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
220 my_asnprintf (NULL, &length, "%a %d", -0.0, 33, 44, 55);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
221 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
222 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
223 ASSERT (strcmp (result, "-0x0p+0 33") == 0);
8336
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
224 ASSERT (length == strlen (result));
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
225 free (result);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
226 }
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
227
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
228 { /* Positive infinity. */
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
229 size_t length;
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
230 char *result =
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
231 my_asnprintf (NULL, &length, "%a %d", 1.0 / 0.0, 33, 44, 55);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
232 ASSERT (result != NULL);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
233 ASSERT (strcmp (result, "inf 33") == 0);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
234 ASSERT (length == strlen (result));
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
235 free (result);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
236 }
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
237
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
238 { /* Negative infinity. */
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
239 size_t length;
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
240 char *result =
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
241 my_asnprintf (NULL, &length, "%a %d", -1.0 / 0.0, 33, 44, 55);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
242 ASSERT (result != NULL);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
243 ASSERT (strcmp (result, "-inf 33") == 0);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
244 ASSERT (length == strlen (result));
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
245 free (result);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
246 }
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
247
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
248 { /* NaN. */
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
249 size_t length;
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
250 char *result =
9854
baba3b346ab2 Use macros NaNf, NaNd, NaNl instead of NAN.
Bruno Haible <bruno@clisp.org>
parents: 9850
diff changeset
251 my_asnprintf (NULL, &length, "%a %d", NaNd (), 33, 44, 55);
8336
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
252 ASSERT (result != NULL);
8850
d1fe16dfbfee Avoid test failures on IRIX 6.5.
Bruno Haible <bruno@clisp.org>
parents: 8839
diff changeset
253 ASSERT (strlen (result) >= 3 + 3
8865
9e203d8ade65 Stricter check for printf result for NaN arguments.
Bruno Haible <bruno@clisp.org>
parents: 8857
diff changeset
254 && strisnan (result, 0, strlen (result) - 3, 0)
8850
d1fe16dfbfee Avoid test failures on IRIX 6.5.
Bruno Haible <bruno@clisp.org>
parents: 8839
diff changeset
255 && strcmp (result + strlen (result) - 3, " 33") == 0);
8336
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
256 ASSERT (length == strlen (result));
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
257 free (result);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
258 }
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
259
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
260 { /* Rounding near the decimal point. */
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
261 size_t length;
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
262 char *result =
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
263 my_asnprintf (NULL, &length, "%.0a %d", 1.5, 33, 44, 55);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
264 ASSERT (result != NULL);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
265 ASSERT (strcmp (result, "0x2p+0 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
266 || strcmp (result, "0x3p-1 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
267 || strcmp (result, "0x6p-2 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
268 || strcmp (result, "0xcp-3 33") == 0);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
269 ASSERT (length == strlen (result));
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
270 free (result);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
271 }
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
272
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
273 { /* Rounding with precision 0. */
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
274 size_t length;
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
275 char *result =
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
276 my_asnprintf (NULL, &length, "%.0a %d", 1.51, 33, 44, 55);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
277 ASSERT (result != NULL);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
278 ASSERT (strcmp (result, "0x2p+0 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
279 || strcmp (result, "0x3p-1 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
280 || strcmp (result, "0x6p-2 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
281 || strcmp (result, "0xcp-3 33") == 0);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
282 ASSERT (length == strlen (result));
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
283 free (result);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
284 }
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
285
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
286 { /* Rounding with precision 1. */
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
287 size_t length;
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
288 char *result =
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
289 my_asnprintf (NULL, &length, "%.1a %d", 1.51, 33, 44, 55);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
290 ASSERT (result != NULL);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
291 ASSERT (strcmp (result, "0x1.8p+0 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
292 || strcmp (result, "0x3.0p-1 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
293 || strcmp (result, "0x6.1p-2 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
294 || strcmp (result, "0xc.1p-3 33") == 0);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
295 ASSERT (length == strlen (result));
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
296 free (result);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
297 }
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
298
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
299 { /* Rounding with precision 2. */
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
300 size_t length;
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
301 char *result =
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
302 my_asnprintf (NULL, &length, "%.2a %d", 1.51, 33, 44, 55);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
303 ASSERT (result != NULL);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
304 ASSERT (strcmp (result, "0x1.83p+0 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
305 || strcmp (result, "0x3.05p-1 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
306 || strcmp (result, "0x6.0ap-2 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
307 || strcmp (result, "0xc.14p-3 33") == 0);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
308 ASSERT (length == strlen (result));
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
309 free (result);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
310 }
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
311
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
312 { /* Rounding with precision 3. */
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
313 size_t length;
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
314 char *result =
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
315 my_asnprintf (NULL, &length, "%.3a %d", 1.51, 33, 44, 55);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
316 ASSERT (result != NULL);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
317 ASSERT (strcmp (result, "0x1.829p+0 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
318 || strcmp (result, "0x3.052p-1 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
319 || strcmp (result, "0x6.0a4p-2 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
320 || strcmp (result, "0xc.148p-3 33") == 0);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
321 ASSERT (length == strlen (result));
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
322 free (result);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
323 }
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
324
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
325 { /* Rounding can turn a ...FFF into a ...000. */
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
326 size_t length;
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
327 char *result =
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
328 my_asnprintf (NULL, &length, "%.3a %d", 1.49999, 33, 44, 55);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
329 ASSERT (result != NULL);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
330 ASSERT (strcmp (result, "0x1.800p+0 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
331 || strcmp (result, "0x3.000p-1 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
332 || strcmp (result, "0x6.000p-2 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
333 || strcmp (result, "0xc.000p-3 33") == 0);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
334 ASSERT (length == strlen (result));
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
335 free (result);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
336 }
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
337
8344
c8055280f68e Test a corner case. Exclude two buggy implementations.
Bruno Haible <bruno@clisp.org>
parents: 8336
diff changeset
338 { /* Rounding can turn a ...FFF into a ...000.
c8055280f68e Test a corner case. Exclude two buggy implementations.
Bruno Haible <bruno@clisp.org>
parents: 8336
diff changeset
339 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: 8336
diff changeset
340 size_t length;
c8055280f68e Test a corner case. Exclude two buggy implementations.
Bruno Haible <bruno@clisp.org>
parents: 8336
diff changeset
341 char *result =
c8055280f68e Test a corner case. Exclude two buggy implementations.
Bruno Haible <bruno@clisp.org>
parents: 8336
diff changeset
342 my_asnprintf (NULL, &length, "%.1a %d", 1.999, 33, 44, 55);
c8055280f68e Test a corner case. Exclude two buggy implementations.
Bruno Haible <bruno@clisp.org>
parents: 8336
diff changeset
343 ASSERT (result != NULL);
c8055280f68e Test a corner case. Exclude two buggy implementations.
Bruno Haible <bruno@clisp.org>
parents: 8336
diff changeset
344 ASSERT (strcmp (result, "0x1.0p+1 33") == 0
c8055280f68e Test a corner case. Exclude two buggy implementations.
Bruno Haible <bruno@clisp.org>
parents: 8336
diff changeset
345 || strcmp (result, "0x2.0p+0 33") == 0
c8055280f68e Test a corner case. Exclude two buggy implementations.
Bruno Haible <bruno@clisp.org>
parents: 8336
diff changeset
346 || strcmp (result, "0x4.0p-1 33") == 0
c8055280f68e Test a corner case. Exclude two buggy implementations.
Bruno Haible <bruno@clisp.org>
parents: 8336
diff changeset
347 || strcmp (result, "0x8.0p-2 33") == 0);
c8055280f68e Test a corner case. Exclude two buggy implementations.
Bruno Haible <bruno@clisp.org>
parents: 8336
diff changeset
348 ASSERT (length == strlen (result));
c8055280f68e Test a corner case. Exclude two buggy implementations.
Bruno Haible <bruno@clisp.org>
parents: 8336
diff changeset
349 free (result);
c8055280f68e Test a corner case. Exclude two buggy implementations.
Bruno Haible <bruno@clisp.org>
parents: 8336
diff changeset
350 }
c8055280f68e Test a corner case. Exclude two buggy implementations.
Bruno Haible <bruno@clisp.org>
parents: 8336
diff changeset
351
8336
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
352 { /* Width. */
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
353 size_t length;
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
354 char *result =
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
355 my_asnprintf (NULL, &length, "%10a %d", 1.75, 33, 44, 55);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
356 ASSERT (result != NULL);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
357 ASSERT (strcmp (result, " 0x1.cp+0 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
358 || strcmp (result, " 0x3.8p-1 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
359 || strcmp (result, " 0x7p-2 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
360 || strcmp (result, " 0xep-3 33") == 0);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
361 ASSERT (length == strlen (result));
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
362 free (result);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
363 }
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
364
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
365 { /* Small precision. */
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
366 size_t length;
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
367 char *result =
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
368 my_asnprintf (NULL, &length, "%.10a %d", 1.75, 33, 44, 55);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
369 ASSERT (result != NULL);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
370 ASSERT (strcmp (result, "0x1.c000000000p+0 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
371 || strcmp (result, "0x3.8000000000p-1 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
372 || strcmp (result, "0x7.0000000000p-2 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
373 || strcmp (result, "0xe.0000000000p-3 33") == 0);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
374 ASSERT (length == strlen (result));
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
375 free (result);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
376 }
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
377
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
378 { /* Large precision. */
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
379 size_t length;
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
380 char *result =
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
381 my_asnprintf (NULL, &length, "%.50a %d", 1.75, 33, 44, 55);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
382 ASSERT (result != NULL);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
383 ASSERT (strcmp (result, "0x1.c0000000000000000000000000000000000000000000000000p+0 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
384 || strcmp (result, "0x3.80000000000000000000000000000000000000000000000000p-1 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
385 || strcmp (result, "0x7.00000000000000000000000000000000000000000000000000p-2 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
386 || strcmp (result, "0xe.00000000000000000000000000000000000000000000000000p-3 33") == 0);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
387 ASSERT (length == strlen (result));
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
388 free (result);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
389 }
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
390
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
391 { /* FLAG_LEFT. */
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
392 size_t length;
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
393 char *result =
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
394 my_asnprintf (NULL, &length, "%-10a %d", 1.75, 33, 44, 55);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
395 ASSERT (result != NULL);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
396 ASSERT (strcmp (result, "0x1.cp+0 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
397 || strcmp (result, "0x3.8p-1 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
398 || strcmp (result, "0x7p-2 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
399 || strcmp (result, "0xep-3 33") == 0);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
400 ASSERT (length == strlen (result));
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
401 free (result);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
402 }
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
403
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
404 { /* FLAG_SHOWSIGN. */
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
405 size_t length;
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
406 char *result =
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
407 my_asnprintf (NULL, &length, "%+a %d", 1.75, 33, 44, 55);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
408 ASSERT (result != NULL);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
409 ASSERT (strcmp (result, "+0x1.cp+0 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
410 || strcmp (result, "+0x3.8p-1 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
411 || strcmp (result, "+0x7p-2 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
412 || strcmp (result, "+0xep-3 33") == 0);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
413 ASSERT (length == strlen (result));
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
414 free (result);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
415 }
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
416
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
417 { /* FLAG_SPACE. */
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
418 size_t length;
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
419 char *result =
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
420 my_asnprintf (NULL, &length, "% a %d", 1.75, 33, 44, 55);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
421 ASSERT (result != NULL);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
422 ASSERT (strcmp (result, " 0x1.cp+0 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
423 || strcmp (result, " 0x3.8p-1 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
424 || strcmp (result, " 0x7p-2 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
425 || strcmp (result, " 0xep-3 33") == 0);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
426 ASSERT (length == strlen (result));
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
427 free (result);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
428 }
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
429
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
430 { /* FLAG_ALT. */
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
431 size_t length;
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
432 char *result =
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
433 my_asnprintf (NULL, &length, "%#a %d", 1.75, 33, 44, 55);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
434 ASSERT (result != NULL);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
435 ASSERT (strcmp (result, "0x1.cp+0 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
436 || strcmp (result, "0x3.8p-1 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
437 || strcmp (result, "0x7.p-2 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
438 || strcmp (result, "0xe.p-3 33") == 0);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
439 ASSERT (length == strlen (result));
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
440 free (result);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
441 }
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
442
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
443 { /* FLAG_ALT. */
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
444 size_t length;
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
445 char *result =
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
446 my_asnprintf (NULL, &length, "%#a %d", 1.0, 33, 44, 55);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
447 ASSERT (result != NULL);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
448 ASSERT (strcmp (result, "0x1.p+0 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
449 || strcmp (result, "0x2.p-1 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
450 || strcmp (result, "0x4.p-2 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
451 || strcmp (result, "0x8.p-3 33") == 0);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
452 ASSERT (length == strlen (result));
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
453 free (result);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
454 }
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
455
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
456 { /* FLAG_ZERO with finite number. */
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
457 size_t length;
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
458 char *result =
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
459 my_asnprintf (NULL, &length, "%010a %d", 1.75, 33, 44, 55);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
460 ASSERT (result != NULL);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
461 ASSERT (strcmp (result, "0x001.cp+0 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
462 || strcmp (result, "0x003.8p-1 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
463 || strcmp (result, "0x00007p-2 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
464 || strcmp (result, "0x0000ep-3 33") == 0);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
465 ASSERT (length == strlen (result));
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
466 free (result);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
467 }
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
468
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
469 { /* FLAG_ZERO with infinite number. */
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
470 size_t length;
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
471 char *result =
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
472 my_asnprintf (NULL, &length, "%010a %d", 1.0 / 0.0, 33, 44, 55);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
473 ASSERT (result != NULL);
8662
023aa5c883a7 Guard against FreeBSD 6.1 bug.
Bruno Haible <bruno@clisp.org>
parents: 8648
diff changeset
474 /* "0000000inf 33" is not a valid result; see
023aa5c883a7 Guard against FreeBSD 6.1 bug.
Bruno Haible <bruno@clisp.org>
parents: 8648
diff changeset
475 <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
476 ASSERT (strcmp (result, " inf 33") == 0);
8336
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
477 ASSERT (length == strlen (result));
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
478 free (result);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
479 }
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
480
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
481 { /* FLAG_ZERO with NaN. */
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
482 size_t length;
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
483 char *result =
9854
baba3b346ab2 Use macros NaNf, NaNd, NaNl instead of NAN.
Bruno Haible <bruno@clisp.org>
parents: 9850
diff changeset
484 my_asnprintf (NULL, &length, "%050a %d", NaNd (), 33, 44, 55);
8336
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
485 ASSERT (result != NULL);
8662
023aa5c883a7 Guard against FreeBSD 6.1 bug.
Bruno Haible <bruno@clisp.org>
parents: 8648
diff changeset
486 /* "0000000nan 33" is not a valid result; see
023aa5c883a7 Guard against FreeBSD 6.1 bug.
Bruno Haible <bruno@clisp.org>
parents: 8648
diff changeset
487 <http://lists.gnu.org/archive/html/bug-gnulib/2007-04/msg00107.html> */
8870
4e1f2ea486b4 Allow for a longer printed representation of NaN.
Bruno Haible <bruno@clisp.org>
parents: 8865
diff changeset
488 ASSERT (strlen (result) == 50 + 3
8865
9e203d8ade65 Stricter check for printf result for NaN arguments.
Bruno Haible <bruno@clisp.org>
parents: 8857
diff changeset
489 && strisnan (result, strspn (result, " "), strlen (result) - 3, 0)
8850
d1fe16dfbfee Avoid test failures on IRIX 6.5.
Bruno Haible <bruno@clisp.org>
parents: 8839
diff changeset
490 && strcmp (result + strlen (result) - 3, " 33") == 0);
8336
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
491 ASSERT (length == strlen (result));
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
492 free (result);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
493 }
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
494
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
495 { /* A positive number. */
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
496 size_t length;
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
497 char *result =
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
498 my_asnprintf (NULL, &length, "%La %d", 3.1416015625L, 33, 44, 55);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
499 ASSERT (result != NULL);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
500 ASSERT (strcmp (result, "0x1.922p+1 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
501 || strcmp (result, "0x3.244p+0 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
502 || strcmp (result, "0x6.488p-1 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
503 || strcmp (result, "0xc.91p-2 33") == 0);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
504 ASSERT (length == strlen (result));
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
505 free (result);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
506 }
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
507
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
508 { /* A negative number. */
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
509 size_t length;
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
510 char *result =
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
511 my_asnprintf (NULL, &length, "%LA %d", -3.1416015625L, 33, 44, 55);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
512 ASSERT (result != NULL);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
513 ASSERT (strcmp (result, "-0X1.922P+1 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
514 || strcmp (result, "-0X3.244P+0 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
515 || strcmp (result, "-0X6.488P-1 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
516 || strcmp (result, "-0XC.91P-2 33") == 0);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
517 ASSERT (length == strlen (result));
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
518 free (result);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
519 }
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
520
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
521 { /* Positive zero. */
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
522 size_t length;
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
523 char *result =
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
524 my_asnprintf (NULL, &length, "%La %d", 0.0L, 33, 44, 55);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
525 ASSERT (result != NULL);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
526 ASSERT (strcmp (result, "0x0p+0 33") == 0);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
527 ASSERT (length == strlen (result));
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
528 free (result);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
529 }
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
530
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
531 { /* Negative zero. */
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
532 size_t length;
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
533 char *result =
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
534 my_asnprintf (NULL, &length, "%La %d", -0.0L, 33, 44, 55);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
535 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
536 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
537 ASSERT (strcmp (result, "-0x0p+0 33") == 0);
8336
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
538 ASSERT (length == strlen (result));
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
539 free (result);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
540 }
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
541
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
542 { /* Positive infinity. */
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
543 size_t length;
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
544 char *result =
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
545 my_asnprintf (NULL, &length, "%La %d", 1.0L / 0.0L, 33, 44, 55);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
546 ASSERT (result != NULL);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
547 ASSERT (strcmp (result, "inf 33") == 0);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
548 ASSERT (length == strlen (result));
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
549 free (result);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
550 }
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
551
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
552 { /* Negative infinity. */
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
553 size_t length;
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
554 char *result =
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
555 my_asnprintf (NULL, &length, "%La %d", -1.0L / 0.0L, 33, 44, 55);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
556 ASSERT (result != NULL);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
557 ASSERT (strcmp (result, "-inf 33") == 0);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
558 ASSERT (length == strlen (result));
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
559 free (result);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
560 }
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
561
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
562 { /* NaN. */
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
563 size_t length;
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
564 char *result =
9854
baba3b346ab2 Use macros NaNf, NaNd, NaNl instead of NAN.
Bruno Haible <bruno@clisp.org>
parents: 9850
diff changeset
565 my_asnprintf (NULL, &length, "%La %d", NaNl (), 33, 44, 55);
8336
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
566 ASSERT (result != NULL);
8850
d1fe16dfbfee Avoid test failures on IRIX 6.5.
Bruno Haible <bruno@clisp.org>
parents: 8839
diff changeset
567 ASSERT (strlen (result) >= 3 + 3
8865
9e203d8ade65 Stricter check for printf result for NaN arguments.
Bruno Haible <bruno@clisp.org>
parents: 8857
diff changeset
568 && strisnan (result, 0, strlen (result) - 3, 0)
8850
d1fe16dfbfee Avoid test failures on IRIX 6.5.
Bruno Haible <bruno@clisp.org>
parents: 8839
diff changeset
569 && strcmp (result + strlen (result) - 3, " 33") == 0);
8336
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
570 ASSERT (length == strlen (result));
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
571 free (result);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
572 }
8919
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
573 #if CHECK_PRINTF_SAFE && ((defined __ia64 && LDBL_MANT_DIG == 64) || (defined __x86_64__ || defined __amd64__) || (defined __i386 || defined __i386__ || defined _I386 || defined _M_IX86 || defined _X86_))
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
574 { /* Quiet NaN. */
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
575 static union { unsigned int word[4]; long double value; } x =
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
576 { LDBL80_WORDS (0xFFFF, 0xC3333333, 0x00000000) };
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
577 size_t length;
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
578 char *result =
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
579 my_asnprintf (NULL, &length, "%La %d", x.value, 33, 44, 55);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
580 ASSERT (result != NULL);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
581 ASSERT (strlen (result) >= 3 + 3
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
582 && strisnan (result, 0, strlen (result) - 3, 0)
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
583 && strcmp (result + strlen (result) - 3, " 33") == 0);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
584 ASSERT (length == strlen (result));
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
585 free (result);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
586 }
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
587 {
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
588 /* Signalling NaN. */
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
589 static union { unsigned int word[4]; long double value; } x =
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
590 { LDBL80_WORDS (0xFFFF, 0x83333333, 0x00000000) };
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
591 size_t length;
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
592 char *result =
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
593 my_asnprintf (NULL, &length, "%La %d", x.value, 33, 44, 55);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
594 ASSERT (result != NULL);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
595 ASSERT (strlen (result) >= 3 + 3
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
596 && strisnan (result, 0, strlen (result) - 3, 0)
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
597 && strcmp (result + strlen (result) - 3, " 33") == 0);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
598 ASSERT (length == strlen (result));
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
599 free (result);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
600 }
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
601 /* The isnanl function should recognize Pseudo-NaNs, Pseudo-Infinities,
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
602 Pseudo-Zeroes, Unnormalized Numbers, and Pseudo-Denormals, as defined in
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
603 Intel IA-64 Architecture Software Developer's Manual, Volume 1:
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
604 Application Architecture.
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
605 Table 5-2 "Floating-Point Register Encodings"
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
606 Figure 5-6 "Memory to Floating-Point Register Data Translation"
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
607 */
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
608 { /* Pseudo-NaN. */
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
609 static union { unsigned int word[4]; long double value; } x =
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
610 { LDBL80_WORDS (0xFFFF, 0x40000001, 0x00000000) };
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
611 size_t length;
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
612 char *result =
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
613 my_asnprintf (NULL, &length, "%La %d", x.value, 33, 44, 55);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
614 ASSERT (result != NULL);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
615 ASSERT (strlen (result) >= 3 + 3
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
616 && strisnan (result, 0, strlen (result) - 3, 0)
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
617 && strcmp (result + strlen (result) - 3, " 33") == 0);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
618 ASSERT (length == strlen (result));
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
619 free (result);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
620 }
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
621 { /* Pseudo-Infinity. */
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
622 static union { unsigned int word[4]; long double value; } x =
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
623 { LDBL80_WORDS (0xFFFF, 0x00000000, 0x00000000) };
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
624 size_t length;
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
625 char *result =
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
626 my_asnprintf (NULL, &length, "%La %d", x.value, 33, 44, 55);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
627 ASSERT (result != NULL);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
628 ASSERT (strlen (result) >= 3 + 3
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
629 && strisnan (result, 0, strlen (result) - 3, 0)
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
630 && strcmp (result + strlen (result) - 3, " 33") == 0);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
631 ASSERT (length == strlen (result));
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
632 free (result);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
633 }
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
634 { /* Pseudo-Zero. */
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
635 static union { unsigned int word[4]; long double value; } x =
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
636 { LDBL80_WORDS (0x4004, 0x00000000, 0x00000000) };
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
637 size_t length;
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
638 char *result =
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
639 my_asnprintf (NULL, &length, "%La %d", x.value, 33, 44, 55);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
640 ASSERT (result != NULL);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
641 ASSERT (strlen (result) >= 3 + 3
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
642 && strisnan (result, 0, strlen (result) - 3, 0)
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
643 && strcmp (result + strlen (result) - 3, " 33") == 0);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
644 ASSERT (length == strlen (result));
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
645 free (result);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
646 }
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
647 { /* Unnormalized number. */
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
648 static union { unsigned int word[4]; long double value; } x =
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
649 { LDBL80_WORDS (0x4000, 0x63333333, 0x00000000) };
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
650 size_t length;
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
651 char *result =
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
652 my_asnprintf (NULL, &length, "%La %d", x.value, 33, 44, 55);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
653 ASSERT (result != NULL);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
654 ASSERT (strlen (result) >= 3 + 3
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
655 && strisnan (result, 0, strlen (result) - 3, 0)
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
656 && strcmp (result + strlen (result) - 3, " 33") == 0);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
657 ASSERT (length == strlen (result));
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
658 free (result);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
659 }
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
660 { /* Pseudo-Denormal. */
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
661 static union { unsigned int word[4]; long double value; } x =
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
662 { LDBL80_WORDS (0x0000, 0x83333333, 0x00000000) };
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
663 size_t length;
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
664 char *result =
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
665 my_asnprintf (NULL, &length, "%La %d", x.value, 33, 44, 55);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
666 ASSERT (result != NULL);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
667 ASSERT (strlen (result) >= 3 + 3
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
668 && strisnan (result, 0, strlen (result) - 3, 0)
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
669 && strcmp (result + strlen (result) - 3, " 33") == 0);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
670 ASSERT (length == strlen (result));
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
671 free (result);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
672 }
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
673 #endif
8336
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
674
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
675 { /* Rounding near the decimal point. */
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
676 size_t length;
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
677 char *result =
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
678 my_asnprintf (NULL, &length, "%.0La %d", 1.5L, 33, 44, 55);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
679 ASSERT (result != NULL);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
680 ASSERT (strcmp (result, "0x2p+0 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
681 || strcmp (result, "0x3p-1 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
682 || strcmp (result, "0x6p-2 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
683 || strcmp (result, "0xcp-3 33") == 0);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
684 ASSERT (length == strlen (result));
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
685 free (result);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
686 }
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
687
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
688 { /* Rounding with precision 0. */
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
689 size_t length;
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
690 char *result =
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
691 my_asnprintf (NULL, &length, "%.0La %d", 1.51L, 33, 44, 55);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
692 ASSERT (result != NULL);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
693 ASSERT (strcmp (result, "0x2p+0 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
694 || strcmp (result, "0x3p-1 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
695 || strcmp (result, "0x6p-2 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
696 || strcmp (result, "0xcp-3 33") == 0);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
697 ASSERT (length == strlen (result));
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
698 free (result);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
699 }
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
700
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
701 { /* Rounding with precision 1. */
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
702 size_t length;
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
703 char *result =
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
704 my_asnprintf (NULL, &length, "%.1La %d", 1.51L, 33, 44, 55);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
705 ASSERT (result != NULL);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
706 ASSERT (strcmp (result, "0x1.8p+0 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
707 || strcmp (result, "0x3.0p-1 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
708 || strcmp (result, "0x6.1p-2 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
709 || strcmp (result, "0xc.1p-3 33") == 0);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
710 ASSERT (length == strlen (result));
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
711 free (result);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
712 }
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
713
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
714 { /* Rounding with precision 2. */
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
715 size_t length;
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
716 char *result =
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
717 my_asnprintf (NULL, &length, "%.2La %d", 1.51L, 33, 44, 55);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
718 ASSERT (result != NULL);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
719 ASSERT (strcmp (result, "0x1.83p+0 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
720 || strcmp (result, "0x3.05p-1 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
721 || strcmp (result, "0x6.0ap-2 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
722 || strcmp (result, "0xc.14p-3 33") == 0);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
723 ASSERT (length == strlen (result));
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
724 free (result);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
725 }
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
726
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
727 { /* Rounding with precision 3. */
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
728 size_t length;
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
729 char *result =
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
730 my_asnprintf (NULL, &length, "%.3La %d", 1.51L, 33, 44, 55);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
731 ASSERT (result != NULL);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
732 ASSERT (strcmp (result, "0x1.829p+0 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
733 || strcmp (result, "0x3.052p-1 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
734 || strcmp (result, "0x6.0a4p-2 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
735 || strcmp (result, "0xc.148p-3 33") == 0);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
736 ASSERT (length == strlen (result));
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
737 free (result);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
738 }
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
739
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
740 { /* Rounding can turn a ...FFF into a ...000. */
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
741 size_t length;
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
742 char *result =
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
743 my_asnprintf (NULL, &length, "%.3La %d", 1.49999L, 33, 44, 55);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
744 ASSERT (result != NULL);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
745 ASSERT (strcmp (result, "0x1.800p+0 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
746 || strcmp (result, "0x3.000p-1 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
747 || strcmp (result, "0x6.000p-2 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
748 || strcmp (result, "0xc.000p-3 33") == 0);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
749 ASSERT (length == strlen (result));
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
750 free (result);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
751 }
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
752
8344
c8055280f68e Test a corner case. Exclude two buggy implementations.
Bruno Haible <bruno@clisp.org>
parents: 8336
diff changeset
753 { /* Rounding can turn a ...FFF into a ...000.
c8055280f68e Test a corner case. Exclude two buggy implementations.
Bruno Haible <bruno@clisp.org>
parents: 8336
diff changeset
754 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: 8336
diff changeset
755 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: 8336
diff changeset
756 size_t length;
c8055280f68e Test a corner case. Exclude two buggy implementations.
Bruno Haible <bruno@clisp.org>
parents: 8336
diff changeset
757 char *result =
c8055280f68e Test a corner case. Exclude two buggy implementations.
Bruno Haible <bruno@clisp.org>
parents: 8336
diff changeset
758 my_asnprintf (NULL, &length, "%.1La %d", 1.999L, 33, 44, 55);
c8055280f68e Test a corner case. Exclude two buggy implementations.
Bruno Haible <bruno@clisp.org>
parents: 8336
diff changeset
759 ASSERT (result != NULL);
c8055280f68e Test a corner case. Exclude two buggy implementations.
Bruno Haible <bruno@clisp.org>
parents: 8336
diff changeset
760 ASSERT (strcmp (result, "0x1.0p+1 33") == 0
c8055280f68e Test a corner case. Exclude two buggy implementations.
Bruno Haible <bruno@clisp.org>
parents: 8336
diff changeset
761 || strcmp (result, "0x2.0p+0 33") == 0
c8055280f68e Test a corner case. Exclude two buggy implementations.
Bruno Haible <bruno@clisp.org>
parents: 8336
diff changeset
762 || strcmp (result, "0x4.0p-1 33") == 0
c8055280f68e Test a corner case. Exclude two buggy implementations.
Bruno Haible <bruno@clisp.org>
parents: 8336
diff changeset
763 || strcmp (result, "0x8.0p-2 33") == 0);
c8055280f68e Test a corner case. Exclude two buggy implementations.
Bruno Haible <bruno@clisp.org>
parents: 8336
diff changeset
764 ASSERT (length == strlen (result));
c8055280f68e Test a corner case. Exclude two buggy implementations.
Bruno Haible <bruno@clisp.org>
parents: 8336
diff changeset
765 free (result);
c8055280f68e Test a corner case. Exclude two buggy implementations.
Bruno Haible <bruno@clisp.org>
parents: 8336
diff changeset
766 }
c8055280f68e Test a corner case. Exclude two buggy implementations.
Bruno Haible <bruno@clisp.org>
parents: 8336
diff changeset
767
8336
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
768 { /* Width. */
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
769 size_t length;
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
770 char *result =
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
771 my_asnprintf (NULL, &length, "%10La %d", 1.75L, 33, 44, 55);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
772 ASSERT (result != NULL);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
773 ASSERT (strcmp (result, " 0x1.cp+0 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
774 || strcmp (result, " 0x3.8p-1 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
775 || strcmp (result, " 0x7p-2 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
776 || strcmp (result, " 0xep-3 33") == 0);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
777 ASSERT (length == strlen (result));
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
778 free (result);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
779 }
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
780
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
781 { /* Small precision. */
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
782 size_t length;
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
783 char *result =
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
784 my_asnprintf (NULL, &length, "%.10La %d", 1.75L, 33, 44, 55);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
785 ASSERT (result != NULL);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
786 ASSERT (strcmp (result, "0x1.c000000000p+0 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
787 || strcmp (result, "0x3.8000000000p-1 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
788 || strcmp (result, "0x7.0000000000p-2 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
789 || strcmp (result, "0xe.0000000000p-3 33") == 0);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
790 ASSERT (length == strlen (result));
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
791 free (result);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
792 }
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
793
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
794 { /* Large precision. */
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
795 size_t length;
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
796 char *result =
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
797 my_asnprintf (NULL, &length, "%.50La %d", 1.75L, 33, 44, 55);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
798 ASSERT (result != NULL);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
799 ASSERT (strcmp (result, "0x1.c0000000000000000000000000000000000000000000000000p+0 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
800 || strcmp (result, "0x3.80000000000000000000000000000000000000000000000000p-1 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
801 || strcmp (result, "0x7.00000000000000000000000000000000000000000000000000p-2 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
802 || strcmp (result, "0xe.00000000000000000000000000000000000000000000000000p-3 33") == 0);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
803 ASSERT (length == strlen (result));
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
804 free (result);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
805 }
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
806
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
807 { /* FLAG_LEFT. */
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
808 size_t length;
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
809 char *result =
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
810 my_asnprintf (NULL, &length, "%-10La %d", 1.75L, 33, 44, 55);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
811 ASSERT (result != NULL);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
812 ASSERT (strcmp (result, "0x1.cp+0 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
813 || strcmp (result, "0x3.8p-1 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
814 || strcmp (result, "0x7p-2 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
815 || strcmp (result, "0xep-3 33") == 0);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
816 ASSERT (length == strlen (result));
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
817 free (result);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
818 }
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
819
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
820 { /* FLAG_SHOWSIGN. */
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
821 size_t length;
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
822 char *result =
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
823 my_asnprintf (NULL, &length, "%+La %d", 1.75L, 33, 44, 55);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
824 ASSERT (result != NULL);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
825 ASSERT (strcmp (result, "+0x1.cp+0 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
826 || strcmp (result, "+0x3.8p-1 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
827 || strcmp (result, "+0x7p-2 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
828 || strcmp (result, "+0xep-3 33") == 0);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
829 ASSERT (length == strlen (result));
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
830 free (result);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
831 }
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
832
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
833 { /* FLAG_SPACE. */
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
834 size_t length;
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
835 char *result =
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
836 my_asnprintf (NULL, &length, "% La %d", 1.75L, 33, 44, 55);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
837 ASSERT (result != NULL);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
838 ASSERT (strcmp (result, " 0x1.cp+0 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
839 || strcmp (result, " 0x3.8p-1 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
840 || strcmp (result, " 0x7p-2 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
841 || strcmp (result, " 0xep-3 33") == 0);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
842 ASSERT (length == strlen (result));
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
843 free (result);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
844 }
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
845
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
846 { /* FLAG_ALT. */
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
847 size_t length;
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
848 char *result =
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
849 my_asnprintf (NULL, &length, "%#La %d", 1.75L, 33, 44, 55);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
850 ASSERT (result != NULL);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
851 ASSERT (strcmp (result, "0x1.cp+0 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
852 || strcmp (result, "0x3.8p-1 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
853 || strcmp (result, "0x7.p-2 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
854 || strcmp (result, "0xe.p-3 33") == 0);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
855 ASSERT (length == strlen (result));
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
856 free (result);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
857 }
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
858
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
859 { /* FLAG_ALT. */
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
860 size_t length;
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
861 char *result =
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
862 my_asnprintf (NULL, &length, "%#La %d", 1.0L, 33, 44, 55);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
863 ASSERT (result != NULL);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
864 ASSERT (strcmp (result, "0x1.p+0 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
865 || strcmp (result, "0x2.p-1 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
866 || strcmp (result, "0x4.p-2 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
867 || strcmp (result, "0x8.p-3 33") == 0);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
868 ASSERT (length == strlen (result));
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
869 free (result);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
870 }
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
871
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
872 { /* FLAG_ZERO with finite number. */
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
873 size_t length;
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
874 char *result =
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
875 my_asnprintf (NULL, &length, "%010La %d", 1.75L, 33, 44, 55);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
876 ASSERT (result != NULL);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
877 ASSERT (strcmp (result, "0x001.cp+0 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
878 || strcmp (result, "0x003.8p-1 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
879 || strcmp (result, "0x00007p-2 33") == 0
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
880 || strcmp (result, "0x0000ep-3 33") == 0);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
881 ASSERT (length == strlen (result));
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
882 free (result);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
883 }
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
884
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
885 { /* FLAG_ZERO with infinite number. */
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
886 size_t length;
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
887 char *result =
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
888 my_asnprintf (NULL, &length, "%010La %d", 1.0L / 0.0L, 33, 44, 55);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
889 ASSERT (result != NULL);
8662
023aa5c883a7 Guard against FreeBSD 6.1 bug.
Bruno Haible <bruno@clisp.org>
parents: 8648
diff changeset
890 /* "0000000inf 33" is not a valid result; see
023aa5c883a7 Guard against FreeBSD 6.1 bug.
Bruno Haible <bruno@clisp.org>
parents: 8648
diff changeset
891 <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
892 ASSERT (strcmp (result, " inf 33") == 0);
8336
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
893 ASSERT (length == strlen (result));
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
894 free (result);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
895 }
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
896
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
897 { /* FLAG_ZERO with NaN. */
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
898 size_t length;
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
899 char *result =
9854
baba3b346ab2 Use macros NaNf, NaNd, NaNl instead of NAN.
Bruno Haible <bruno@clisp.org>
parents: 9850
diff changeset
900 my_asnprintf (NULL, &length, "%050La %d", NaNl (), 33, 44, 55);
8336
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
901 ASSERT (result != NULL);
8662
023aa5c883a7 Guard against FreeBSD 6.1 bug.
Bruno Haible <bruno@clisp.org>
parents: 8648
diff changeset
902 /* "0000000nan 33" is not a valid result; see
023aa5c883a7 Guard against FreeBSD 6.1 bug.
Bruno Haible <bruno@clisp.org>
parents: 8648
diff changeset
903 <http://lists.gnu.org/archive/html/bug-gnulib/2007-04/msg00107.html> */
8870
4e1f2ea486b4 Allow for a longer printed representation of NaN.
Bruno Haible <bruno@clisp.org>
parents: 8865
diff changeset
904 ASSERT (strlen (result) == 50 + 3
8865
9e203d8ade65 Stricter check for printf result for NaN arguments.
Bruno Haible <bruno@clisp.org>
parents: 8857
diff changeset
905 && strisnan (result, strspn (result, " "), strlen (result) - 3, 0)
8850
d1fe16dfbfee Avoid test failures on IRIX 6.5.
Bruno Haible <bruno@clisp.org>
parents: 8839
diff changeset
906 && strcmp (result + strlen (result) - 3, " 33") == 0);
8336
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
907 ASSERT (length == strlen (result));
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
908 free (result);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
909 }
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
910
8684
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
911 /* 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
912
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
913 { /* A positive number. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
914 size_t length;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
915 char *result =
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
916 my_asnprintf (NULL, &length, "%f %d", 12.75, 33, 44, 55);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
917 ASSERT (result != NULL);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
918 ASSERT (strcmp (result, "12.750000 33") == 0);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
919 ASSERT (length == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
920 free (result);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
921 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
922
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
923 { /* A larger positive number. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
924 size_t length;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
925 char *result =
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
926 my_asnprintf (NULL, &length, "%f %d", 1234567.0, 33, 44, 55);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
927 ASSERT (result != NULL);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
928 ASSERT (strcmp (result, "1234567.000000 33") == 0);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
929 ASSERT (length == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
930 free (result);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
931 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
932
8834
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
933 { /* Small and large positive numbers. */
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
934 static struct { double value; const char *string; } data[] =
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
935 {
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
936 { 1.234321234321234e-37, "0.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
937 { 1.234321234321234e-36, "0.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
938 { 1.234321234321234e-35, "0.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
939 { 1.234321234321234e-34, "0.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
940 { 1.234321234321234e-33, "0.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
941 { 1.234321234321234e-32, "0.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
942 { 1.234321234321234e-31, "0.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
943 { 1.234321234321234e-30, "0.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
944 { 1.234321234321234e-29, "0.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
945 { 1.234321234321234e-28, "0.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
946 { 1.234321234321234e-27, "0.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
947 { 1.234321234321234e-26, "0.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
948 { 1.234321234321234e-25, "0.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
949 { 1.234321234321234e-24, "0.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
950 { 1.234321234321234e-23, "0.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
951 { 1.234321234321234e-22, "0.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
952 { 1.234321234321234e-21, "0.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
953 { 1.234321234321234e-20, "0.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
954 { 1.234321234321234e-19, "0.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
955 { 1.234321234321234e-18, "0.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
956 { 1.234321234321234e-17, "0.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
957 { 1.234321234321234e-16, "0.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
958 { 1.234321234321234e-15, "0.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
959 { 1.234321234321234e-14, "0.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
960 { 1.234321234321234e-13, "0.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
961 { 1.234321234321234e-12, "0.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
962 { 1.234321234321234e-11, "0.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
963 { 1.234321234321234e-10, "0.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
964 { 1.234321234321234e-9, "0.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
965 { 1.234321234321234e-8, "0.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
966 { 1.234321234321234e-7, "0.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
967 { 1.234321234321234e-6, "0.000001" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
968 { 1.234321234321234e-5, "0.000012" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
969 { 1.234321234321234e-4, "0.000123" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
970 { 1.234321234321234e-3, "0.001234" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
971 { 1.234321234321234e-2, "0.012343" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
972 { 1.234321234321234e-1, "0.123432" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
973 { 1.234321234321234, "1.234321" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
974 { 1.234321234321234e1, "12.343212" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
975 { 1.234321234321234e2, "123.432123" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
976 { 1.234321234321234e3, "1234.321234" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
977 { 1.234321234321234e4, "12343.212343" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
978 { 1.234321234321234e5, "123432.123432" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
979 { 1.234321234321234e6, "1234321.234321" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
980 { 1.234321234321234e7, "12343212.343212" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
981 { 1.234321234321234e8, "123432123.432123" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
982 { 1.234321234321234e9, "1234321234.321234" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
983 { 1.234321234321234e10, "12343212343.2123**" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
984 { 1.234321234321234e11, "123432123432.123***" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
985 { 1.234321234321234e12, "1234321234321.23****" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
986 { 1.234321234321234e13, "12343212343212.3*****" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
987 { 1.234321234321234e14, "123432123432123.******" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
988 { 1.234321234321234e15, "1234321234321234.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
989 { 1.234321234321234e16, "123432123432123**.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
990 { 1.234321234321234e17, "123432123432123***.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
991 { 1.234321234321234e18, "123432123432123****.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
992 { 1.234321234321234e19, "123432123432123*****.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
993 { 1.234321234321234e20, "123432123432123******.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
994 { 1.234321234321234e21, "123432123432123*******.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
995 { 1.234321234321234e22, "123432123432123********.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
996 { 1.234321234321234e23, "123432123432123*********.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
997 { 1.234321234321234e24, "123432123432123**********.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
998 { 1.234321234321234e25, "123432123432123***********.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
999 { 1.234321234321234e26, "123432123432123************.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1000 { 1.234321234321234e27, "123432123432123*************.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1001 { 1.234321234321234e28, "123432123432123**************.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1002 { 1.234321234321234e29, "123432123432123***************.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1003 { 1.234321234321234e30, "123432123432123****************.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1004 { 1.234321234321234e31, "123432123432123*****************.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1005 { 1.234321234321234e32, "123432123432123******************.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1006 { 1.234321234321234e33, "123432123432123*******************.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1007 { 1.234321234321234e34, "123432123432123********************.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1008 { 1.234321234321234e35, "123432123432123*********************.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1009 { 1.234321234321234e36, "123432123432123**********************.000000" }
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1010 };
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1011 size_t k;
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1012 for (k = 0; k < SIZEOF (data); k++)
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1013 {
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1014 size_t length;
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1015 char *result =
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1016 my_asnprintf (NULL, &length, "%f", data[k].value);
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1017 ASSERT (result != NULL);
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1018 ASSERT (strmatch (data[k].string, result));
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1019 ASSERT (length == strlen (result));
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1020 free (result);
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1021 }
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1022 }
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1023
8684
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1024 { /* A negative number. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1025 size_t length;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1026 char *result =
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1027 my_asnprintf (NULL, &length, "%f %d", -0.03125, 33, 44, 55);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1028 ASSERT (result != NULL);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1029 ASSERT (strcmp (result, "-0.031250 33") == 0);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1030 ASSERT (length == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1031 free (result);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1032 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1033
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1034 { /* Positive zero. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1035 size_t length;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1036 char *result =
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1037 my_asnprintf (NULL, &length, "%f %d", 0.0, 33, 44, 55);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1038 ASSERT (result != NULL);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1039 ASSERT (strcmp (result, "0.000000 33") == 0);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1040 ASSERT (length == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1041 free (result);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1042 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1043
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1044 { /* Negative zero. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1045 size_t length;
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 my_asnprintf (NULL, &length, "%f %d", -0.0, 33, 44, 55);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1048 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
1049 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
1050 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
1051 ASSERT (length == 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 { /* Positive infinity. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1056 size_t length;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1057 char *result =
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1058 my_asnprintf (NULL, &length, "%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
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, "inf 33") == 0
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1061 || strcmp (result, "infinity 33") == 0);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1062 ASSERT (length == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1063 free (result);
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
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1066 { /* Negative infinity. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1067 size_t length;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1068 char *result =
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1069 my_asnprintf (NULL, &length, "%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
1070 ASSERT (result != NULL);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1071 ASSERT (strcmp (result, "-inf 33") == 0
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1072 || strcmp (result, "-infinity 33") == 0);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1073 ASSERT (length == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1074 free (result);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1075 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1076
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1077 { /* NaN. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1078 size_t length;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1079 char *result =
9854
baba3b346ab2 Use macros NaNf, NaNd, NaNl instead of NAN.
Bruno Haible <bruno@clisp.org>
parents: 9850
diff changeset
1080 my_asnprintf (NULL, &length, "%f %d", NaNd (), 33, 44, 55);
8684
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1081 ASSERT (result != NULL);
8850
d1fe16dfbfee Avoid test failures on IRIX 6.5.
Bruno Haible <bruno@clisp.org>
parents: 8839
diff changeset
1082 ASSERT (strlen (result) >= 3 + 3
8865
9e203d8ade65 Stricter check for printf result for NaN arguments.
Bruno Haible <bruno@clisp.org>
parents: 8857
diff changeset
1083 && strisnan (result, 0, strlen (result) - 3, 0)
8850
d1fe16dfbfee Avoid test failures on IRIX 6.5.
Bruno Haible <bruno@clisp.org>
parents: 8839
diff changeset
1084 && 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
1085 ASSERT (length == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1086 free (result);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1087 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1088
8804
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1089 { /* Width. */
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1090 size_t length;
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1091 char *result =
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1092 my_asnprintf (NULL, &length, "%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
1093 ASSERT (result != NULL);
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1094 ASSERT (strcmp (result, " 1.750000 33") == 0);
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1095 ASSERT (length == strlen (result));
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1096 free (result);
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1097 }
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1098
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1099 { /* FLAG_LEFT. */
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1100 size_t length;
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1101 char *result =
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1102 my_asnprintf (NULL, &length, "%-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
1103 ASSERT (result != NULL);
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1104 ASSERT (strcmp (result, "1.750000 33") == 0);
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1105 ASSERT (length == strlen (result));
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1106 free (result);
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1107 }
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1108
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1109 { /* FLAG_SHOWSIGN. */
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1110 size_t length;
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1111 char *result =
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1112 my_asnprintf (NULL, &length, "%+f %d", 1.75, 33, 44, 55);
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1113 ASSERT (result != NULL);
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1114 ASSERT (strcmp (result, "+1.750000 33") == 0);
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1115 ASSERT (length == strlen (result));
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1116 free (result);
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1117 }
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1118
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1119 { /* FLAG_SPACE. */
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1120 size_t length;
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1121 char *result =
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1122 my_asnprintf (NULL, &length, "% f %d", 1.75, 33, 44, 55);
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1123 ASSERT (result != NULL);
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1124 ASSERT (strcmp (result, " 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
1125 ASSERT (length == strlen (result));
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1126 free (result);
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1127 }
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1128
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1129 { /* FLAG_ALT. */
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1130 size_t length;
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1131 char *result =
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1132 my_asnprintf (NULL, &length, "%#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
1133 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
1134 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
1135 ASSERT (length == strlen (result));
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1136 free (result);
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1137 }
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1138
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1139 { /* FLAG_ALT. */
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1140 size_t length;
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1141 char *result =
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1142 my_asnprintf (NULL, &length, "%#.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
1143 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
1144 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
1145 ASSERT (length == strlen (result));
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1146 free (result);
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1147 }
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1148
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1149 { /* FLAG_ZERO with finite number. */
8684
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1150 size_t length;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1151 char *result =
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1152 my_asnprintf (NULL, &length, "%015f %d", 1234.0, 33, 44, 55);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1153 ASSERT (result != NULL);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1154 ASSERT (strcmp (result, "00001234.000000 33") == 0);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1155 ASSERT (length == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1156 free (result);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1157 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1158
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1159 { /* FLAG_ZERO with infinite number. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1160 size_t length;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1161 char *result =
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1162 my_asnprintf (NULL, &length, "%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
1163 ASSERT (result != NULL);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1164 ASSERT (strcmp (result, " -inf 33") == 0
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1165 || strcmp (result, " -infinity 33") == 0);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1166 ASSERT (length == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1167 free (result);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1168 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1169
8804
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1170 { /* 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
1171 size_t length;
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1172 char *result =
9854
baba3b346ab2 Use macros NaNf, NaNd, NaNl instead of NAN.
Bruno Haible <bruno@clisp.org>
parents: 9850
diff changeset
1173 my_asnprintf (NULL, &length, "%050f %d", NaNd (), 33, 44, 55);
8804
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1174 ASSERT (result != NULL);
8870
4e1f2ea486b4 Allow for a longer printed representation of NaN.
Bruno Haible <bruno@clisp.org>
parents: 8865
diff changeset
1175 ASSERT (strlen (result) == 50 + 3
8865
9e203d8ade65 Stricter check for printf result for NaN arguments.
Bruno Haible <bruno@clisp.org>
parents: 8857
diff changeset
1176 && strisnan (result, strspn (result, " "), strlen (result) - 3, 0)
8850
d1fe16dfbfee Avoid test failures on IRIX 6.5.
Bruno Haible <bruno@clisp.org>
parents: 8839
diff changeset
1177 && 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
1178 ASSERT (length == strlen (result));
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1179 free (result);
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1180 }
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1181
8684
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1182 { /* Precision. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1183 size_t length;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1184 char *result =
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1185 my_asnprintf (NULL, &length, "%.f %d", 1234.0, 33, 44, 55);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1186 ASSERT (result != NULL);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1187 ASSERT (strcmp (result, "1234 33") == 0);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1188 ASSERT (length == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1189 free (result);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1190 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1191
9938
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
1192 { /* Precision with no rounding. */
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
1193 size_t length;
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
1194 char *result =
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
1195 my_asnprintf (NULL, &length, "%.2f %d", 999.951, 33, 44, 55);
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
1196 ASSERT (result != NULL);
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
1197 ASSERT (strcmp (result, "999.95 33") == 0);
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
1198 ASSERT (length == strlen (result));
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
1199 free (result);
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
1200 }
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
1201
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
1202 { /* Precision with rounding. */
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
1203 size_t length;
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
1204 char *result =
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
1205 my_asnprintf (NULL, &length, "%.2f %d", 999.996, 33, 44, 55);
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
1206 ASSERT (result != NULL);
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
1207 ASSERT (strcmp (result, "1000.00 33") == 0);
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
1208 ASSERT (length == strlen (result));
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
1209 free (result);
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
1210 }
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
1211
8684
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1212 { /* A positive number. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1213 size_t length;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1214 char *result =
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1215 my_asnprintf (NULL, &length, "%Lf %d", 12.75L, 33, 44, 55);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1216 ASSERT (result != NULL);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1217 ASSERT (strcmp (result, "12.750000 33") == 0);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1218 ASSERT (length == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1219 free (result);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1220 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1221
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1222 { /* A larger positive number. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1223 size_t length;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1224 char *result =
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1225 my_asnprintf (NULL, &length, "%Lf %d", 1234567.0L, 33, 44, 55);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1226 ASSERT (result != NULL);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1227 ASSERT (strcmp (result, "1234567.000000 33") == 0);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1228 ASSERT (length == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1229 free (result);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1230 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1231
8834
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1232 { /* Small and large positive numbers. */
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1233 static struct { long double value; const char *string; } data[] =
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1234 {
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1235 { 1.234321234321234e-37L, "0.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1236 { 1.234321234321234e-36L, "0.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1237 { 1.234321234321234e-35L, "0.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1238 { 1.234321234321234e-34L, "0.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1239 { 1.234321234321234e-33L, "0.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1240 { 1.234321234321234e-32L, "0.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1241 { 1.234321234321234e-31L, "0.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1242 { 1.234321234321234e-30L, "0.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1243 { 1.234321234321234e-29L, "0.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1244 { 1.234321234321234e-28L, "0.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1245 { 1.234321234321234e-27L, "0.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1246 { 1.234321234321234e-26L, "0.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1247 { 1.234321234321234e-25L, "0.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1248 { 1.234321234321234e-24L, "0.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1249 { 1.234321234321234e-23L, "0.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1250 { 1.234321234321234e-22L, "0.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1251 { 1.234321234321234e-21L, "0.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1252 { 1.234321234321234e-20L, "0.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1253 { 1.234321234321234e-19L, "0.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1254 { 1.234321234321234e-18L, "0.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1255 { 1.234321234321234e-17L, "0.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1256 { 1.234321234321234e-16L, "0.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1257 { 1.234321234321234e-15L, "0.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1258 { 1.234321234321234e-14L, "0.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1259 { 1.234321234321234e-13L, "0.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1260 { 1.234321234321234e-12L, "0.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1261 { 1.234321234321234e-11L, "0.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1262 { 1.234321234321234e-10L, "0.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1263 { 1.234321234321234e-9L, "0.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1264 { 1.234321234321234e-8L, "0.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1265 { 1.234321234321234e-7L, "0.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1266 { 1.234321234321234e-6L, "0.000001" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1267 { 1.234321234321234e-5L, "0.000012" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1268 { 1.234321234321234e-4L, "0.000123" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1269 { 1.234321234321234e-3L, "0.001234" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1270 { 1.234321234321234e-2L, "0.012343" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1271 { 1.234321234321234e-1L, "0.123432" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1272 { 1.234321234321234L, "1.234321" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1273 { 1.234321234321234e1L, "12.343212" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1274 { 1.234321234321234e2L, "123.432123" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1275 { 1.234321234321234e3L, "1234.321234" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1276 { 1.234321234321234e4L, "12343.212343" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1277 { 1.234321234321234e5L, "123432.123432" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1278 { 1.234321234321234e6L, "1234321.234321" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1279 { 1.234321234321234e7L, "12343212.343212" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1280 { 1.234321234321234e8L, "123432123.432123" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1281 { 1.234321234321234e9L, "1234321234.321234" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1282 { 1.234321234321234e10L, "12343212343.2123**" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1283 { 1.234321234321234e11L, "123432123432.123***" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1284 { 1.234321234321234e12L, "1234321234321.23****" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1285 { 1.234321234321234e13L, "12343212343212.3*****" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1286 { 1.234321234321234e14L, "123432123432123.******" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1287 { 1.234321234321234e15L, "1234321234321234.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1288 { 1.234321234321234e16L, "123432123432123**.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1289 { 1.234321234321234e17L, "123432123432123***.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1290 { 1.234321234321234e18L, "123432123432123****.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1291 { 1.234321234321234e19L, "123432123432123*****.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1292 { 1.234321234321234e20L, "123432123432123******.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1293 { 1.234321234321234e21L, "123432123432123*******.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1294 { 1.234321234321234e22L, "123432123432123********.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1295 { 1.234321234321234e23L, "123432123432123*********.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1296 { 1.234321234321234e24L, "123432123432123**********.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1297 { 1.234321234321234e25L, "123432123432123***********.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1298 { 1.234321234321234e26L, "123432123432123************.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1299 { 1.234321234321234e27L, "123432123432123*************.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1300 { 1.234321234321234e28L, "123432123432123**************.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1301 { 1.234321234321234e29L, "123432123432123***************.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1302 { 1.234321234321234e30L, "123432123432123****************.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1303 { 1.234321234321234e31L, "123432123432123*****************.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1304 { 1.234321234321234e32L, "123432123432123******************.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1305 { 1.234321234321234e33L, "123432123432123*******************.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1306 { 1.234321234321234e34L, "123432123432123********************.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1307 { 1.234321234321234e35L, "123432123432123*********************.000000" },
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1308 { 1.234321234321234e36L, "123432123432123**********************.000000" }
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1309 };
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1310 size_t k;
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1311 for (k = 0; k < SIZEOF (data); k++)
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1312 {
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1313 size_t length;
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1314 char *result =
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1315 my_asnprintf (NULL, &length, "%Lf", data[k].value);
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1316 ASSERT (result != NULL);
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1317 ASSERT (strmatch (data[k].string, result));
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1318 ASSERT (length == strlen (result));
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1319 free (result);
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1320 }
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1321 }
4c705f82cd20 More tests of printf %f.
Bruno Haible <bruno@clisp.org>
parents: 8804
diff changeset
1322
8684
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1323 { /* A negative number. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1324 size_t length;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1325 char *result =
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1326 my_asnprintf (NULL, &length, "%Lf %d", -0.03125L, 33, 44, 55);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1327 ASSERT (result != NULL);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1328 ASSERT (strcmp (result, "-0.031250 33") == 0);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1329 ASSERT (length == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1330 free (result);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1331 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1332
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1333 { /* Positive zero. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1334 size_t length;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1335 char *result =
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1336 my_asnprintf (NULL, &length, "%Lf %d", 0.0L, 33, 44, 55);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1337 ASSERT (result != NULL);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1338 ASSERT (strcmp (result, "0.000000 33") == 0);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1339 ASSERT (length == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1340 free (result);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1341 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1342
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1343 { /* Negative zero. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1344 size_t length;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1345 char *result =
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1346 my_asnprintf (NULL, &length, "%Lf %d", -0.0L, 33, 44, 55);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1347 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
1348 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
1349 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
1350 ASSERT (length == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1351 free (result);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1352 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1353
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1354 { /* Positive infinity. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1355 size_t length;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1356 char *result =
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1357 my_asnprintf (NULL, &length, "%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
1358 ASSERT (result != NULL);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1359 ASSERT (strcmp (result, "inf 33") == 0
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1360 || strcmp (result, "infinity 33") == 0);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1361 ASSERT (length == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1362 free (result);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1363 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1364
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1365 { /* Negative infinity. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1366 size_t length;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1367 char *result =
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1368 my_asnprintf (NULL, &length, "%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
1369 ASSERT (result != NULL);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1370 ASSERT (strcmp (result, "-inf 33") == 0
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1371 || strcmp (result, "-infinity 33") == 0);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1372 ASSERT (length == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1373 free (result);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1374 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1375
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1376 { /* NaN. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1377 size_t length;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1378 char *result =
9854
baba3b346ab2 Use macros NaNf, NaNd, NaNl instead of NAN.
Bruno Haible <bruno@clisp.org>
parents: 9850
diff changeset
1379 my_asnprintf (NULL, &length, "%Lf %d", NaNl (), 33, 44, 55);
8684
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1380 ASSERT (result != NULL);
8850
d1fe16dfbfee Avoid test failures on IRIX 6.5.
Bruno Haible <bruno@clisp.org>
parents: 8839
diff changeset
1381 ASSERT (strlen (result) >= 3 + 3
8865
9e203d8ade65 Stricter check for printf result for NaN arguments.
Bruno Haible <bruno@clisp.org>
parents: 8857
diff changeset
1382 && strisnan (result, 0, strlen (result) - 3, 0)
8850
d1fe16dfbfee Avoid test failures on IRIX 6.5.
Bruno Haible <bruno@clisp.org>
parents: 8839
diff changeset
1383 && 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
1384 ASSERT (length == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1385 free (result);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1386 }
8919
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
1387 #if CHECK_PRINTF_SAFE && ((defined __ia64 && LDBL_MANT_DIG == 64) || (defined __x86_64__ || defined __amd64__) || (defined __i386 || defined __i386__ || defined _I386 || defined _M_IX86 || defined _X86_))
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
1388 { /* Quiet NaN. */
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
1389 static union { unsigned int word[4]; long double value; } x =
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
1390 { LDBL80_WORDS (0xFFFF, 0xC3333333, 0x00000000) };
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
1391 size_t length;
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
1392 char *result =
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
1393 my_asnprintf (NULL, &length, "%Lf %d", x.value, 33, 44, 55);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
1394 ASSERT (result != NULL);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
1395 ASSERT (strlen (result) >= 3 + 3
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
1396 && strisnan (result, 0, strlen (result) - 3, 0)
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
1397 && strcmp (result + strlen (result) - 3, " 33") == 0);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
1398 ASSERT (length == strlen (result));
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
1399 free (result);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
1400 }
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
1401 {
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
1402 /* Signalling NaN. */
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
1403 static union { unsigned int word[4]; long double value; } x =
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
1404 { LDBL80_WORDS (0xFFFF, 0x83333333, 0x00000000) };
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
1405 size_t length;
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
1406 char *result =
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
1407 my_asnprintf (NULL, &length, "%Lf %d", x.value, 33, 44, 55);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
1408 ASSERT (result != NULL);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
1409 ASSERT (strlen (result) >= 3 + 3
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
1410 && strisnan (result, 0, strlen (result) - 3, 0)
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
1411 && strcmp (result + strlen (result) - 3, " 33") == 0);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
1412 ASSERT (length == strlen (result));
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
1413 free (result);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
1414 }
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
1415 /* The isnanl function should recognize Pseudo-NaNs, Pseudo-Infinities,
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
1416 Pseudo-Zeroes, Unnormalized Numbers, and Pseudo-Denormals, as defined in
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
1417 Intel IA-64 Architecture Software Developer's Manual, Volume 1:
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
1418 Application Architecture.
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
1419 Table 5-2 "Floating-Point Register Encodings"
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
1420 Figure 5-6 "Memory to Floating-Point Register Data Translation"
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
1421 */
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
1422 { /* Pseudo-NaN. */
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
1423 static union { unsigned int word[4]; long double value; } x =
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
1424 { LDBL80_WORDS (0xFFFF, 0x40000001, 0x00000000) };
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
1425 size_t length;
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
1426 char *result =
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
1427 my_asnprintf (NULL, &length, "%Lf %d", x.value, 33, 44, 55);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
1428 ASSERT (result != NULL);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
1429 ASSERT (strlen (result) >= 3 + 3
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
1430 && strisnan (result, 0, strlen (result) - 3, 0)
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
1431 && strcmp (result + strlen (result) - 3, " 33") == 0);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
1432 ASSERT (length == strlen (result));
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
1433 free (result);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
1434 }
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
1435 { /* Pseudo-Infinity. */
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
1436 static union { unsigned int word[4]; long double value; } x =
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
1437 { LDBL80_WORDS (0xFFFF, 0x00000000, 0x00000000) };
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
1438 size_t length;
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
1439 char *result =
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
1440 my_asnprintf (NULL, &length, "%Lf %d", x.value, 33, 44, 55);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
1441 ASSERT (result != NULL);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
1442 ASSERT (strlen (result) >= 3 + 3
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
1443 && strisnan (result, 0, strlen (result) - 3, 0)
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
1444 && strcmp (result + strlen (result) - 3, " 33") == 0);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
1445 ASSERT (length == strlen (result));
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
1446 free (result);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
1447 }
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
1448 { /* Pseudo-Zero. */
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
1449 static union { unsigned int word[4]; long double value; } x =
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
1450 { LDBL80_WORDS (0x4004, 0x00000000, 0x00000000) };
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
1451 size_t length;
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
1452 char *result =
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
1453 my_asnprintf (NULL, &length, "%Lf %d", x.value, 33, 44, 55);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
1454 ASSERT (result != NULL);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
1455 ASSERT (strlen (result) >= 3 + 3
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
1456 && strisnan (result, 0, strlen (result) - 3, 0)
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
1457 && strcmp (result + strlen (result) - 3, " 33") == 0);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
1458 ASSERT (length == strlen (result));
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
1459 free (result);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
1460 }
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
1461 { /* Unnormalized number. */
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
1462 static union { unsigned int word[4]; long double value; } x =
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
1463 { LDBL80_WORDS (0x4000, 0x63333333, 0x00000000) };
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
1464 size_t length;
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
1465 char *result =
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
1466 my_asnprintf (NULL, &length, "%Lf %d", x.value, 33, 44, 55);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
1467 ASSERT (result != NULL);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
1468 ASSERT (strlen (result) >= 3 + 3
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
1469 && strisnan (result, 0, strlen (result) - 3, 0)
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
1470 && strcmp (result + strlen (result) - 3, " 33") == 0);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
1471 ASSERT (length == strlen (result));
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
1472 free (result);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
1473 }
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
1474 { /* Pseudo-Denormal. */
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
1475 static union { unsigned int word[4]; long double value; } x =
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
1476 { LDBL80_WORDS (0x0000, 0x83333333, 0x00000000) };
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
1477 size_t length;
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
1478 char *result =
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
1479 my_asnprintf (NULL, &length, "%Lf %d", x.value, 33, 44, 55);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
1480 ASSERT (result != NULL);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
1481 ASSERT (strlen (result) >= 3 + 3
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
1482 && strisnan (result, 0, strlen (result) - 3, 0)
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
1483 && strcmp (result + strlen (result) - 3, " 33") == 0);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
1484 ASSERT (length == strlen (result));
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
1485 free (result);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
1486 }
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
1487 #endif
8684
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1488
8804
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1489 { /* Width. */
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1490 size_t length;
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1491 char *result =
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1492 my_asnprintf (NULL, &length, "%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
1493 ASSERT (result != NULL);
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1494 ASSERT (strcmp (result, " 1.750000 33") == 0);
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1495 ASSERT (length == strlen (result));
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1496 free (result);
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1497 }
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1498
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1499 { /* FLAG_LEFT. */
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1500 size_t length;
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1501 char *result =
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1502 my_asnprintf (NULL, &length, "%-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
1503 ASSERT (result != NULL);
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1504 ASSERT (strcmp (result, "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
1505 ASSERT (length == strlen (result));
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1506 free (result);
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1507 }
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1508
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1509 { /* FLAG_SHOWSIGN. */
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1510 size_t length;
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1511 char *result =
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1512 my_asnprintf (NULL, &length, "%+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
1513 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
1514 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
1515 ASSERT (length == strlen (result));
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1516 free (result);
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1517 }
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1518
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1519 { /* FLAG_SPACE. */
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1520 size_t length;
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1521 char *result =
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1522 my_asnprintf (NULL, &length, "% 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
1523 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
1524 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
1525 ASSERT (length == strlen (result));
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1526 free (result);
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1527 }
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1528
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1529 { /* FLAG_ALT. */
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1530 size_t length;
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1531 char *result =
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1532 my_asnprintf (NULL, &length, "%#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
1533 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
1534 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
1535 ASSERT (length == strlen (result));
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1536 free (result);
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1537 }
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1538
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1539 { /* FLAG_ALT. */
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1540 size_t length;
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1541 char *result =
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1542 my_asnprintf (NULL, &length, "%#.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
1543 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
1544 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
1545 ASSERT (length == strlen (result));
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1546 free (result);
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1547 }
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1548
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1549 { /* FLAG_ZERO with finite number. */
8684
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1550 size_t length;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1551 char *result =
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1552 my_asnprintf (NULL, &length, "%015Lf %d", 1234.0L, 33, 44, 55);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1553 ASSERT (result != NULL);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1554 ASSERT (strcmp (result, "00001234.000000 33") == 0);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1555 ASSERT (length == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1556 free (result);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1557 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1558
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1559 { /* FLAG_ZERO with infinite number. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1560 size_t length;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1561 char *result =
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1562 my_asnprintf (NULL, &length, "%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
1563 ASSERT (result != NULL);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1564 ASSERT (strcmp (result, " -inf 33") == 0
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1565 || strcmp (result, " -infinity 33") == 0);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1566 ASSERT (length == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1567 free (result);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1568 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1569
8804
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1570 { /* 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
1571 size_t length;
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1572 char *result =
9854
baba3b346ab2 Use macros NaNf, NaNd, NaNl instead of NAN.
Bruno Haible <bruno@clisp.org>
parents: 9850
diff changeset
1573 my_asnprintf (NULL, &length, "%050Lf %d", NaNl (), 33, 44, 55);
8804
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1574 ASSERT (result != NULL);
8870
4e1f2ea486b4 Allow for a longer printed representation of NaN.
Bruno Haible <bruno@clisp.org>
parents: 8865
diff changeset
1575 ASSERT (strlen (result) == 50 + 3
8865
9e203d8ade65 Stricter check for printf result for NaN arguments.
Bruno Haible <bruno@clisp.org>
parents: 8857
diff changeset
1576 && strisnan (result, strspn (result, " "), strlen (result) - 3, 0)
8850
d1fe16dfbfee Avoid test failures on IRIX 6.5.
Bruno Haible <bruno@clisp.org>
parents: 8839
diff changeset
1577 && 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
1578 ASSERT (length == strlen (result));
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1579 free (result);
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1580 }
6ce313658b4d Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents: 8803
diff changeset
1581
8684
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1582 { /* Precision. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1583 size_t length;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1584 char *result =
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1585 my_asnprintf (NULL, &length, "%.Lf %d", 1234.0L, 33, 44, 55);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1586 ASSERT (result != NULL);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1587 ASSERT (strcmp (result, "1234 33") == 0);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1588 ASSERT (length == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1589 free (result);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1590 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1591
9938
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
1592 { /* Precision with no rounding. */
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
1593 size_t length;
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
1594 char *result =
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
1595 my_asnprintf (NULL, &length, "%.2Lf %d", 999.951L, 33, 44, 55);
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
1596 ASSERT (result != NULL);
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
1597 ASSERT (strcmp (result, "999.95 33") == 0);
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
1598 ASSERT (length == strlen (result));
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
1599 free (result);
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
1600 }
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
1601
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
1602 { /* Precision with rounding. */
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
1603 size_t length;
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
1604 char *result =
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
1605 my_asnprintf (NULL, &length, "%.2Lf %d", 999.996L, 33, 44, 55);
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
1606 ASSERT (result != NULL);
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
1607 ASSERT (strcmp (result, "1000.00 33") == 0);
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
1608 ASSERT (length == strlen (result));
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
1609 free (result);
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
1610 }
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
1611
8684
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1612 /* 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
1613
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1614 { /* A positive number. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1615 size_t length;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1616 char *result =
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1617 my_asnprintf (NULL, &length, "%F %d", 12.75, 33, 44, 55);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1618 ASSERT (result != NULL);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1619 ASSERT (strcmp (result, "12.750000 33") == 0);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1620 ASSERT (length == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1621 free (result);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1622 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1623
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1624 { /* A larger positive number. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1625 size_t length;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1626 char *result =
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1627 my_asnprintf (NULL, &length, "%F %d", 1234567.0, 33, 44, 55);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1628 ASSERT (result != NULL);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1629 ASSERT (strcmp (result, "1234567.000000 33") == 0);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1630 ASSERT (length == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1631 free (result);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1632 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1633
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1634 { /* A negative number. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1635 size_t length;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1636 char *result =
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1637 my_asnprintf (NULL, &length, "%F %d", -0.03125, 33, 44, 55);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1638 ASSERT (result != NULL);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1639 ASSERT (strcmp (result, "-0.031250 33") == 0);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1640 ASSERT (length == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1641 free (result);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1642 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1643
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1644 { /* Positive zero. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1645 size_t length;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1646 char *result =
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1647 my_asnprintf (NULL, &length, "%F %d", 0.0, 33, 44, 55);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1648 ASSERT (result != NULL);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1649 ASSERT (strcmp (result, "0.000000 33") == 0);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1650 ASSERT (length == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1651 free (result);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1652 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1653
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1654 { /* Negative zero. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1655 size_t length;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1656 char *result =
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1657 my_asnprintf (NULL, &length, "%F %d", -0.0, 33, 44, 55);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1658 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
1659 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
1660 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
1661 ASSERT (length == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1662 free (result);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1663 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1664
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1665 { /* Positive infinity. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1666 size_t length;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1667 char *result =
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1668 my_asnprintf (NULL, &length, "%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
1669 ASSERT (result != NULL);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1670 ASSERT (strcmp (result, "INF 33") == 0
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1671 || strcmp (result, "INFINITY 33") == 0);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1672 ASSERT (length == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1673 free (result);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1674 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1675
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1676 { /* Negative infinity. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1677 size_t length;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1678 char *result =
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1679 my_asnprintf (NULL, &length, "%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
1680 ASSERT (result != NULL);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1681 ASSERT (strcmp (result, "-INF 33") == 0
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1682 || strcmp (result, "-INFINITY 33") == 0);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1683 ASSERT (length == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1684 free (result);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1685 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1686
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1687 { /* NaN. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1688 size_t length;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1689 char *result =
9854
baba3b346ab2 Use macros NaNf, NaNd, NaNl instead of NAN.
Bruno Haible <bruno@clisp.org>
parents: 9850
diff changeset
1690 my_asnprintf (NULL, &length, "%F %d", NaNd (), 33, 44, 55);
8684
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1691 ASSERT (result != NULL);
8850
d1fe16dfbfee Avoid test failures on IRIX 6.5.
Bruno Haible <bruno@clisp.org>
parents: 8839
diff changeset
1692 ASSERT (strlen (result) >= 3 + 3
8865
9e203d8ade65 Stricter check for printf result for NaN arguments.
Bruno Haible <bruno@clisp.org>
parents: 8857
diff changeset
1693 && strisnan (result, 0, strlen (result) - 3, 1)
8850
d1fe16dfbfee Avoid test failures on IRIX 6.5.
Bruno Haible <bruno@clisp.org>
parents: 8839
diff changeset
1694 && 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
1695 ASSERT (length == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1696 free (result);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1697 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1698
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1699 { /* FLAG_ZERO. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1700 size_t length;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1701 char *result =
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1702 my_asnprintf (NULL, &length, "%015F %d", 1234.0, 33, 44, 55);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1703 ASSERT (result != NULL);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1704 ASSERT (strcmp (result, "00001234.000000 33") == 0);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1705 ASSERT (length == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1706 free (result);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1707 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1708
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1709 { /* FLAG_ZERO with infinite number. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1710 size_t length;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1711 char *result =
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1712 my_asnprintf (NULL, &length, "%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
1713 ASSERT (result != NULL);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1714 ASSERT (strcmp (result, " -INF 33") == 0
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1715 || strcmp (result, " -INFINITY 33") == 0);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1716 ASSERT (length == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1717 free (result);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1718 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1719
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1720 { /* Precision. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1721 size_t length;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1722 char *result =
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1723 my_asnprintf (NULL, &length, "%.F %d", 1234.0, 33, 44, 55);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1724 ASSERT (result != NULL);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1725 ASSERT (strcmp (result, "1234 33") == 0);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1726 ASSERT (length == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1727 free (result);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1728 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1729
9938
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
1730 { /* Precision with no rounding. */
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
1731 size_t length;
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
1732 char *result =
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
1733 my_asnprintf (NULL, &length, "%.2F %d", 999.951, 33, 44, 55);
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
1734 ASSERT (result != NULL);
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
1735 ASSERT (strcmp (result, "999.95 33") == 0);
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
1736 ASSERT (length == strlen (result));
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
1737 free (result);
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
1738 }
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
1739
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
1740 { /* Precision with rounding. */
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
1741 size_t length;
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
1742 char *result =
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
1743 my_asnprintf (NULL, &length, "%.2F %d", 999.996, 33, 44, 55);
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
1744 ASSERT (result != NULL);
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
1745 ASSERT (strcmp (result, "1000.00 33") == 0);
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
1746 ASSERT (length == strlen (result));
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
1747 free (result);
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
1748 }
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
1749
8684
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1750 { /* A positive number. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1751 size_t length;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1752 char *result =
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1753 my_asnprintf (NULL, &length, "%LF %d", 12.75L, 33, 44, 55);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1754 ASSERT (result != NULL);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1755 ASSERT (strcmp (result, "12.750000 33") == 0);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1756 ASSERT (length == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1757 free (result);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1758 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1759
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1760 { /* A larger positive number. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1761 size_t length;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1762 char *result =
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1763 my_asnprintf (NULL, &length, "%LF %d", 1234567.0L, 33, 44, 55);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1764 ASSERT (result != NULL);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1765 ASSERT (strcmp (result, "1234567.000000 33") == 0);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1766 ASSERT (length == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1767 free (result);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1768 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1769
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1770 { /* A negative number. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1771 size_t length;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1772 char *result =
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1773 my_asnprintf (NULL, &length, "%LF %d", -0.03125L, 33, 44, 55);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1774 ASSERT (result != NULL);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1775 ASSERT (strcmp (result, "-0.031250 33") == 0);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1776 ASSERT (length == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1777 free (result);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1778 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1779
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1780 { /* Positive zero. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1781 size_t length;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1782 char *result =
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1783 my_asnprintf (NULL, &length, "%LF %d", 0.0L, 33, 44, 55);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1784 ASSERT (result != NULL);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1785 ASSERT (strcmp (result, "0.000000 33") == 0);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1786 ASSERT (length == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1787 free (result);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1788 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1789
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1790 { /* Negative zero. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1791 size_t length;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1792 char *result =
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1793 my_asnprintf (NULL, &length, "%LF %d", -0.0L, 33, 44, 55);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1794 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
1795 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
1796 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
1797 ASSERT (length == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1798 free (result);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1799 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1800
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1801 { /* Positive infinity. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1802 size_t length;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1803 char *result =
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1804 my_asnprintf (NULL, &length, "%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
1805 ASSERT (result != NULL);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1806 ASSERT (strcmp (result, "INF 33") == 0
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1807 || strcmp (result, "INFINITY 33") == 0);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1808 ASSERT (length == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1809 free (result);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1810 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1811
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1812 { /* Negative infinity. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1813 size_t length;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1814 char *result =
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1815 my_asnprintf (NULL, &length, "%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
1816 ASSERT (result != NULL);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1817 ASSERT (strcmp (result, "-INF 33") == 0
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1818 || strcmp (result, "-INFINITY 33") == 0);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1819 ASSERT (length == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1820 free (result);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1821 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1822
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1823 { /* NaN. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1824 size_t length;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1825 char *result =
9854
baba3b346ab2 Use macros NaNf, NaNd, NaNl instead of NAN.
Bruno Haible <bruno@clisp.org>
parents: 9850
diff changeset
1826 my_asnprintf (NULL, &length, "%LF %d", NaNl (), 33, 44, 55);
8684
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1827 ASSERT (result != NULL);
8850
d1fe16dfbfee Avoid test failures on IRIX 6.5.
Bruno Haible <bruno@clisp.org>
parents: 8839
diff changeset
1828 ASSERT (strlen (result) >= 3 + 3
8865
9e203d8ade65 Stricter check for printf result for NaN arguments.
Bruno Haible <bruno@clisp.org>
parents: 8857
diff changeset
1829 && strisnan (result, 0, strlen (result) - 3, 1)
8850
d1fe16dfbfee Avoid test failures on IRIX 6.5.
Bruno Haible <bruno@clisp.org>
parents: 8839
diff changeset
1830 && 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
1831 ASSERT (length == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1832 free (result);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1833 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1834
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1835 { /* FLAG_ZERO. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1836 size_t length;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1837 char *result =
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1838 my_asnprintf (NULL, &length, "%015LF %d", 1234.0L, 33, 44, 55);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1839 ASSERT (result != NULL);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1840 ASSERT (strcmp (result, "00001234.000000 33") == 0);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1841 ASSERT (length == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1842 free (result);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1843 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1844
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1845 { /* FLAG_ZERO with infinite number. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1846 size_t length;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1847 char *result =
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1848 my_asnprintf (NULL, &length, "%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
1849 ASSERT (result != NULL);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1850 ASSERT (strcmp (result, " -INF 33") == 0
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1851 || strcmp (result, " -INFINITY 33") == 0);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1852 ASSERT (length == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1853 free (result);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1854 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1855
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1856 { /* Precision. */
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1857 size_t length;
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1858 char *result =
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1859 my_asnprintf (NULL, &length, "%.LF %d", 1234.0L, 33, 44, 55);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1860 ASSERT (result != NULL);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1861 ASSERT (strcmp (result, "1234 33") == 0);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1862 ASSERT (length == strlen (result));
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1863 free (result);
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1864 }
9ea5590b49d1 Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents: 8662
diff changeset
1865
9938
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
1866 { /* Precision with no rounding. */
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
1867 size_t length;
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
1868 char *result =
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
1869 my_asnprintf (NULL, &length, "%.2LF %d", 999.951L, 33, 44, 55);
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
1870 ASSERT (result != NULL);
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
1871 ASSERT (strcmp (result, "999.95 33") == 0);
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
1872 ASSERT (length == strlen (result));
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
1873 free (result);
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
1874 }
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
1875
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
1876 { /* Precision with rounding. */
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
1877 size_t length;
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
1878 char *result =
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
1879 my_asnprintf (NULL, &length, "%.2LF %d", 999.996L, 33, 44, 55);
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
1880 ASSERT (result != NULL);
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
1881 ASSERT (strcmp (result, "1000.00 33") == 0);
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
1882 ASSERT (length == strlen (result));
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
1883 free (result);
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
1884 }
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
1885
8836
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1886 /* 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
1887
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1888 { /* A positive number. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1889 size_t length;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1890 char *result =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1891 my_asnprintf (NULL, &length, "%e %d", 12.75, 33, 44, 55);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1892 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
1893 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
1894 || 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
1895 ASSERT (length == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1896 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1897 }
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 { /* A larger positive number. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1900 size_t length;
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 my_asnprintf (NULL, &length, "%e %d", 1234567.0, 33, 44, 55);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1903 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
1904 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
1905 || 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
1906 ASSERT (length == 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 { 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-37, "1.234321e-37" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1914 { 1.234321234321234e-36, "1.234321e-36" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1915 { 1.234321234321234e-35, "1.234321e-35" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1916 { 1.234321234321234e-34, "1.234321e-34" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1917 { 1.234321234321234e-33, "1.234321e-33" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1918 { 1.234321234321234e-32, "1.234321e-32" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1919 { 1.234321234321234e-31, "1.234321e-31" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1920 { 1.234321234321234e-30, "1.234321e-30" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1921 { 1.234321234321234e-29, "1.234321e-29" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1922 { 1.234321234321234e-28, "1.234321e-28" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1923 { 1.234321234321234e-27, "1.234321e-27" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1924 { 1.234321234321234e-26, "1.234321e-26" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1925 { 1.234321234321234e-25, "1.234321e-25" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1926 { 1.234321234321234e-24, "1.234321e-24" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1927 { 1.234321234321234e-23, "1.234321e-23" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1928 { 1.234321234321234e-22, "1.234321e-22" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1929 { 1.234321234321234e-21, "1.234321e-21" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1930 { 1.234321234321234e-20, "1.234321e-20" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1931 { 1.234321234321234e-19, "1.234321e-19" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1932 { 1.234321234321234e-18, "1.234321e-18" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1933 { 1.234321234321234e-17, "1.234321e-17" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1934 { 1.234321234321234e-16, "1.234321e-16" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1935 { 1.234321234321234e-15, "1.234321e-15" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1936 { 1.234321234321234e-14, "1.234321e-14" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1937 { 1.234321234321234e-13, "1.234321e-13" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1938 { 1.234321234321234e-12, "1.234321e-12" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1939 { 1.234321234321234e-11, "1.234321e-11" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1940 { 1.234321234321234e-10, "1.234321e-10" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1941 { 1.234321234321234e-9, "1.234321e-09" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1942 { 1.234321234321234e-8, "1.234321e-08" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1943 { 1.234321234321234e-7, "1.234321e-07" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1944 { 1.234321234321234e-6, "1.234321e-06" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1945 { 1.234321234321234e-5, "1.234321e-05" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1946 { 1.234321234321234e-4, "1.234321e-04" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1947 { 1.234321234321234e-3, "1.234321e-03" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1948 { 1.234321234321234e-2, "1.234321e-02" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1949 { 1.234321234321234e-1, "1.234321e-01" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1950 { 1.234321234321234, "1.234321e+00" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1951 { 1.234321234321234e1, "1.234321e+01" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1952 { 1.234321234321234e2, "1.234321e+02" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1953 { 1.234321234321234e3, "1.234321e+03" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1954 { 1.234321234321234e4, "1.234321e+04" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1955 { 1.234321234321234e5, "1.234321e+05" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1956 { 1.234321234321234e6, "1.234321e+06" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1957 { 1.234321234321234e7, "1.234321e+07" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1958 { 1.234321234321234e8, "1.234321e+08" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1959 { 1.234321234321234e9, "1.234321e+09" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1960 { 1.234321234321234e10, "1.234321e+10" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1961 { 1.234321234321234e11, "1.234321e+11" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1962 { 1.234321234321234e12, "1.234321e+12" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1963 { 1.234321234321234e13, "1.234321e+13" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1964 { 1.234321234321234e14, "1.234321e+14" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1965 { 1.234321234321234e15, "1.234321e+15" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1966 { 1.234321234321234e16, "1.234321e+16" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1967 { 1.234321234321234e17, "1.234321e+17" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1968 { 1.234321234321234e18, "1.234321e+18" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1969 { 1.234321234321234e19, "1.234321e+19" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1970 { 1.234321234321234e20, "1.234321e+20" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1971 { 1.234321234321234e21, "1.234321e+21" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1972 { 1.234321234321234e22, "1.234321e+22" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1973 { 1.234321234321234e23, "1.234321e+23" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1974 { 1.234321234321234e24, "1.234321e+24" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1975 { 1.234321234321234e25, "1.234321e+25" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1976 { 1.234321234321234e26, "1.234321e+26" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1977 { 1.234321234321234e27, "1.234321e+27" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1978 { 1.234321234321234e28, "1.234321e+28" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1979 { 1.234321234321234e29, "1.234321e+29" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1980 { 1.234321234321234e30, "1.234321e+30" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1981 { 1.234321234321234e31, "1.234321e+31" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1982 { 1.234321234321234e32, "1.234321e+32" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1983 { 1.234321234321234e33, "1.234321e+33" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1984 { 1.234321234321234e34, "1.234321e+34" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1985 { 1.234321234321234e35, "1.234321e+35" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1986 { 1.234321234321234e36, "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 size_t length;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1992 char *result =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1993 my_asnprintf (NULL, &length, "%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
1994 const char *expected = data[k].string;
8836
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
1995 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
1996 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
1997 /* 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
1998 || (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
1999 && 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
2000 && 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
2001 && 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
2002 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
2003 == 0));
8836
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2004 ASSERT (length == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2005 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2006 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2007 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2008
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2009 { /* A negative number. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2010 size_t length;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2011 char *result =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2012 my_asnprintf (NULL, &length, "%e %d", -0.03125, 33, 44, 55);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2013 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
2014 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
2015 || 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
2016 ASSERT (length == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2017 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2018 }
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 { /* Positive zero. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2021 size_t length;
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 my_asnprintf (NULL, &length, "%e %d", 0.0, 33, 44, 55);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2024 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
2025 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
2026 || 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
2027 ASSERT (length == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2028 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2029 }
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 { /* Negative zero. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2032 size_t length;
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 my_asnprintf (NULL, &length, "%e %d", -0.0, 33, 44, 55);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2035 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
2036 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
2037 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
2038 || 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
2039 ASSERT (length == 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 { /* Positive infinity. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2044 size_t length;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2045 char *result =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2046 my_asnprintf (NULL, &length, "%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
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 (length == 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 { /* Negative infinity. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2055 size_t length;
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 my_asnprintf (NULL, &length, "%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
2058 ASSERT (result != NULL);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2059 ASSERT (strcmp (result, "-inf 33") == 0
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2060 || strcmp (result, "-infinity 33") == 0);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2061 ASSERT (length == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2062 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2063 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2064
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2065 { /* NaN. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2066 size_t length;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2067 char *result =
9854
baba3b346ab2 Use macros NaNf, NaNd, NaNl instead of NAN.
Bruno Haible <bruno@clisp.org>
parents: 9850
diff changeset
2068 my_asnprintf (NULL, &length, "%e %d", NaNd (), 33, 44, 55);
8836
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2069 ASSERT (result != NULL);
8850
d1fe16dfbfee Avoid test failures on IRIX 6.5.
Bruno Haible <bruno@clisp.org>
parents: 8839
diff changeset
2070 ASSERT (strlen (result) >= 3 + 3
8865
9e203d8ade65 Stricter check for printf result for NaN arguments.
Bruno Haible <bruno@clisp.org>
parents: 8857
diff changeset
2071 && strisnan (result, 0, strlen (result) - 3, 0)
8850
d1fe16dfbfee Avoid test failures on IRIX 6.5.
Bruno Haible <bruno@clisp.org>
parents: 8839
diff changeset
2072 && 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
2073 ASSERT (length == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2074 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2075 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2076
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2077 { /* Width. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2078 size_t length;
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 my_asnprintf (NULL, &length, "%15e %d", 1.75, 33, 44, 55);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2081 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
2082 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
2083 || 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
2084 ASSERT (length == 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_LEFT. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2089 size_t length;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2090 char *result =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2091 my_asnprintf (NULL, &length, "%-15e %d", 1.75, 33, 44, 55);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2092 ASSERT (result != NULL);
8839
5efc1d668039 Accomodate for implementations that produce 3 exponent digits in %e and %g.
Bruno Haible <bruno@clisp.org>
parents: 8836
diff changeset
2093 ASSERT (strcmp (result, "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
2094 || 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
2095 ASSERT (length == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2096 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2097 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2098
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2099 { /* FLAG_SHOWSIGN. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2100 size_t length;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2101 char *result =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2102 my_asnprintf (NULL, &length, "%+e %d", 1.75, 33, 44, 55);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2103 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
2104 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
2105 || 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
2106 ASSERT (length == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2107 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2108 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2109
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2110 { /* FLAG_SPACE. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2111 size_t length;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2112 char *result =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2113 my_asnprintf (NULL, &length, "% e %d", 1.75, 33, 44, 55);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2114 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
2115 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
2116 || 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
2117 ASSERT (length == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2118 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2119 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2120
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2121 { /* FLAG_ALT. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2122 size_t length;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2123 char *result =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2124 my_asnprintf (NULL, &length, "%#e %d", 1.75, 33, 44, 55);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2125 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
2126 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
2127 || 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
2128 ASSERT (length == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2129 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2130 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2131
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2132 { /* FLAG_ALT. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2133 size_t length;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2134 char *result =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2135 my_asnprintf (NULL, &length, "%#.e %d", 1.75, 33, 44, 55);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2136 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
2137 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
2138 || 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
2139 ASSERT (length == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2140 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2141 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2142
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2143 { /* FLAG_ALT. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2144 size_t length;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2145 char *result =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2146 my_asnprintf (NULL, &length, "%#.e %d", 9.75, 33, 44, 55);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2147 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
2148 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
2149 || 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
2150 ASSERT (length == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2151 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2152 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2153
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2154 { /* FLAG_ZERO with finite number. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2155 size_t length;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2156 char *result =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2157 my_asnprintf (NULL, &length, "%015e %d", 1234.0, 33, 44, 55);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2158 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
2159 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
2160 || 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
2161 ASSERT (length == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2162 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2163 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2164
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2165 { /* FLAG_ZERO with infinite number. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2166 size_t length;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2167 char *result =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2168 my_asnprintf (NULL, &length, "%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
2169 ASSERT (result != NULL);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2170 ASSERT (strcmp (result, " -inf 33") == 0
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2171 || strcmp (result, " -infinity 33") == 0);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2172 ASSERT (length == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2173 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2174 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2175
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2176 { /* FLAG_ZERO with NaN. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2177 size_t length;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2178 char *result =
9854
baba3b346ab2 Use macros NaNf, NaNd, NaNl instead of NAN.
Bruno Haible <bruno@clisp.org>
parents: 9850
diff changeset
2179 my_asnprintf (NULL, &length, "%050e %d", NaNd (), 33, 44, 55);
8836
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2180 ASSERT (result != NULL);
8870
4e1f2ea486b4 Allow for a longer printed representation of NaN.
Bruno Haible <bruno@clisp.org>
parents: 8865
diff changeset
2181 ASSERT (strlen (result) == 50 + 3
8865
9e203d8ade65 Stricter check for printf result for NaN arguments.
Bruno Haible <bruno@clisp.org>
parents: 8857
diff changeset
2182 && strisnan (result, strspn (result, " "), strlen (result) - 3, 0)
8850
d1fe16dfbfee Avoid test failures on IRIX 6.5.
Bruno Haible <bruno@clisp.org>
parents: 8839
diff changeset
2183 && 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
2184 ASSERT (length == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2185 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2186 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2187
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2188 { /* Precision. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2189 size_t length;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2190 char *result =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2191 my_asnprintf (NULL, &length, "%.e %d", 1234.0, 33, 44, 55);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2192 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
2193 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
2194 || strcmp (result, "1e+003 33") == 0);
8836
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2195 ASSERT (length == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2196 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2197 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2198
9938
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
2199 { /* Precision with no rounding. */
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
2200 size_t length;
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
2201 char *result =
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
2202 my_asnprintf (NULL, &length, "%.4e %d", 999.951, 33, 44, 55);
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
2203 ASSERT (result != NULL);
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
2204 ASSERT (strcmp (result, "9.9995e+02 33") == 0
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
2205 || strcmp (result, "9.9995e+002 33") == 0);
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
2206 ASSERT (length == strlen (result));
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
2207 free (result);
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
2208 }
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
2209
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
2210 { /* Precision with rounding. */
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
2211 size_t length;
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
2212 char *result =
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
2213 my_asnprintf (NULL, &length, "%.4e %d", 999.996, 33, 44, 55);
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
2214 ASSERT (result != NULL);
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
2215 ASSERT (strcmp (result, "1.0000e+03 33") == 0
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
2216 || strcmp (result, "1.0000e+003 33") == 0);
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
2217 ASSERT (length == strlen (result));
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
2218 free (result);
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
2219 }
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
2220
8836
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2221 { /* A positive number. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2222 size_t length;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2223 char *result =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2224 my_asnprintf (NULL, &length, "%Le %d", 12.75L, 33, 44, 55);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2225 ASSERT (result != NULL);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2226 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
2227 ASSERT (length == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2228 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2229 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2230
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2231 { /* A larger positive number. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2232 size_t length;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2233 char *result =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2234 my_asnprintf (NULL, &length, "%Le %d", 1234567.0L, 33, 44, 55);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2235 ASSERT (result != NULL);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2236 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
2237 ASSERT (length == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2238 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2239 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2240
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2241 { /* Small and large positive numbers. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2242 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
2243 {
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2244 { 1.234321234321234e-37L, "1.234321e-37" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2245 { 1.234321234321234e-36L, "1.234321e-36" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2246 { 1.234321234321234e-35L, "1.234321e-35" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2247 { 1.234321234321234e-34L, "1.234321e-34" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2248 { 1.234321234321234e-33L, "1.234321e-33" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2249 { 1.234321234321234e-32L, "1.234321e-32" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2250 { 1.234321234321234e-31L, "1.234321e-31" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2251 { 1.234321234321234e-30L, "1.234321e-30" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2252 { 1.234321234321234e-29L, "1.234321e-29" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2253 { 1.234321234321234e-28L, "1.234321e-28" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2254 { 1.234321234321234e-27L, "1.234321e-27" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2255 { 1.234321234321234e-26L, "1.234321e-26" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2256 { 1.234321234321234e-25L, "1.234321e-25" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2257 { 1.234321234321234e-24L, "1.234321e-24" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2258 { 1.234321234321234e-23L, "1.234321e-23" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2259 { 1.234321234321234e-22L, "1.234321e-22" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2260 { 1.234321234321234e-21L, "1.234321e-21" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2261 { 1.234321234321234e-20L, "1.234321e-20" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2262 { 1.234321234321234e-19L, "1.234321e-19" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2263 { 1.234321234321234e-18L, "1.234321e-18" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2264 { 1.234321234321234e-17L, "1.234321e-17" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2265 { 1.234321234321234e-16L, "1.234321e-16" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2266 { 1.234321234321234e-15L, "1.234321e-15" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2267 { 1.234321234321234e-14L, "1.234321e-14" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2268 { 1.234321234321234e-13L, "1.234321e-13" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2269 { 1.234321234321234e-12L, "1.234321e-12" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2270 { 1.234321234321234e-11L, "1.234321e-11" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2271 { 1.234321234321234e-10L, "1.234321e-10" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2272 { 1.234321234321234e-9L, "1.234321e-09" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2273 { 1.234321234321234e-8L, "1.234321e-08" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2274 { 1.234321234321234e-7L, "1.234321e-07" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2275 { 1.234321234321234e-6L, "1.234321e-06" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2276 { 1.234321234321234e-5L, "1.234321e-05" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2277 { 1.234321234321234e-4L, "1.234321e-04" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2278 { 1.234321234321234e-3L, "1.234321e-03" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2279 { 1.234321234321234e-2L, "1.234321e-02" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2280 { 1.234321234321234e-1L, "1.234321e-01" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2281 { 1.234321234321234L, "1.234321e+00" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2282 { 1.234321234321234e1L, "1.234321e+01" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2283 { 1.234321234321234e2L, "1.234321e+02" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2284 { 1.234321234321234e3L, "1.234321e+03" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2285 { 1.234321234321234e4L, "1.234321e+04" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2286 { 1.234321234321234e5L, "1.234321e+05" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2287 { 1.234321234321234e6L, "1.234321e+06" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2288 { 1.234321234321234e7L, "1.234321e+07" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2289 { 1.234321234321234e8L, "1.234321e+08" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2290 { 1.234321234321234e9L, "1.234321e+09" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2291 { 1.234321234321234e10L, "1.234321e+10" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2292 { 1.234321234321234e11L, "1.234321e+11" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2293 { 1.234321234321234e12L, "1.234321e+12" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2294 { 1.234321234321234e13L, "1.234321e+13" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2295 { 1.234321234321234e14L, "1.234321e+14" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2296 { 1.234321234321234e15L, "1.234321e+15" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2297 { 1.234321234321234e16L, "1.234321e+16" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2298 { 1.234321234321234e17L, "1.234321e+17" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2299 { 1.234321234321234e18L, "1.234321e+18" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2300 { 1.234321234321234e19L, "1.234321e+19" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2301 { 1.234321234321234e20L, "1.234321e+20" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2302 { 1.234321234321234e21L, "1.234321e+21" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2303 { 1.234321234321234e22L, "1.234321e+22" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2304 { 1.234321234321234e23L, "1.234321e+23" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2305 { 1.234321234321234e24L, "1.234321e+24" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2306 { 1.234321234321234e25L, "1.234321e+25" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2307 { 1.234321234321234e26L, "1.234321e+26" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2308 { 1.234321234321234e27L, "1.234321e+27" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2309 { 1.234321234321234e28L, "1.234321e+28" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2310 { 1.234321234321234e29L, "1.234321e+29" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2311 { 1.234321234321234e30L, "1.234321e+30" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2312 { 1.234321234321234e31L, "1.234321e+31" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2313 { 1.234321234321234e32L, "1.234321e+32" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2314 { 1.234321234321234e33L, "1.234321e+33" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2315 { 1.234321234321234e34L, "1.234321e+34" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2316 { 1.234321234321234e35L, "1.234321e+35" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2317 { 1.234321234321234e36L, "1.234321e+36" }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2318 };
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2319 size_t k;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2320 for (k = 0; k < SIZEOF (data); k++)
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2321 {
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2322 size_t length;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2323 char *result =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2324 my_asnprintf (NULL, &length, "%Le", data[k].value);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2325 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
2326 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
2327 ASSERT (length == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2328 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2329 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2330 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2331
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2332 { /* A negative number. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2333 size_t length;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2334 char *result =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2335 my_asnprintf (NULL, &length, "%Le %d", -0.03125L, 33, 44, 55);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2336 ASSERT (result != NULL);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2337 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
2338 ASSERT (length == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2339 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2340 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2341
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2342 { /* Positive zero. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2343 size_t length;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2344 char *result =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2345 my_asnprintf (NULL, &length, "%Le %d", 0.0L, 33, 44, 55);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2346 ASSERT (result != NULL);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2347 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
2348 ASSERT (length == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2349 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2350 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2351
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2352 { /* Negative zero. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2353 size_t length;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2354 char *result =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2355 my_asnprintf (NULL, &length, "%Le %d", -0.0L, 33, 44, 55);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2356 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
2357 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
2358 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
2359 ASSERT (length == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2360 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2361 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2362
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2363 { /* Positive infinity. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2364 size_t length;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2365 char *result =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2366 my_asnprintf (NULL, &length, "%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
2367 ASSERT (result != NULL);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2368 ASSERT (strcmp (result, "inf 33") == 0
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2369 || strcmp (result, "infinity 33") == 0);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2370 ASSERT (length == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2371 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2372 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2373
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2374 { /* Negative infinity. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2375 size_t length;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2376 char *result =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2377 my_asnprintf (NULL, &length, "%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
2378 ASSERT (result != NULL);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2379 ASSERT (strcmp (result, "-inf 33") == 0
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2380 || strcmp (result, "-infinity 33") == 0);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2381 ASSERT (length == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2382 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2383 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2384
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2385 { /* NaN. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2386 size_t length;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2387 char *result =
9854
baba3b346ab2 Use macros NaNf, NaNd, NaNl instead of NAN.
Bruno Haible <bruno@clisp.org>
parents: 9850
diff changeset
2388 my_asnprintf (NULL, &length, "%Le %d", NaNl (), 33, 44, 55);
8836
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2389 ASSERT (result != NULL);
8850
d1fe16dfbfee Avoid test failures on IRIX 6.5.
Bruno Haible <bruno@clisp.org>
parents: 8839
diff changeset
2390 ASSERT (strlen (result) >= 3 + 3
8865
9e203d8ade65 Stricter check for printf result for NaN arguments.
Bruno Haible <bruno@clisp.org>
parents: 8857
diff changeset
2391 && strisnan (result, 0, strlen (result) - 3, 0)
8850
d1fe16dfbfee Avoid test failures on IRIX 6.5.
Bruno Haible <bruno@clisp.org>
parents: 8839
diff changeset
2392 && 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
2393 ASSERT (length == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2394 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2395 }
8919
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2396 #if CHECK_PRINTF_SAFE && ((defined __ia64 && LDBL_MANT_DIG == 64) || (defined __x86_64__ || defined __amd64__) || (defined __i386 || defined __i386__ || defined _I386 || defined _M_IX86 || defined _X86_))
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2397 { /* Quiet NaN. */
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2398 static union { unsigned int word[4]; long double value; } x =
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2399 { LDBL80_WORDS (0xFFFF, 0xC3333333, 0x00000000) };
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2400 size_t length;
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2401 char *result =
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2402 my_asnprintf (NULL, &length, "%Le %d", x.value, 33, 44, 55);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2403 ASSERT (result != NULL);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2404 ASSERT (strlen (result) >= 3 + 3
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2405 && strisnan (result, 0, strlen (result) - 3, 0)
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2406 && strcmp (result + strlen (result) - 3, " 33") == 0);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2407 ASSERT (length == strlen (result));
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2408 free (result);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2409 }
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2410 {
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2411 /* Signalling NaN. */
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2412 static union { unsigned int word[4]; long double value; } x =
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2413 { LDBL80_WORDS (0xFFFF, 0x83333333, 0x00000000) };
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2414 size_t length;
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2415 char *result =
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2416 my_asnprintf (NULL, &length, "%Le %d", x.value, 33, 44, 55);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2417 ASSERT (result != NULL);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2418 ASSERT (strlen (result) >= 3 + 3
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2419 && strisnan (result, 0, strlen (result) - 3, 0)
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2420 && strcmp (result + strlen (result) - 3, " 33") == 0);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2421 ASSERT (length == strlen (result));
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2422 free (result);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2423 }
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2424 /* The isnanl function should recognize Pseudo-NaNs, Pseudo-Infinities,
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2425 Pseudo-Zeroes, Unnormalized Numbers, and Pseudo-Denormals, as defined in
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2426 Intel IA-64 Architecture Software Developer's Manual, Volume 1:
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2427 Application Architecture.
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2428 Table 5-2 "Floating-Point Register Encodings"
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2429 Figure 5-6 "Memory to Floating-Point Register Data Translation"
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2430 */
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2431 { /* Pseudo-NaN. */
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2432 static union { unsigned int word[4]; long double value; } x =
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2433 { LDBL80_WORDS (0xFFFF, 0x40000001, 0x00000000) };
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2434 size_t length;
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2435 char *result =
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2436 my_asnprintf (NULL, &length, "%Le %d", x.value, 33, 44, 55);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2437 ASSERT (result != NULL);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2438 ASSERT (strlen (result) >= 3 + 3
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2439 && strisnan (result, 0, strlen (result) - 3, 0)
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2440 && strcmp (result + strlen (result) - 3, " 33") == 0);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2441 ASSERT (length == strlen (result));
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2442 free (result);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2443 }
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2444 { /* Pseudo-Infinity. */
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2445 static union { unsigned int word[4]; long double value; } x =
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2446 { LDBL80_WORDS (0xFFFF, 0x00000000, 0x00000000) };
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2447 size_t length;
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2448 char *result =
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2449 my_asnprintf (NULL, &length, "%Le %d", x.value, 33, 44, 55);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2450 ASSERT (result != NULL);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2451 ASSERT (strlen (result) >= 3 + 3
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2452 && strisnan (result, 0, strlen (result) - 3, 0)
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2453 && strcmp (result + strlen (result) - 3, " 33") == 0);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2454 ASSERT (length == strlen (result));
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2455 free (result);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2456 }
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2457 { /* Pseudo-Zero. */
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2458 static union { unsigned int word[4]; long double value; } x =
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2459 { LDBL80_WORDS (0x4004, 0x00000000, 0x00000000) };
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2460 size_t length;
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2461 char *result =
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2462 my_asnprintf (NULL, &length, "%Le %d", x.value, 33, 44, 55);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2463 ASSERT (result != NULL);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2464 ASSERT (strlen (result) >= 3 + 3
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2465 && strisnan (result, 0, strlen (result) - 3, 0)
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2466 && strcmp (result + strlen (result) - 3, " 33") == 0);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2467 ASSERT (length == strlen (result));
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2468 free (result);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2469 }
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2470 { /* Unnormalized number. */
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2471 static union { unsigned int word[4]; long double value; } x =
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2472 { LDBL80_WORDS (0x4000, 0x63333333, 0x00000000) };
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2473 size_t length;
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2474 char *result =
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2475 my_asnprintf (NULL, &length, "%Le %d", x.value, 33, 44, 55);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2476 ASSERT (result != NULL);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2477 ASSERT (strlen (result) >= 3 + 3
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2478 && strisnan (result, 0, strlen (result) - 3, 0)
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2479 && strcmp (result + strlen (result) - 3, " 33") == 0);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2480 ASSERT (length == strlen (result));
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2481 free (result);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2482 }
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2483 { /* Pseudo-Denormal. */
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2484 static union { unsigned int word[4]; long double value; } x =
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2485 { LDBL80_WORDS (0x0000, 0x83333333, 0x00000000) };
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2486 size_t length;
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2487 char *result =
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2488 my_asnprintf (NULL, &length, "%Le %d", x.value, 33, 44, 55);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2489 ASSERT (result != NULL);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2490 ASSERT (strlen (result) >= 3 + 3
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2491 && strisnan (result, 0, strlen (result) - 3, 0)
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2492 && strcmp (result + strlen (result) - 3, " 33") == 0);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2493 ASSERT (length == strlen (result));
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2494 free (result);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2495 }
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
2496 #endif
8836
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2497
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2498 { /* Width. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2499 size_t length;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2500 char *result =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2501 my_asnprintf (NULL, &length, "%15Le %d", 1.75L, 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.750000e+00 33") == 0);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2504 ASSERT (length == 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 { /* FLAG_LEFT. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2509 size_t length;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2510 char *result =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2511 my_asnprintf (NULL, &length, "%-15Le %d", 1.75L, 33, 44, 55);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2512 ASSERT (result != NULL);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2513 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
2514 ASSERT (length == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2515 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2516 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2517
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2518 { /* FLAG_SHOWSIGN. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2519 size_t length;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2520 char *result =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2521 my_asnprintf (NULL, &length, "%+Le %d", 1.75L, 33, 44, 55);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2522 ASSERT (result != NULL);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2523 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
2524 ASSERT (length == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2525 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2526 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2527
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2528 { /* FLAG_SPACE. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2529 size_t length;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2530 char *result =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2531 my_asnprintf (NULL, &length, "% Le %d", 1.75L, 33, 44, 55);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2532 ASSERT (result != NULL);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2533 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
2534 ASSERT (length == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2535 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2536 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2537
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2538 { /* FLAG_ALT. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2539 size_t length;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2540 char *result =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2541 my_asnprintf (NULL, &length, "%#Le %d", 1.75L, 33, 44, 55);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2542 ASSERT (result != NULL);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2543 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
2544 ASSERT (length == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2545 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2546 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2547
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2548 { /* FLAG_ALT. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2549 size_t length;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2550 char *result =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2551 my_asnprintf (NULL, &length, "%#.Le %d", 1.75L, 33, 44, 55);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2552 ASSERT (result != NULL);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2553 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
2554 ASSERT (length == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2555 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2556 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2557
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2558 { /* FLAG_ALT. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2559 size_t length;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2560 char *result =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2561 my_asnprintf (NULL, &length, "%#.Le %d", 9.75L, 33, 44, 55);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2562 ASSERT (result != NULL);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2563 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
2564 ASSERT (length == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2565 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2566 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2567
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2568 { /* FLAG_ZERO with finite number. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2569 size_t length;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2570 char *result =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2571 my_asnprintf (NULL, &length, "%015Le %d", 1234.0L, 33, 44, 55);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2572 ASSERT (result != NULL);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2573 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
2574 ASSERT (length == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2575 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2576 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2577
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2578 { /* FLAG_ZERO with infinite number. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2579 size_t length;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2580 char *result =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2581 my_asnprintf (NULL, &length, "%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
2582 ASSERT (result != NULL);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2583 ASSERT (strcmp (result, " -inf 33") == 0
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2584 || strcmp (result, " -infinity 33") == 0);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2585 ASSERT (length == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2586 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2587 }
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 { /* FLAG_ZERO with NaN. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2590 size_t length;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2591 char *result =
9854
baba3b346ab2 Use macros NaNf, NaNd, NaNl instead of NAN.
Bruno Haible <bruno@clisp.org>
parents: 9850
diff changeset
2592 my_asnprintf (NULL, &length, "%050Le %d", NaNl (), 33, 44, 55);
8836
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2593 ASSERT (result != NULL);
8870
4e1f2ea486b4 Allow for a longer printed representation of NaN.
Bruno Haible <bruno@clisp.org>
parents: 8865
diff changeset
2594 ASSERT (strlen (result) == 50 + 3
8865
9e203d8ade65 Stricter check for printf result for NaN arguments.
Bruno Haible <bruno@clisp.org>
parents: 8857
diff changeset
2595 && strisnan (result, strspn (result, " "), strlen (result) - 3, 0)
8850
d1fe16dfbfee Avoid test failures on IRIX 6.5.
Bruno Haible <bruno@clisp.org>
parents: 8839
diff changeset
2596 && 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
2597 ASSERT (length == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2598 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2599 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2600
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2601 { /* Precision. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2602 size_t length;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2603 char *result =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2604 my_asnprintf (NULL, &length, "%.Le %d", 1234.0L, 33, 44, 55);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2605 ASSERT (result != NULL);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2606 ASSERT (strcmp (result, "1e+03 33") == 0);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2607 ASSERT (length == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2608 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2609 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2610
9938
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
2611 { /* Precision with no rounding. */
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
2612 size_t length;
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
2613 char *result =
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
2614 my_asnprintf (NULL, &length, "%.4Le %d", 999.951L, 33, 44, 55);
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
2615 ASSERT (result != NULL);
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
2616 ASSERT (strcmp (result, "9.9995e+02 33") == 0);
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
2617 ASSERT (length == strlen (result));
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
2618 free (result);
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
2619 }
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
2620
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
2621 { /* Precision with rounding. */
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
2622 size_t length;
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
2623 char *result =
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
2624 my_asnprintf (NULL, &length, "%.4Le %d", 999.996L, 33, 44, 55);
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
2625 ASSERT (result != NULL);
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
2626 ASSERT (strcmp (result, "1.0000e+03 33") == 0);
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
2627 ASSERT (length == strlen (result));
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
2628 free (result);
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
2629 }
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
2630
8836
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2631 /* 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
2632
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2633 { /* A positive number. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2634 size_t length;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2635 char *result =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2636 my_asnprintf (NULL, &length, "%g %d", 12.75, 33, 44, 55);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2637 ASSERT (result != NULL);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2638 ASSERT (strcmp (result, "12.75 33") == 0);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2639 ASSERT (length == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2640 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2641 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2642
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2643 { /* A larger positive number. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2644 size_t length;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2645 char *result =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2646 my_asnprintf (NULL, &length, "%g %d", 1234567.0, 33, 44, 55);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2647 ASSERT (result != NULL);
8839
5efc1d668039 Accomodate for implementations that produce 3 exponent digits in %e and %g.
Bruno Haible <bruno@clisp.org>
parents: 8836
diff changeset
2648 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
2649 || 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
2650 ASSERT (length == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2651 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2652 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2653
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2654 { /* Small and large positive numbers. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2655 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
2656 {
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2657 { 1.234321234321234e-37, "1.23432e-37" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2658 { 1.234321234321234e-36, "1.23432e-36" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2659 { 1.234321234321234e-35, "1.23432e-35" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2660 { 1.234321234321234e-34, "1.23432e-34" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2661 { 1.234321234321234e-33, "1.23432e-33" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2662 { 1.234321234321234e-32, "1.23432e-32" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2663 { 1.234321234321234e-31, "1.23432e-31" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2664 { 1.234321234321234e-30, "1.23432e-30" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2665 { 1.234321234321234e-29, "1.23432e-29" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2666 { 1.234321234321234e-28, "1.23432e-28" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2667 { 1.234321234321234e-27, "1.23432e-27" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2668 { 1.234321234321234e-26, "1.23432e-26" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2669 { 1.234321234321234e-25, "1.23432e-25" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2670 { 1.234321234321234e-24, "1.23432e-24" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2671 { 1.234321234321234e-23, "1.23432e-23" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2672 { 1.234321234321234e-22, "1.23432e-22" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2673 { 1.234321234321234e-21, "1.23432e-21" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2674 { 1.234321234321234e-20, "1.23432e-20" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2675 { 1.234321234321234e-19, "1.23432e-19" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2676 { 1.234321234321234e-18, "1.23432e-18" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2677 { 1.234321234321234e-17, "1.23432e-17" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2678 { 1.234321234321234e-16, "1.23432e-16" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2679 { 1.234321234321234e-15, "1.23432e-15" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2680 { 1.234321234321234e-14, "1.23432e-14" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2681 { 1.234321234321234e-13, "1.23432e-13" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2682 { 1.234321234321234e-12, "1.23432e-12" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2683 { 1.234321234321234e-11, "1.23432e-11" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2684 { 1.234321234321234e-10, "1.23432e-10" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2685 { 1.234321234321234e-9, "1.23432e-09" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2686 { 1.234321234321234e-8, "1.23432e-08" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2687 { 1.234321234321234e-7, "1.23432e-07" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2688 { 1.234321234321234e-6, "1.23432e-06" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2689 { 1.234321234321234e-5, "1.23432e-05" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2690 { 1.234321234321234e-4, "0.000123432" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2691 { 1.234321234321234e-3, "0.00123432" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2692 { 1.234321234321234e-2, "0.0123432" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2693 { 1.234321234321234e-1, "0.123432" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2694 { 1.234321234321234, "1.23432" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2695 { 1.234321234321234e1, "12.3432" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2696 { 1.234321234321234e2, "123.432" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2697 { 1.234321234321234e3, "1234.32" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2698 { 1.234321234321234e4, "12343.2" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2699 { 1.234321234321234e5, "123432" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2700 { 1.234321234321234e6, "1.23432e+06" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2701 { 1.234321234321234e7, "1.23432e+07" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2702 { 1.234321234321234e8, "1.23432e+08" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2703 { 1.234321234321234e9, "1.23432e+09" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2704 { 1.234321234321234e10, "1.23432e+10" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2705 { 1.234321234321234e11, "1.23432e+11" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2706 { 1.234321234321234e12, "1.23432e+12" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2707 { 1.234321234321234e13, "1.23432e+13" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2708 { 1.234321234321234e14, "1.23432e+14" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2709 { 1.234321234321234e15, "1.23432e+15" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2710 { 1.234321234321234e16, "1.23432e+16" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2711 { 1.234321234321234e17, "1.23432e+17" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2712 { 1.234321234321234e18, "1.23432e+18" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2713 { 1.234321234321234e19, "1.23432e+19" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2714 { 1.234321234321234e20, "1.23432e+20" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2715 { 1.234321234321234e21, "1.23432e+21" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2716 { 1.234321234321234e22, "1.23432e+22" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2717 { 1.234321234321234e23, "1.23432e+23" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2718 { 1.234321234321234e24, "1.23432e+24" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2719 { 1.234321234321234e25, "1.23432e+25" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2720 { 1.234321234321234e26, "1.23432e+26" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2721 { 1.234321234321234e27, "1.23432e+27" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2722 { 1.234321234321234e28, "1.23432e+28" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2723 { 1.234321234321234e29, "1.23432e+29" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2724 { 1.234321234321234e30, "1.23432e+30" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2725 { 1.234321234321234e31, "1.23432e+31" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2726 { 1.234321234321234e32, "1.23432e+32" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2727 { 1.234321234321234e33, "1.23432e+33" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2728 { 1.234321234321234e34, "1.23432e+34" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2729 { 1.234321234321234e35, "1.23432e+35" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2730 { 1.234321234321234e36, "1.23432e+36" }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2731 };
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2732 size_t k;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2733 for (k = 0; k < SIZEOF (data); k++)
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 size_t length;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2736 char *result =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2737 my_asnprintf (NULL, &length, "%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
2738 const char *expected = data[k].string;
8836
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2739 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
2740 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
2741 /* 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
2742 || (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
2743 && 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
2744 && 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
2745 && 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
2746 && 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
2747 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
2748 == 0));
8836
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2749 ASSERT (length == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2750 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2751 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2752 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2753
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2754 { /* A negative number. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2755 size_t length;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2756 char *result =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2757 my_asnprintf (NULL, &length, "%g %d", -0.03125, 33, 44, 55);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2758 ASSERT (result != NULL);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2759 ASSERT (strcmp (result, "-0.03125 33") == 0);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2760 ASSERT (length == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2761 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2762 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2763
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2764 { /* Positive zero. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2765 size_t length;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2766 char *result =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2767 my_asnprintf (NULL, &length, "%g %d", 0.0, 33, 44, 55);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2768 ASSERT (result != NULL);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2769 ASSERT (strcmp (result, "0 33") == 0);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2770 ASSERT (length == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2771 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2772 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2773
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2774 { /* Negative zero. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2775 size_t length;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2776 char *result =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2777 my_asnprintf (NULL, &length, "%g %d", -0.0, 33, 44, 55);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2778 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
2779 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
2780 ASSERT (strcmp (result, "-0 33") == 0);
8836
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2781 ASSERT (length == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2782 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2783 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2784
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2785 { /* Positive infinity. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2786 size_t length;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2787 char *result =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2788 my_asnprintf (NULL, &length, "%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
2789 ASSERT (result != NULL);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2790 ASSERT (strcmp (result, "inf 33") == 0
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2791 || strcmp (result, "infinity 33") == 0);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2792 ASSERT (length == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2793 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2794 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2795
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2796 { /* Negative infinity. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2797 size_t length;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2798 char *result =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2799 my_asnprintf (NULL, &length, "%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
2800 ASSERT (result != NULL);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2801 ASSERT (strcmp (result, "-inf 33") == 0
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2802 || strcmp (result, "-infinity 33") == 0);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2803 ASSERT (length == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2804 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2805 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2806
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2807 { /* NaN. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2808 size_t length;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2809 char *result =
9854
baba3b346ab2 Use macros NaNf, NaNd, NaNl instead of NAN.
Bruno Haible <bruno@clisp.org>
parents: 9850
diff changeset
2810 my_asnprintf (NULL, &length, "%g %d", NaNd (), 33, 44, 55);
8836
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2811 ASSERT (result != NULL);
8850
d1fe16dfbfee Avoid test failures on IRIX 6.5.
Bruno Haible <bruno@clisp.org>
parents: 8839
diff changeset
2812 ASSERT (strlen (result) >= 3 + 3
8865
9e203d8ade65 Stricter check for printf result for NaN arguments.
Bruno Haible <bruno@clisp.org>
parents: 8857
diff changeset
2813 && strisnan (result, 0, strlen (result) - 3, 0)
8850
d1fe16dfbfee Avoid test failures on IRIX 6.5.
Bruno Haible <bruno@clisp.org>
parents: 8839
diff changeset
2814 && 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
2815 ASSERT (length == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2816 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2817 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2818
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2819 { /* Width. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2820 size_t length;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2821 char *result =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2822 my_asnprintf (NULL, &length, "%10g %d", 1.75, 33, 44, 55);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2823 ASSERT (result != NULL);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2824 ASSERT (strcmp (result, " 1.75 33") == 0);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2825 ASSERT (length == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2826 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2827 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2828
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2829 { /* FLAG_LEFT. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2830 size_t length;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2831 char *result =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2832 my_asnprintf (NULL, &length, "%-10g %d", 1.75, 33, 44, 55);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2833 ASSERT (result != NULL);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2834 ASSERT (strcmp (result, "1.75 33") == 0);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2835 ASSERT (length == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2836 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2837 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2838
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2839 { /* FLAG_SHOWSIGN. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2840 size_t length;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2841 char *result =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2842 my_asnprintf (NULL, &length, "%+g %d", 1.75, 33, 44, 55);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2843 ASSERT (result != NULL);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2844 ASSERT (strcmp (result, "+1.75 33") == 0);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2845 ASSERT (length == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2846 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2847 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2848
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2849 { /* FLAG_SPACE. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2850 size_t length;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2851 char *result =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2852 my_asnprintf (NULL, &length, "% g %d", 1.75, 33, 44, 55);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2853 ASSERT (result != NULL);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2854 ASSERT (strcmp (result, " 1.75 33") == 0);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2855 ASSERT (length == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2856 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2857 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2858
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2859 { /* FLAG_ALT. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2860 size_t length;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2861 char *result =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2862 my_asnprintf (NULL, &length, "%#g %d", 1.75, 33, 44, 55);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2863 ASSERT (result != NULL);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2864 ASSERT (strcmp (result, "1.75000 33") == 0);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2865 ASSERT (length == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2866 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2867 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2868
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2869 { /* FLAG_ALT. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2870 size_t length;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2871 char *result =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2872 my_asnprintf (NULL, &length, "%#.g %d", 1.75, 33, 44, 55);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2873 ASSERT (result != NULL);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2874 ASSERT (strcmp (result, "2. 33") == 0);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2875 ASSERT (length == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2876 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2877 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2878
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2879 { /* FLAG_ALT. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2880 size_t length;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2881 char *result =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2882 my_asnprintf (NULL, &length, "%#.g %d", 9.75, 33, 44, 55);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2883 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
2884 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
2885 || 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
2886 ASSERT (length == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2887 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2888 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2889
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2890 { /* FLAG_ZERO with finite number. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2891 size_t length;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2892 char *result =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2893 my_asnprintf (NULL, &length, "%010g %d", 1234.0, 33, 44, 55);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2894 ASSERT (result != NULL);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2895 ASSERT (strcmp (result, "0000001234 33") == 0);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2896 ASSERT (length == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2897 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2898 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2899
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2900 { /* FLAG_ZERO with infinite number. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2901 size_t length;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2902 char *result =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2903 my_asnprintf (NULL, &length, "%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
2904 ASSERT (result != NULL);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2905 ASSERT (strcmp (result, " -inf 33") == 0
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2906 || strcmp (result, " -infinity 33") == 0);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2907 ASSERT (length == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2908 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2909 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2910
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2911 { /* FLAG_ZERO with NaN. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2912 size_t length;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2913 char *result =
9854
baba3b346ab2 Use macros NaNf, NaNd, NaNl instead of NAN.
Bruno Haible <bruno@clisp.org>
parents: 9850
diff changeset
2914 my_asnprintf (NULL, &length, "%050g %d", NaNd (), 33, 44, 55);
8836
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2915 ASSERT (result != NULL);
8870
4e1f2ea486b4 Allow for a longer printed representation of NaN.
Bruno Haible <bruno@clisp.org>
parents: 8865
diff changeset
2916 ASSERT (strlen (result) == 50 + 3
8865
9e203d8ade65 Stricter check for printf result for NaN arguments.
Bruno Haible <bruno@clisp.org>
parents: 8857
diff changeset
2917 && strisnan (result, strspn (result, " "), strlen (result) - 3, 0)
8850
d1fe16dfbfee Avoid test failures on IRIX 6.5.
Bruno Haible <bruno@clisp.org>
parents: 8839
diff changeset
2918 && 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
2919 ASSERT (length == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2920 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2921 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2922
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2923 { /* Precision. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2924 size_t length;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2925 char *result =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2926 my_asnprintf (NULL, &length, "%.g %d", 1234.0, 33, 44, 55);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2927 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
2928 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
2929 || strcmp (result, "1e+003 33") == 0);
8836
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2930 ASSERT (length == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2931 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2932 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2933
9938
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
2934 { /* Precision with no rounding. */
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
2935 size_t length;
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
2936 char *result =
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
2937 my_asnprintf (NULL, &length, "%.5g %d", 999.951, 33, 44, 55);
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
2938 ASSERT (result != NULL);
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
2939 ASSERT (strcmp (result, "999.95 33") == 0);
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
2940 ASSERT (length == strlen (result));
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
2941 free (result);
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
2942 }
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
2943
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
2944 { /* Precision with rounding. */
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
2945 size_t length;
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
2946 char *result =
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
2947 my_asnprintf (NULL, &length, "%.5g %d", 999.996, 33, 44, 55);
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
2948 ASSERT (result != NULL);
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
2949 ASSERT (strcmp (result, "1000 33") == 0);
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
2950 ASSERT (length == strlen (result));
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
2951 free (result);
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
2952 }
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
2953
8836
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2954 { /* A positive number. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2955 size_t length;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2956 char *result =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2957 my_asnprintf (NULL, &length, "%Lg %d", 12.75L, 33, 44, 55);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2958 ASSERT (result != NULL);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2959 ASSERT (strcmp (result, "12.75 33") == 0);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2960 ASSERT (length == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2961 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2962 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2963
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2964 { /* A larger positive number. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2965 size_t length;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2966 char *result =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2967 my_asnprintf (NULL, &length, "%Lg %d", 1234567.0L, 33, 44, 55);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2968 ASSERT (result != NULL);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2969 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
2970 ASSERT (length == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2971 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2972 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2973
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2974 { /* Small and large positive numbers. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2975 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
2976 {
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2977 { 1.234321234321234e-37L, "1.23432e-37" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2978 { 1.234321234321234e-36L, "1.23432e-36" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2979 { 1.234321234321234e-35L, "1.23432e-35" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2980 { 1.234321234321234e-34L, "1.23432e-34" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2981 { 1.234321234321234e-33L, "1.23432e-33" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2982 { 1.234321234321234e-32L, "1.23432e-32" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2983 { 1.234321234321234e-31L, "1.23432e-31" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2984 { 1.234321234321234e-30L, "1.23432e-30" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2985 { 1.234321234321234e-29L, "1.23432e-29" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2986 { 1.234321234321234e-28L, "1.23432e-28" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2987 { 1.234321234321234e-27L, "1.23432e-27" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2988 { 1.234321234321234e-26L, "1.23432e-26" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2989 { 1.234321234321234e-25L, "1.23432e-25" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2990 { 1.234321234321234e-24L, "1.23432e-24" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2991 { 1.234321234321234e-23L, "1.23432e-23" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2992 { 1.234321234321234e-22L, "1.23432e-22" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2993 { 1.234321234321234e-21L, "1.23432e-21" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2994 { 1.234321234321234e-20L, "1.23432e-20" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2995 { 1.234321234321234e-19L, "1.23432e-19" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2996 { 1.234321234321234e-18L, "1.23432e-18" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2997 { 1.234321234321234e-17L, "1.23432e-17" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2998 { 1.234321234321234e-16L, "1.23432e-16" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
2999 { 1.234321234321234e-15L, "1.23432e-15" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3000 { 1.234321234321234e-14L, "1.23432e-14" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3001 { 1.234321234321234e-13L, "1.23432e-13" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3002 { 1.234321234321234e-12L, "1.23432e-12" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3003 { 1.234321234321234e-11L, "1.23432e-11" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3004 { 1.234321234321234e-10L, "1.23432e-10" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3005 { 1.234321234321234e-9L, "1.23432e-09" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3006 { 1.234321234321234e-8L, "1.23432e-08" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3007 { 1.234321234321234e-7L, "1.23432e-07" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3008 { 1.234321234321234e-6L, "1.23432e-06" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3009 { 1.234321234321234e-5L, "1.23432e-05" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3010 { 1.234321234321234e-4L, "0.000123432" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3011 { 1.234321234321234e-3L, "0.00123432" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3012 { 1.234321234321234e-2L, "0.0123432" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3013 { 1.234321234321234e-1L, "0.123432" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3014 { 1.234321234321234L, "1.23432" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3015 { 1.234321234321234e1L, "12.3432" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3016 { 1.234321234321234e2L, "123.432" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3017 { 1.234321234321234e3L, "1234.32" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3018 { 1.234321234321234e4L, "12343.2" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3019 { 1.234321234321234e5L, "123432" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3020 { 1.234321234321234e6L, "1.23432e+06" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3021 { 1.234321234321234e7L, "1.23432e+07" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3022 { 1.234321234321234e8L, "1.23432e+08" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3023 { 1.234321234321234e9L, "1.23432e+09" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3024 { 1.234321234321234e10L, "1.23432e+10" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3025 { 1.234321234321234e11L, "1.23432e+11" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3026 { 1.234321234321234e12L, "1.23432e+12" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3027 { 1.234321234321234e13L, "1.23432e+13" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3028 { 1.234321234321234e14L, "1.23432e+14" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3029 { 1.234321234321234e15L, "1.23432e+15" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3030 { 1.234321234321234e16L, "1.23432e+16" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3031 { 1.234321234321234e17L, "1.23432e+17" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3032 { 1.234321234321234e18L, "1.23432e+18" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3033 { 1.234321234321234e19L, "1.23432e+19" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3034 { 1.234321234321234e20L, "1.23432e+20" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3035 { 1.234321234321234e21L, "1.23432e+21" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3036 { 1.234321234321234e22L, "1.23432e+22" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3037 { 1.234321234321234e23L, "1.23432e+23" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3038 { 1.234321234321234e24L, "1.23432e+24" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3039 { 1.234321234321234e25L, "1.23432e+25" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3040 { 1.234321234321234e26L, "1.23432e+26" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3041 { 1.234321234321234e27L, "1.23432e+27" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3042 { 1.234321234321234e28L, "1.23432e+28" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3043 { 1.234321234321234e29L, "1.23432e+29" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3044 { 1.234321234321234e30L, "1.23432e+30" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3045 { 1.234321234321234e31L, "1.23432e+31" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3046 { 1.234321234321234e32L, "1.23432e+32" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3047 { 1.234321234321234e33L, "1.23432e+33" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3048 { 1.234321234321234e34L, "1.23432e+34" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3049 { 1.234321234321234e35L, "1.23432e+35" },
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3050 { 1.234321234321234e36L, "1.23432e+36" }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3051 };
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3052 size_t k;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3053 for (k = 0; k < SIZEOF (data); k++)
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3054 {
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3055 size_t length;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3056 char *result =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3057 my_asnprintf (NULL, &length, "%Lg", data[k].value);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3058 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
3059 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
3060 ASSERT (length == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3061 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3062 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3063 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3064
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3065 { /* A negative number. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3066 size_t length;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3067 char *result =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3068 my_asnprintf (NULL, &length, "%Lg %d", -0.03125L, 33, 44, 55);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3069 ASSERT (result != NULL);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3070 ASSERT (strcmp (result, "-0.03125 33") == 0);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3071 ASSERT (length == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3072 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3073 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3074
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3075 { /* Positive zero. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3076 size_t length;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3077 char *result =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3078 my_asnprintf (NULL, &length, "%Lg %d", 0.0L, 33, 44, 55);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3079 ASSERT (result != NULL);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3080 ASSERT (strcmp (result, "0 33") == 0);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3081 ASSERT (length == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3082 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3083 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3084
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3085 { /* Negative zero. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3086 size_t length;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3087 char *result =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3088 my_asnprintf (NULL, &length, "%Lg %d", -0.0L, 33, 44, 55);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3089 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
3090 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
3091 ASSERT (strcmp (result, "-0 33") == 0);
8836
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3092 ASSERT (length == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3093 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3094 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3095
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3096 { /* Positive infinity. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3097 size_t length;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3098 char *result =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3099 my_asnprintf (NULL, &length, "%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
3100 ASSERT (result != NULL);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3101 ASSERT (strcmp (result, "inf 33") == 0
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3102 || strcmp (result, "infinity 33") == 0);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3103 ASSERT (length == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3104 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3105 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3106
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3107 { /* Negative infinity. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3108 size_t length;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3109 char *result =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3110 my_asnprintf (NULL, &length, "%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
3111 ASSERT (result != NULL);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3112 ASSERT (strcmp (result, "-inf 33") == 0
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3113 || strcmp (result, "-infinity 33") == 0);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3114 ASSERT (length == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3115 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3116 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3117
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3118 { /* NaN. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3119 size_t length;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3120 char *result =
9854
baba3b346ab2 Use macros NaNf, NaNd, NaNl instead of NAN.
Bruno Haible <bruno@clisp.org>
parents: 9850
diff changeset
3121 my_asnprintf (NULL, &length, "%Lg %d", NaNl (), 33, 44, 55);
8836
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3122 ASSERT (result != NULL);
8850
d1fe16dfbfee Avoid test failures on IRIX 6.5.
Bruno Haible <bruno@clisp.org>
parents: 8839
diff changeset
3123 ASSERT (strlen (result) >= 3 + 3
8865
9e203d8ade65 Stricter check for printf result for NaN arguments.
Bruno Haible <bruno@clisp.org>
parents: 8857
diff changeset
3124 && strisnan (result, 0, strlen (result) - 3, 0)
8850
d1fe16dfbfee Avoid test failures on IRIX 6.5.
Bruno Haible <bruno@clisp.org>
parents: 8839
diff changeset
3125 && 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
3126 ASSERT (length == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3127 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3128 }
8919
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3129 #if CHECK_PRINTF_SAFE && ((defined __ia64 && LDBL_MANT_DIG == 64) || (defined __x86_64__ || defined __amd64__) || (defined __i386 || defined __i386__ || defined _I386 || defined _M_IX86 || defined _X86_))
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3130 { /* Quiet NaN. */
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3131 static union { unsigned int word[4]; long double value; } x =
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3132 { LDBL80_WORDS (0xFFFF, 0xC3333333, 0x00000000) };
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3133 size_t length;
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3134 char *result =
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3135 my_asnprintf (NULL, &length, "%Lg %d", x.value, 33, 44, 55);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3136 ASSERT (result != NULL);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3137 ASSERT (strlen (result) >= 3 + 3
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3138 && strisnan (result, 0, strlen (result) - 3, 0)
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3139 && strcmp (result + strlen (result) - 3, " 33") == 0);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3140 ASSERT (length == strlen (result));
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3141 free (result);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3142 }
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3143 {
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3144 /* Signalling NaN. */
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3145 static union { unsigned int word[4]; long double value; } x =
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3146 { LDBL80_WORDS (0xFFFF, 0x83333333, 0x00000000) };
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3147 size_t length;
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3148 char *result =
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3149 my_asnprintf (NULL, &length, "%Lg %d", x.value, 33, 44, 55);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3150 ASSERT (result != NULL);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3151 ASSERT (strlen (result) >= 3 + 3
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3152 && strisnan (result, 0, strlen (result) - 3, 0)
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3153 && strcmp (result + strlen (result) - 3, " 33") == 0);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3154 ASSERT (length == strlen (result));
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3155 free (result);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3156 }
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3157 /* The isnanl function should recognize Pseudo-NaNs, Pseudo-Infinities,
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3158 Pseudo-Zeroes, Unnormalized Numbers, and Pseudo-Denormals, as defined in
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3159 Intel IA-64 Architecture Software Developer's Manual, Volume 1:
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3160 Application Architecture.
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3161 Table 5-2 "Floating-Point Register Encodings"
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3162 Figure 5-6 "Memory to Floating-Point Register Data Translation"
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3163 */
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3164 { /* Pseudo-NaN. */
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3165 static union { unsigned int word[4]; long double value; } x =
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3166 { LDBL80_WORDS (0xFFFF, 0x40000001, 0x00000000) };
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3167 size_t length;
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3168 char *result =
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3169 my_asnprintf (NULL, &length, "%Lg %d", x.value, 33, 44, 55);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3170 ASSERT (result != NULL);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3171 ASSERT (strlen (result) >= 3 + 3
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3172 && strisnan (result, 0, strlen (result) - 3, 0)
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3173 && strcmp (result + strlen (result) - 3, " 33") == 0);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3174 ASSERT (length == strlen (result));
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3175 free (result);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3176 }
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3177 { /* Pseudo-Infinity. */
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3178 static union { unsigned int word[4]; long double value; } x =
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3179 { LDBL80_WORDS (0xFFFF, 0x00000000, 0x00000000) };
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3180 size_t length;
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3181 char *result =
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3182 my_asnprintf (NULL, &length, "%Lg %d", x.value, 33, 44, 55);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3183 ASSERT (result != NULL);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3184 ASSERT (strlen (result) >= 3 + 3
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3185 && strisnan (result, 0, strlen (result) - 3, 0)
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3186 && strcmp (result + strlen (result) - 3, " 33") == 0);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3187 ASSERT (length == strlen (result));
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3188 free (result);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3189 }
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3190 { /* Pseudo-Zero. */
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3191 static union { unsigned int word[4]; long double value; } x =
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3192 { LDBL80_WORDS (0x4004, 0x00000000, 0x00000000) };
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3193 size_t length;
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3194 char *result =
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3195 my_asnprintf (NULL, &length, "%Lg %d", x.value, 33, 44, 55);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3196 ASSERT (result != NULL);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3197 ASSERT (strlen (result) >= 3 + 3
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3198 && strisnan (result, 0, strlen (result) - 3, 0)
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3199 && strcmp (result + strlen (result) - 3, " 33") == 0);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3200 ASSERT (length == strlen (result));
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3201 free (result);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3202 }
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3203 { /* Unnormalized number. */
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3204 static union { unsigned int word[4]; long double value; } x =
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3205 { LDBL80_WORDS (0x4000, 0x63333333, 0x00000000) };
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3206 size_t length;
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3207 char *result =
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3208 my_asnprintf (NULL, &length, "%Lg %d", x.value, 33, 44, 55);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3209 ASSERT (result != NULL);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3210 ASSERT (strlen (result) >= 3 + 3
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3211 && strisnan (result, 0, strlen (result) - 3, 0)
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3212 && strcmp (result + strlen (result) - 3, " 33") == 0);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3213 ASSERT (length == strlen (result));
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3214 free (result);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3215 }
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3216 { /* Pseudo-Denormal. */
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3217 static union { unsigned int word[4]; long double value; } x =
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3218 { LDBL80_WORDS (0x0000, 0x83333333, 0x00000000) };
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3219 size_t length;
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3220 char *result =
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3221 my_asnprintf (NULL, &length, "%Lg %d", x.value, 33, 44, 55);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3222 ASSERT (result != NULL);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3223 ASSERT (strlen (result) >= 3 + 3
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3224 && strisnan (result, 0, strlen (result) - 3, 0)
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3225 && strcmp (result + strlen (result) - 3, " 33") == 0);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3226 ASSERT (length == strlen (result));
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3227 free (result);
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3228 }
42e2847583f9 Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
3229 #endif
8836
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3230
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3231 { /* Width. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3232 size_t length;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3233 char *result =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3234 my_asnprintf (NULL, &length, "%10Lg %d", 1.75L, 33, 44, 55);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3235 ASSERT (result != NULL);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3236 ASSERT (strcmp (result, " 1.75 33") == 0);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3237 ASSERT (length == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3238 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3239 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3240
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3241 { /* FLAG_LEFT. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3242 size_t length;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3243 char *result =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3244 my_asnprintf (NULL, &length, "%-10Lg %d", 1.75L, 33, 44, 55);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3245 ASSERT (result != NULL);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3246 ASSERT (strcmp (result, "1.75 33") == 0);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3247 ASSERT (length == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3248 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3249 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3250
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3251 { /* FLAG_SHOWSIGN. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3252 size_t length;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3253 char *result =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3254 my_asnprintf (NULL, &length, "%+Lg %d", 1.75L, 33, 44, 55);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3255 ASSERT (result != NULL);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3256 ASSERT (strcmp (result, "+1.75 33") == 0);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3257 ASSERT (length == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3258 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3259 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3260
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3261 { /* FLAG_SPACE. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3262 size_t length;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3263 char *result =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3264 my_asnprintf (NULL, &length, "% Lg %d", 1.75L, 33, 44, 55);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3265 ASSERT (result != NULL);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3266 ASSERT (strcmp (result, " 1.75 33") == 0);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3267 ASSERT (length == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3268 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3269 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3270
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3271 { /* FLAG_ALT. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3272 size_t length;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3273 char *result =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3274 my_asnprintf (NULL, &length, "%#Lg %d", 1.75L, 33, 44, 55);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3275 ASSERT (result != NULL);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3276 ASSERT (strcmp (result, "1.75000 33") == 0);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3277 ASSERT (length == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3278 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3279 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3280
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3281 { /* FLAG_ALT. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3282 size_t length;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3283 char *result =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3284 my_asnprintf (NULL, &length, "%#.Lg %d", 1.75L, 33, 44, 55);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3285 ASSERT (result != NULL);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3286 ASSERT (strcmp (result, "2. 33") == 0);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3287 ASSERT (length == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3288 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3289 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3290
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3291 { /* FLAG_ALT. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3292 size_t length;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3293 char *result =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3294 my_asnprintf (NULL, &length, "%#.Lg %d", 9.75L, 33, 44, 55);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3295 ASSERT (result != NULL);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3296 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
3297 ASSERT (length == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3298 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3299 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3300
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3301 { /* FLAG_ZERO with finite number. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3302 size_t length;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3303 char *result =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3304 my_asnprintf (NULL, &length, "%010Lg %d", 1234.0L, 33, 44, 55);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3305 ASSERT (result != NULL);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3306 ASSERT (strcmp (result, "0000001234 33") == 0);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3307 ASSERT (length == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3308 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3309 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3310
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3311 { /* FLAG_ZERO with infinite number. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3312 size_t length;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3313 char *result =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3314 my_asnprintf (NULL, &length, "%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
3315 ASSERT (result != NULL);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3316 ASSERT (strcmp (result, " -inf 33") == 0
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3317 || strcmp (result, " -infinity 33") == 0);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3318 ASSERT (length == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3319 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3320 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3321
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3322 { /* FLAG_ZERO with NaN. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3323 size_t length;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3324 char *result =
9854
baba3b346ab2 Use macros NaNf, NaNd, NaNl instead of NAN.
Bruno Haible <bruno@clisp.org>
parents: 9850
diff changeset
3325 my_asnprintf (NULL, &length, "%050Lg %d", NaNl (), 33, 44, 55);
8836
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3326 ASSERT (result != NULL);
8870
4e1f2ea486b4 Allow for a longer printed representation of NaN.
Bruno Haible <bruno@clisp.org>
parents: 8865
diff changeset
3327 ASSERT (strlen (result) == 50 + 3
8865
9e203d8ade65 Stricter check for printf result for NaN arguments.
Bruno Haible <bruno@clisp.org>
parents: 8857
diff changeset
3328 && strisnan (result, strspn (result, " "), strlen (result) - 3, 0)
8850
d1fe16dfbfee Avoid test failures on IRIX 6.5.
Bruno Haible <bruno@clisp.org>
parents: 8839
diff changeset
3329 && 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
3330 ASSERT (length == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3331 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3332 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3333
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3334 { /* Precision. */
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3335 size_t length;
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3336 char *result =
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3337 my_asnprintf (NULL, &length, "%.Lg %d", 1234.0L, 33, 44, 55);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3338 ASSERT (result != NULL);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3339 ASSERT (strcmp (result, "1e+03 33") == 0);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3340 ASSERT (length == strlen (result));
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3341 free (result);
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3342 }
07084ab003b8 Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents: 8834
diff changeset
3343
9938
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
3344 { /* Precision with no rounding. */
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
3345 size_t length;
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
3346 char *result =
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
3347 my_asnprintf (NULL, &length, "%.5Lg %d", 999.951L, 33, 44, 55);
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
3348 ASSERT (result != NULL);
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
3349 ASSERT (strcmp (result, "999.95 33") == 0);
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
3350 ASSERT (length == strlen (result));
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
3351 free (result);
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
3352 }
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
3353
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
3354 { /* Precision with rounding. */
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
3355 size_t length;
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
3356 char *result =
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
3357 my_asnprintf (NULL, &length, "%.5Lg %d", 999.996L, 33, 44, 55);
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
3358 ASSERT (result != NULL);
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
3359 ASSERT (strcmp (result, "1000 33") == 0);
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
3360 ASSERT (length == strlen (result));
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
3361 free (result);
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
3362 }
9f8c455639fc Fix rounding when a precision is given.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
3363
8336
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3364 /* Test the support of the %n format directive. */
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3365
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3366 {
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3367 int count = -1;
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3368 size_t length;
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3369 char *result =
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3370 my_asnprintf (NULL, &length, "%d %n", 123, &count, 33, 44, 55);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3371 ASSERT (result != NULL);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3372 ASSERT (strcmp (result, "123 ") == 0);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3373 ASSERT (length == strlen (result));
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3374 ASSERT (count == 4);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3375 free (result);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3376 }
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3377
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3378 /* Test the support of the POSIX/XSI format strings with positions. */
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3379
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3380 {
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3381 size_t length;
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3382 char *result =
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3383 my_asnprintf (NULL, &length, "%2$d %1$d", 33, 55);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3384 ASSERT (result != NULL);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3385 ASSERT (strcmp (result, "55 33") == 0);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3386 ASSERT (length == strlen (result));
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3387 free (result);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3388 }
8803
6c1d98929550 Work around lack of support of grouping flag.
Bruno Haible <bruno@clisp.org>
parents: 8754
diff changeset
3389
6c1d98929550 Work around lack of support of grouping flag.
Bruno Haible <bruno@clisp.org>
parents: 8754
diff changeset
3390 /* 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
3391
6c1d98929550 Work around lack of support of grouping flag.
Bruno Haible <bruno@clisp.org>
parents: 8754
diff changeset
3392 {
6c1d98929550 Work around lack of support of grouping flag.
Bruno Haible <bruno@clisp.org>
parents: 8754
diff changeset
3393 size_t length;
6c1d98929550 Work around lack of support of grouping flag.
Bruno Haible <bruno@clisp.org>
parents: 8754
diff changeset
3394 char *result =
6c1d98929550 Work around lack of support of grouping flag.
Bruno Haible <bruno@clisp.org>
parents: 8754
diff changeset
3395 my_asnprintf (NULL, &length, "%'d %d", 1234567, 99);
6c1d98929550 Work around lack of support of grouping flag.
Bruno Haible <bruno@clisp.org>
parents: 8754
diff changeset
3396 ASSERT (result != NULL);
6c1d98929550 Work around lack of support of grouping flag.
Bruno Haible <bruno@clisp.org>
parents: 8754
diff changeset
3397 ASSERT (result[strlen (result) - 1] == '9');
6c1d98929550 Work around lack of support of grouping flag.
Bruno Haible <bruno@clisp.org>
parents: 8754
diff changeset
3398 ASSERT (length == strlen (result));
6c1d98929550 Work around lack of support of grouping flag.
Bruno Haible <bruno@clisp.org>
parents: 8754
diff changeset
3399 free (result);
6c1d98929550 Work around lack of support of grouping flag.
Bruno Haible <bruno@clisp.org>
parents: 8754
diff changeset
3400 }
9447
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3401
9674
b69f1141e94f Fix *printf behaviour regarding the left-adjust flag on HP-UX 10.20.
Bruno Haible <bruno@clisp.org>
parents: 9447
diff changeset
3402 /* Test the support of the left-adjust flag. */
b69f1141e94f Fix *printf behaviour regarding the left-adjust flag on HP-UX 10.20.
Bruno Haible <bruno@clisp.org>
parents: 9447
diff changeset
3403
b69f1141e94f Fix *printf behaviour regarding the left-adjust flag on HP-UX 10.20.
Bruno Haible <bruno@clisp.org>
parents: 9447
diff changeset
3404 {
b69f1141e94f Fix *printf behaviour regarding the left-adjust flag on HP-UX 10.20.
Bruno Haible <bruno@clisp.org>
parents: 9447
diff changeset
3405 size_t length;
b69f1141e94f Fix *printf behaviour regarding the left-adjust flag on HP-UX 10.20.
Bruno Haible <bruno@clisp.org>
parents: 9447
diff changeset
3406 char *result =
b69f1141e94f Fix *printf behaviour regarding the left-adjust flag on HP-UX 10.20.
Bruno Haible <bruno@clisp.org>
parents: 9447
diff changeset
3407 my_asnprintf (NULL, &length, "a%*sc", -3, "b");
b69f1141e94f Fix *printf behaviour regarding the left-adjust flag on HP-UX 10.20.
Bruno Haible <bruno@clisp.org>
parents: 9447
diff changeset
3408 ASSERT (result != NULL);
b69f1141e94f Fix *printf behaviour regarding the left-adjust flag on HP-UX 10.20.
Bruno Haible <bruno@clisp.org>
parents: 9447
diff changeset
3409 ASSERT (strcmp (result, "ab c") == 0);
b69f1141e94f Fix *printf behaviour regarding the left-adjust flag on HP-UX 10.20.
Bruno Haible <bruno@clisp.org>
parents: 9447
diff changeset
3410 ASSERT (length == strlen (result));
b69f1141e94f Fix *printf behaviour regarding the left-adjust flag on HP-UX 10.20.
Bruno Haible <bruno@clisp.org>
parents: 9447
diff changeset
3411 free (result);
b69f1141e94f Fix *printf behaviour regarding the left-adjust flag on HP-UX 10.20.
Bruno Haible <bruno@clisp.org>
parents: 9447
diff changeset
3412 }
b69f1141e94f Fix *printf behaviour regarding the left-adjust flag on HP-UX 10.20.
Bruno Haible <bruno@clisp.org>
parents: 9447
diff changeset
3413
b69f1141e94f Fix *printf behaviour regarding the left-adjust flag on HP-UX 10.20.
Bruno Haible <bruno@clisp.org>
parents: 9447
diff changeset
3414 {
b69f1141e94f Fix *printf behaviour regarding the left-adjust flag on HP-UX 10.20.
Bruno Haible <bruno@clisp.org>
parents: 9447
diff changeset
3415 size_t length;
b69f1141e94f Fix *printf behaviour regarding the left-adjust flag on HP-UX 10.20.
Bruno Haible <bruno@clisp.org>
parents: 9447
diff changeset
3416 char *result =
b69f1141e94f Fix *printf behaviour regarding the left-adjust flag on HP-UX 10.20.
Bruno Haible <bruno@clisp.org>
parents: 9447
diff changeset
3417 my_asnprintf (NULL, &length, "a%-*sc", 3, "b");
b69f1141e94f Fix *printf behaviour regarding the left-adjust flag on HP-UX 10.20.
Bruno Haible <bruno@clisp.org>
parents: 9447
diff changeset
3418 ASSERT (result != NULL);
b69f1141e94f Fix *printf behaviour regarding the left-adjust flag on HP-UX 10.20.
Bruno Haible <bruno@clisp.org>
parents: 9447
diff changeset
3419 ASSERT (strcmp (result, "ab c") == 0);
b69f1141e94f Fix *printf behaviour regarding the left-adjust flag on HP-UX 10.20.
Bruno Haible <bruno@clisp.org>
parents: 9447
diff changeset
3420 ASSERT (length == strlen (result));
b69f1141e94f Fix *printf behaviour regarding the left-adjust flag on HP-UX 10.20.
Bruno Haible <bruno@clisp.org>
parents: 9447
diff changeset
3421 free (result);
b69f1141e94f Fix *printf behaviour regarding the left-adjust flag on HP-UX 10.20.
Bruno Haible <bruno@clisp.org>
parents: 9447
diff changeset
3422 }
b69f1141e94f Fix *printf behaviour regarding the left-adjust flag on HP-UX 10.20.
Bruno Haible <bruno@clisp.org>
parents: 9447
diff changeset
3423
b69f1141e94f Fix *printf behaviour regarding the left-adjust flag on HP-UX 10.20.
Bruno Haible <bruno@clisp.org>
parents: 9447
diff changeset
3424 {
b69f1141e94f Fix *printf behaviour regarding the left-adjust flag on HP-UX 10.20.
Bruno Haible <bruno@clisp.org>
parents: 9447
diff changeset
3425 size_t length;
b69f1141e94f Fix *printf behaviour regarding the left-adjust flag on HP-UX 10.20.
Bruno Haible <bruno@clisp.org>
parents: 9447
diff changeset
3426 char *result =
b69f1141e94f Fix *printf behaviour regarding the left-adjust flag on HP-UX 10.20.
Bruno Haible <bruno@clisp.org>
parents: 9447
diff changeset
3427 my_asnprintf (NULL, &length, "a%-*sc", -3, "b");
b69f1141e94f Fix *printf behaviour regarding the left-adjust flag on HP-UX 10.20.
Bruno Haible <bruno@clisp.org>
parents: 9447
diff changeset
3428 ASSERT (result != NULL);
b69f1141e94f Fix *printf behaviour regarding the left-adjust flag on HP-UX 10.20.
Bruno Haible <bruno@clisp.org>
parents: 9447
diff changeset
3429 ASSERT (strcmp (result, "ab c") == 0);
b69f1141e94f Fix *printf behaviour regarding the left-adjust flag on HP-UX 10.20.
Bruno Haible <bruno@clisp.org>
parents: 9447
diff changeset
3430 ASSERT (length == strlen (result));
b69f1141e94f Fix *printf behaviour regarding the left-adjust flag on HP-UX 10.20.
Bruno Haible <bruno@clisp.org>
parents: 9447
diff changeset
3431 free (result);
b69f1141e94f Fix *printf behaviour regarding the left-adjust flag on HP-UX 10.20.
Bruno Haible <bruno@clisp.org>
parents: 9447
diff changeset
3432 }
b69f1141e94f Fix *printf behaviour regarding the left-adjust flag on HP-UX 10.20.
Bruno Haible <bruno@clisp.org>
parents: 9447
diff changeset
3433
9447
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3434 /* Test the support of large precision. */
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3435
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3436 {
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3437 size_t length;
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3438 char *result =
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3439 my_asnprintf (NULL, &length, "%.4000d %d", 1234567, 99);
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3440 size_t i;
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3441 ASSERT (result != NULL);
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3442 for (i = 0; i < 4000 - 7; i++)
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3443 ASSERT (result[i] == '0');
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3444 ASSERT (strcmp (result + 4000 - 7, "1234567 99") == 0);
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3445 ASSERT (length == strlen (result));
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3446 free (result);
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3447 }
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3448
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3449 {
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3450 size_t length;
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3451 char *result =
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3452 my_asnprintf (NULL, &length, "%.4000d %d", -1234567, 99);
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3453 size_t i;
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3454 ASSERT (result != NULL);
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3455 ASSERT (result[0] == '-');
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3456 for (i = 0; i < 4000 - 7; i++)
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3457 ASSERT (result[1 + i] == '0');
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3458 ASSERT (strcmp (result + 1 + 4000 - 7, "1234567 99") == 0);
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3459 ASSERT (length == strlen (result));
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3460 free (result);
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3461 }
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3462
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3463 {
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3464 size_t length;
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3465 char *result =
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3466 my_asnprintf (NULL, &length, "%.4000u %d", 1234567, 99);
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3467 size_t i;
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3468 ASSERT (result != NULL);
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3469 for (i = 0; i < 4000 - 7; i++)
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3470 ASSERT (result[i] == '0');
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3471 ASSERT (strcmp (result + 4000 - 7, "1234567 99") == 0);
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3472 ASSERT (length == strlen (result));
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3473 free (result);
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3474 }
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3475
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3476 {
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3477 size_t length;
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3478 char *result =
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3479 my_asnprintf (NULL, &length, "%.4000o %d", 1234567, 99);
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3480 size_t i;
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3481 ASSERT (result != NULL);
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3482 for (i = 0; i < 4000 - 7; i++)
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3483 ASSERT (result[i] == '0');
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3484 ASSERT (strcmp (result + 4000 - 7, "4553207 99") == 0);
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3485 ASSERT (length == strlen (result));
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3486 free (result);
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3487 }
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3488
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3489 {
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3490 size_t length;
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3491 char *result =
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3492 my_asnprintf (NULL, &length, "%.4000x %d", 1234567, 99);
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3493 size_t i;
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3494 ASSERT (result != NULL);
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3495 for (i = 0; i < 4000 - 6; i++)
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3496 ASSERT (result[i] == '0');
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3497 ASSERT (strcmp (result + 4000 - 6, "12d687 99") == 0);
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3498 ASSERT (length == strlen (result));
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3499 free (result);
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3500 }
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3501
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3502 {
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3503 size_t length;
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3504 char *result =
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3505 my_asnprintf (NULL, &length, "%#.4000x %d", 1234567, 99);
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3506 size_t i;
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3507 ASSERT (result != NULL);
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3508 ASSERT (result[0] == '0');
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3509 ASSERT (result[1] == 'x');
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3510 for (i = 0; i < 4000 - 6; i++)
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3511 ASSERT (result[2 + i] == '0');
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3512 ASSERT (strcmp (result + 2 + 4000 - 6, "12d687 99") == 0);
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3513 ASSERT (length == strlen (result));
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3514 free (result);
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3515 }
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3516
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3517 {
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3518 char input[5000];
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3519 size_t length;
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3520 char *result;
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3521 size_t i;
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3522
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3523 for (i = 0; i < sizeof (input) - 1; i++)
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3524 input[i] = 'a' + ((1000000 / (i + 1)) % 26);
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3525 input[i] = '\0';
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3526 result = my_asnprintf (NULL, &length, "%.4000s %d", input, 99);
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3527 ASSERT (result != NULL);
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3528 ASSERT (memcmp (result, input, 4000) == 0);
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3529 ASSERT (strcmp (result + 4000, " 99") == 0);
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3530 ASSERT (length == strlen (result));
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3531 free (result);
6d73d8d1aecb Add tests for large precisions.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3532 }
8336
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3533 }
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3534
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3535 static char *
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3536 my_asnprintf (char *resultbuf, size_t *lengthp, const char *format, ...)
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3537 {
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3538 va_list args;
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3539 char *ret;
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3540
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3541 va_start (args, format);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3542 ret = vasnprintf (resultbuf, lengthp, format, args);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3543 va_end (args);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3544 return ret;
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3545 }
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3546
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3547 static void
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3548 test_vasnprintf ()
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3549 {
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3550 test_function (my_asnprintf);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3551 }
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3552
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3553 static void
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3554 test_asnprintf ()
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3555 {
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3556 test_function (asnprintf);
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3557 }
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3558
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3559 int
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3560 main (int argc, char *argv[])
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3561 {
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3562 test_vasnprintf ();
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3563 test_asnprintf ();
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3564 return 0;
493708637f61 Tests for module 'vasnprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3565 }