Mercurial > hg > octave-lojdl > gnulib-hg
annotate tests/test-vasprintf-posix.c @ 8919:42e2847583f9
Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
author | Bruno Haible <bruno@clisp.org> |
---|---|
date | Wed, 06 Jun 2007 02:20:57 +0000 |
parents | 633babea5f62 |
children | bbbbbf4cd1c5 |
rev | line source |
---|---|
8342
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
1 /* Test of POSIX compatible vasprintf() and asprintf() functions. |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
2 Copyright (C) 2007 Free Software Foundation, Inc. |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
3 |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
4 This program is free software; you can redistribute it and/or modify |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
5 it under the terms of the GNU General Public License as published by |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
6 the Free Software Foundation; either version 2, or (at your option) |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
7 any later version. |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
8 |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
9 This program is distributed in the hope that it will be useful, |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
10 but WITHOUT ANY WARRANTY; without even the implied warranty of |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
12 GNU General Public License for more details. |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
13 |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
14 You should have received a copy of the GNU General Public License |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
15 along with this program; if not, write to the Free Software Foundation, |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
16 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
17 |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
18 /* Written by Bruno Haible <bruno@clisp.org>, 2007. */ |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
19 |
8891
633babea5f62
Unconditionally include <config.h> in unit tests.
Eric Blake <ebb9@byu.net>
parents:
8870
diff
changeset
|
20 #include <config.h> |
8342
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
21 |
8570
4175c39ba7cc
Move vasprintf prototypes to stdio.
Simon Josefsson <simon@josefsson.org>
parents:
8543
diff
changeset
|
22 #include <stdio.h> |
8342
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
23 |
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
|
24 #include <float.h> |
8342
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
25 #include <stdarg.h> |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
26 #include <stddef.h> |
8754 | 27 #include <stdio.h> |
8342
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
28 #include <stdint.h> |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
29 #include <stdlib.h> |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
30 #include <string.h> |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
31 |
8834 | 32 #define SIZEOF(array) (sizeof (array) / sizeof (array[0])) |
8754 | 33 #define ASSERT(expr) \ |
34 do \ | |
35 { \ | |
36 if (!(expr)) \ | |
37 { \ | |
38 fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ | |
39 abort (); \ | |
40 } \ | |
41 } \ | |
42 while (0) | |
8342
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
43 |
8543
e1fdf02d5cdc
Work around a DEC C compiler bug.
Bruno Haible <bruno@clisp.org>
parents:
8344
diff
changeset
|
44 /* The Compaq (ex-DEC) C 6.4 compiler chokes on the expression 0.0 / 0.0. */ |
e1fdf02d5cdc
Work around a DEC C compiler bug.
Bruno Haible <bruno@clisp.org>
parents:
8344
diff
changeset
|
45 #ifdef __DECC |
e1fdf02d5cdc
Work around a DEC C compiler bug.
Bruno Haible <bruno@clisp.org>
parents:
8344
diff
changeset
|
46 static double |
e1fdf02d5cdc
Work around a DEC C compiler bug.
Bruno Haible <bruno@clisp.org>
parents:
8344
diff
changeset
|
47 NaN () |
e1fdf02d5cdc
Work around a DEC C compiler bug.
Bruno Haible <bruno@clisp.org>
parents:
8344
diff
changeset
|
48 { |
e1fdf02d5cdc
Work around a DEC C compiler bug.
Bruno Haible <bruno@clisp.org>
parents:
8344
diff
changeset
|
49 static double zero = 0.0; |
e1fdf02d5cdc
Work around a DEC C compiler bug.
Bruno Haible <bruno@clisp.org>
parents:
8344
diff
changeset
|
50 return zero / zero; |
e1fdf02d5cdc
Work around a DEC C compiler bug.
Bruno Haible <bruno@clisp.org>
parents:
8344
diff
changeset
|
51 } |
e1fdf02d5cdc
Work around a DEC C compiler bug.
Bruno Haible <bruno@clisp.org>
parents:
8344
diff
changeset
|
52 #else |
e1fdf02d5cdc
Work around a DEC C compiler bug.
Bruno Haible <bruno@clisp.org>
parents:
8344
diff
changeset
|
53 # define NaN() (0.0 / 0.0) |
e1fdf02d5cdc
Work around a DEC C compiler bug.
Bruno Haible <bruno@clisp.org>
parents:
8344
diff
changeset
|
54 #endif |
e1fdf02d5cdc
Work around a DEC C compiler bug.
Bruno Haible <bruno@clisp.org>
parents:
8344
diff
changeset
|
55 |
8852
df0b5e8ea770
Avoid test failures on platforms where -0.0 and 0.0 are identical.
Bruno Haible <bruno@clisp.org>
parents:
8850
diff
changeset
|
56 /* 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
|
57 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
|
58 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
|
59 { |
df0b5e8ea770
Avoid test failures on platforms where -0.0 and 0.0 are identical.
Bruno Haible <bruno@clisp.org>
parents:
8850
diff
changeset
|
60 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
|
61 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
|
62 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
|
63 } |
df0b5e8ea770
Avoid test failures on platforms where -0.0 and 0.0 are identical.
Bruno Haible <bruno@clisp.org>
parents:
8850
diff
changeset
|
64 |
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
|
65 /* 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
|
66 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
|
67 #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
|
68 # 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
|
69 { ((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
|
70 ((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
|
71 (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
|
72 } |
42e2847583f9
Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
73 #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
|
74 # 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
|
75 { 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
|
76 #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
|
77 |
8834 | 78 static int |
79 strmatch (const char *pattern, const char *string) | |
80 { | |
81 if (strlen (pattern) != strlen (string)) | |
82 return 0; | |
83 for (; *pattern != '\0'; pattern++, string++) | |
84 if (*pattern != '*' && *string != *pattern) | |
85 return 0; | |
86 return 1; | |
87 } | |
88 | |
8865
9e203d8ade65
Stricter check for printf result for NaN arguments.
Bruno Haible <bruno@clisp.org>
parents:
8857
diff
changeset
|
89 /* 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
|
90 representation of NaN. */ |
9e203d8ade65
Stricter check for printf result for NaN arguments.
Bruno Haible <bruno@clisp.org>
parents:
8857
diff
changeset
|
91 static int |
9e203d8ade65
Stricter check for printf result for NaN arguments.
Bruno Haible <bruno@clisp.org>
parents:
8857
diff
changeset
|
92 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
|
93 { |
9e203d8ade65
Stricter check for printf result for NaN arguments.
Bruno Haible <bruno@clisp.org>
parents:
8857
diff
changeset
|
94 if (start_index < end_index) |
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 if (string[start_index] == '-') |
9e203d8ade65
Stricter check for printf result for NaN arguments.
Bruno Haible <bruno@clisp.org>
parents:
8857
diff
changeset
|
97 start_index++; |
9e203d8ade65
Stricter check for printf result for NaN arguments.
Bruno Haible <bruno@clisp.org>
parents:
8857
diff
changeset
|
98 if (start_index + 3 <= end_index |
9e203d8ade65
Stricter check for printf result for NaN arguments.
Bruno Haible <bruno@clisp.org>
parents:
8857
diff
changeset
|
99 && 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
|
100 { |
9e203d8ade65
Stricter check for printf result for NaN arguments.
Bruno Haible <bruno@clisp.org>
parents:
8857
diff
changeset
|
101 start_index += 3; |
9e203d8ade65
Stricter check for printf result for NaN arguments.
Bruno Haible <bruno@clisp.org>
parents:
8857
diff
changeset
|
102 if (start_index == end_index |
9e203d8ade65
Stricter check for printf result for NaN arguments.
Bruno Haible <bruno@clisp.org>
parents:
8857
diff
changeset
|
103 || (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
|
104 return 1; |
9e203d8ade65
Stricter check for printf result for NaN arguments.
Bruno Haible <bruno@clisp.org>
parents:
8857
diff
changeset
|
105 } |
9e203d8ade65
Stricter check for printf result for NaN arguments.
Bruno Haible <bruno@clisp.org>
parents:
8857
diff
changeset
|
106 } |
9e203d8ade65
Stricter check for printf result for NaN arguments.
Bruno Haible <bruno@clisp.org>
parents:
8857
diff
changeset
|
107 return 0; |
9e203d8ade65
Stricter check for printf result for NaN arguments.
Bruno Haible <bruno@clisp.org>
parents:
8857
diff
changeset
|
108 } |
9e203d8ade65
Stricter check for printf result for NaN arguments.
Bruno Haible <bruno@clisp.org>
parents:
8857
diff
changeset
|
109 |
8342
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
110 static void |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
111 test_function (int (*my_asprintf) (char **, const char *, ...)) |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
112 { |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
113 int repeat; |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
114 |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
115 /* Test return value convention. */ |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
116 |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
117 for (repeat = 0; repeat <= 8; repeat++) |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
118 { |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
119 char *result; |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
120 int retval = asprintf (&result, "%d", 12345); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
121 ASSERT (retval == 5); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
122 ASSERT (result != NULL); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
123 ASSERT (strcmp (result, "12345") == 0); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
124 free (result); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
125 } |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
126 |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
127 /* Test support of size specifiers as in C99. */ |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
128 |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
129 { |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
130 char *result; |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
131 int retval = |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
132 my_asprintf (&result, "%ju %d", (uintmax_t) 12345671, 33, 44, 55); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
133 ASSERT (result != NULL); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
134 ASSERT (strcmp (result, "12345671 33") == 0); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
135 ASSERT (retval == strlen (result)); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
136 free (result); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
137 } |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
138 |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
139 { |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
140 char *result; |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
141 int retval = |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
142 my_asprintf (&result, "%zu %d", (size_t) 12345672, 33, 44, 55); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
143 ASSERT (result != NULL); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
144 ASSERT (strcmp (result, "12345672 33") == 0); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
145 ASSERT (retval == strlen (result)); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
146 free (result); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
147 } |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
148 |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
149 { |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
150 char *result; |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
151 int retval = |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
152 my_asprintf (&result, "%tu %d", (ptrdiff_t) 12345673, 33, 44, 55); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
153 ASSERT (result != NULL); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
154 ASSERT (strcmp (result, "12345673 33") == 0); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
155 ASSERT (retval == strlen (result)); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
156 free (result); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
157 } |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
158 |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
159 { |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
160 char *result; |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
161 int retval = |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
162 my_asprintf (&result, "%Lg %d", (long double) 1.5, 33, 44, 55); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
163 ASSERT (result != NULL); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
164 ASSERT (strcmp (result, "1.5 33") == 0); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
165 ASSERT (retval == strlen (result)); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
166 free (result); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
167 } |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
168 |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
169 /* Test the support of the 'a' and 'A' conversion specifier for hexadecimal |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
170 output of floating-point numbers. */ |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
171 |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
172 { /* A positive number. */ |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
173 char *result; |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
174 int retval = |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
175 my_asprintf (&result, "%a %d", 3.1416015625, 33, 44, 55); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
176 ASSERT (result != NULL); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
177 ASSERT (strcmp (result, "0x1.922p+1 33") == 0 |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
178 || strcmp (result, "0x3.244p+0 33") == 0 |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
179 || strcmp (result, "0x6.488p-1 33") == 0 |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
180 || strcmp (result, "0xc.91p-2 33") == 0); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
181 ASSERT (retval == strlen (result)); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
182 free (result); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
183 } |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
184 |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
185 { /* A negative number. */ |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
186 char *result; |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
187 int retval = |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
188 my_asprintf (&result, "%A %d", -3.1416015625, 33, 44, 55); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
189 ASSERT (result != NULL); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
190 ASSERT (strcmp (result, "-0X1.922P+1 33") == 0 |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
191 || strcmp (result, "-0X3.244P+0 33") == 0 |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
192 || strcmp (result, "-0X6.488P-1 33") == 0 |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
193 || strcmp (result, "-0XC.91P-2 33") == 0); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
194 ASSERT (retval == strlen (result)); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
195 free (result); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
196 } |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
197 |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
198 { /* Positive zero. */ |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
199 char *result; |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
200 int retval = |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
201 my_asprintf (&result, "%a %d", 0.0, 33, 44, 55); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
202 ASSERT (result != NULL); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
203 ASSERT (strcmp (result, "0x0p+0 33") == 0); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
204 ASSERT (retval == strlen (result)); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
205 free (result); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
206 } |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
207 |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
208 { /* Negative zero. */ |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
209 char *result; |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
210 int retval = |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
211 my_asprintf (&result, "%a %d", -0.0, 33, 44, 55); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
212 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
|
213 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
|
214 ASSERT (strcmp (result, "-0x0p+0 33") == 0); |
8342
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
215 ASSERT (retval == strlen (result)); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
216 free (result); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
217 } |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
218 |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
219 { /* Positive infinity. */ |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
220 char *result; |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
221 int retval = |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
222 my_asprintf (&result, "%a %d", 1.0 / 0.0, 33, 44, 55); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
223 ASSERT (result != NULL); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
224 ASSERT (strcmp (result, "inf 33") == 0); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
225 ASSERT (retval == strlen (result)); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
226 free (result); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
227 } |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
228 |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
229 { /* Negative infinity. */ |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
230 char *result; |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
231 int retval = |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
232 my_asprintf (&result, "%a %d", -1.0 / 0.0, 33, 44, 55); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
233 ASSERT (result != NULL); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
234 ASSERT (strcmp (result, "-inf 33") == 0); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
235 ASSERT (retval == strlen (result)); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
236 free (result); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
237 } |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
238 |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
239 { /* NaN. */ |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
240 char *result; |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
241 int retval = |
8543
e1fdf02d5cdc
Work around a DEC C compiler bug.
Bruno Haible <bruno@clisp.org>
parents:
8344
diff
changeset
|
242 my_asprintf (&result, "%a %d", NaN (), 33, 44, 55); |
8342
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
243 ASSERT (result != NULL); |
8850
d1fe16dfbfee
Avoid test failures on IRIX 6.5.
Bruno Haible <bruno@clisp.org>
parents:
8839
diff
changeset
|
244 ASSERT (strlen (result) >= 3 + 3 |
8865
9e203d8ade65
Stricter check for printf result for NaN arguments.
Bruno Haible <bruno@clisp.org>
parents:
8857
diff
changeset
|
245 && 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
|
246 && strcmp (result + strlen (result) - 3, " 33") == 0); |
8342
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
247 ASSERT (retval == strlen (result)); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
248 free (result); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
249 } |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
250 |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
251 { /* Rounding near the decimal point. */ |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
252 char *result; |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
253 int retval = |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
254 my_asprintf (&result, "%.0a %d", 1.5, 33, 44, 55); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
255 ASSERT (result != NULL); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
256 ASSERT (strcmp (result, "0x2p+0 33") == 0 |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
257 || strcmp (result, "0x3p-1 33") == 0 |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
258 || strcmp (result, "0x6p-2 33") == 0 |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
259 || strcmp (result, "0xcp-3 33") == 0); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
260 ASSERT (retval == strlen (result)); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
261 free (result); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
262 } |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
263 |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
264 { /* Rounding with precision 0. */ |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
265 char *result; |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
266 int retval = |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
267 my_asprintf (&result, "%.0a %d", 1.51, 33, 44, 55); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
268 ASSERT (result != NULL); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
269 ASSERT (strcmp (result, "0x2p+0 33") == 0 |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
270 || strcmp (result, "0x3p-1 33") == 0 |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
271 || strcmp (result, "0x6p-2 33") == 0 |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
272 || strcmp (result, "0xcp-3 33") == 0); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
273 ASSERT (retval == strlen (result)); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
274 free (result); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
275 } |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
276 |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
277 { /* Rounding with precision 1. */ |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
278 char *result; |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
279 int retval = |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
280 my_asprintf (&result, "%.1a %d", 1.51, 33, 44, 55); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
281 ASSERT (result != NULL); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
282 ASSERT (strcmp (result, "0x1.8p+0 33") == 0 |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
283 || strcmp (result, "0x3.0p-1 33") == 0 |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
284 || strcmp (result, "0x6.1p-2 33") == 0 |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
285 || strcmp (result, "0xc.1p-3 33") == 0); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
286 ASSERT (retval == strlen (result)); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
287 free (result); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
288 } |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
289 |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
290 { /* Rounding with precision 2. */ |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
291 char *result; |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
292 int retval = |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
293 my_asprintf (&result, "%.2a %d", 1.51, 33, 44, 55); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
294 ASSERT (result != NULL); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
295 ASSERT (strcmp (result, "0x1.83p+0 33") == 0 |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
296 || strcmp (result, "0x3.05p-1 33") == 0 |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
297 || strcmp (result, "0x6.0ap-2 33") == 0 |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
298 || strcmp (result, "0xc.14p-3 33") == 0); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
299 ASSERT (retval == strlen (result)); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
300 free (result); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
301 } |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
302 |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
303 { /* Rounding with precision 3. */ |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
304 char *result; |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
305 int retval = |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
306 my_asprintf (&result, "%.3a %d", 1.51, 33, 44, 55); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
307 ASSERT (result != NULL); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
308 ASSERT (strcmp (result, "0x1.829p+0 33") == 0 |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
309 || strcmp (result, "0x3.052p-1 33") == 0 |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
310 || strcmp (result, "0x6.0a4p-2 33") == 0 |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
311 || strcmp (result, "0xc.148p-3 33") == 0); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
312 ASSERT (retval == strlen (result)); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
313 free (result); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
314 } |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
315 |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
316 { /* Rounding can turn a ...FFF into a ...000. */ |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
317 char *result; |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
318 int retval = |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
319 my_asprintf (&result, "%.3a %d", 1.49999, 33, 44, 55); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
320 ASSERT (result != NULL); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
321 ASSERT (strcmp (result, "0x1.800p+0 33") == 0 |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
322 || strcmp (result, "0x3.000p-1 33") == 0 |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
323 || strcmp (result, "0x6.000p-2 33") == 0 |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
324 || strcmp (result, "0xc.000p-3 33") == 0); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
325 ASSERT (retval == strlen (result)); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
326 free (result); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
327 } |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
328 |
8344
c8055280f68e
Test a corner case. Exclude two buggy implementations.
Bruno Haible <bruno@clisp.org>
parents:
8342
diff
changeset
|
329 { /* Rounding can turn a ...FFF into a ...000. |
c8055280f68e
Test a corner case. Exclude two buggy implementations.
Bruno Haible <bruno@clisp.org>
parents:
8342
diff
changeset
|
330 This shows a MacOS X 10.3.9 (Darwin 7.9) bug. */ |
c8055280f68e
Test a corner case. Exclude two buggy implementations.
Bruno Haible <bruno@clisp.org>
parents:
8342
diff
changeset
|
331 char *result; |
c8055280f68e
Test a corner case. Exclude two buggy implementations.
Bruno Haible <bruno@clisp.org>
parents:
8342
diff
changeset
|
332 int retval = |
c8055280f68e
Test a corner case. Exclude two buggy implementations.
Bruno Haible <bruno@clisp.org>
parents:
8342
diff
changeset
|
333 my_asprintf (&result, "%.1a %d", 1.999, 33, 44, 55); |
c8055280f68e
Test a corner case. Exclude two buggy implementations.
Bruno Haible <bruno@clisp.org>
parents:
8342
diff
changeset
|
334 ASSERT (result != NULL); |
c8055280f68e
Test a corner case. Exclude two buggy implementations.
Bruno Haible <bruno@clisp.org>
parents:
8342
diff
changeset
|
335 ASSERT (strcmp (result, "0x1.0p+1 33") == 0 |
c8055280f68e
Test a corner case. Exclude two buggy implementations.
Bruno Haible <bruno@clisp.org>
parents:
8342
diff
changeset
|
336 || strcmp (result, "0x2.0p+0 33") == 0 |
c8055280f68e
Test a corner case. Exclude two buggy implementations.
Bruno Haible <bruno@clisp.org>
parents:
8342
diff
changeset
|
337 || strcmp (result, "0x4.0p-1 33") == 0 |
c8055280f68e
Test a corner case. Exclude two buggy implementations.
Bruno Haible <bruno@clisp.org>
parents:
8342
diff
changeset
|
338 || strcmp (result, "0x8.0p-2 33") == 0); |
c8055280f68e
Test a corner case. Exclude two buggy implementations.
Bruno Haible <bruno@clisp.org>
parents:
8342
diff
changeset
|
339 ASSERT (retval == strlen (result)); |
c8055280f68e
Test a corner case. Exclude two buggy implementations.
Bruno Haible <bruno@clisp.org>
parents:
8342
diff
changeset
|
340 free (result); |
c8055280f68e
Test a corner case. Exclude two buggy implementations.
Bruno Haible <bruno@clisp.org>
parents:
8342
diff
changeset
|
341 } |
c8055280f68e
Test a corner case. Exclude two buggy implementations.
Bruno Haible <bruno@clisp.org>
parents:
8342
diff
changeset
|
342 |
8342
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
343 { /* Width. */ |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
344 char *result; |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
345 int retval = |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
346 my_asprintf (&result, "%10a %d", 1.75, 33, 44, 55); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
347 ASSERT (result != NULL); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
348 ASSERT (strcmp (result, " 0x1.cp+0 33") == 0 |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
349 || strcmp (result, " 0x3.8p-1 33") == 0 |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
350 || strcmp (result, " 0x7p-2 33") == 0 |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
351 || strcmp (result, " 0xep-3 33") == 0); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
352 ASSERT (retval == strlen (result)); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
353 free (result); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
354 } |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
355 |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
356 { /* Small precision. */ |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
357 char *result; |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
358 int retval = |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
359 my_asprintf (&result, "%.10a %d", 1.75, 33, 44, 55); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
360 ASSERT (result != NULL); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
361 ASSERT (strcmp (result, "0x1.c000000000p+0 33") == 0 |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
362 || strcmp (result, "0x3.8000000000p-1 33") == 0 |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
363 || strcmp (result, "0x7.0000000000p-2 33") == 0 |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
364 || strcmp (result, "0xe.0000000000p-3 33") == 0); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
365 ASSERT (retval == strlen (result)); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
366 free (result); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
367 } |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
368 |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
369 { /* Large precision. */ |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
370 char *result; |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
371 int retval = |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
372 my_asprintf (&result, "%.50a %d", 1.75, 33, 44, 55); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
373 ASSERT (result != NULL); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
374 ASSERT (strcmp (result, "0x1.c0000000000000000000000000000000000000000000000000p+0 33") == 0 |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
375 || strcmp (result, "0x3.80000000000000000000000000000000000000000000000000p-1 33") == 0 |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
376 || strcmp (result, "0x7.00000000000000000000000000000000000000000000000000p-2 33") == 0 |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
377 || strcmp (result, "0xe.00000000000000000000000000000000000000000000000000p-3 33") == 0); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
378 ASSERT (retval == strlen (result)); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
379 free (result); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
380 } |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
381 |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
382 { /* FLAG_LEFT. */ |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
383 char *result; |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
384 int retval = |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
385 my_asprintf (&result, "%-10a %d", 1.75, 33, 44, 55); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
386 ASSERT (result != NULL); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
387 ASSERT (strcmp (result, "0x1.cp+0 33") == 0 |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
388 || strcmp (result, "0x3.8p-1 33") == 0 |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
389 || strcmp (result, "0x7p-2 33") == 0 |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
390 || strcmp (result, "0xep-3 33") == 0); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
391 ASSERT (retval == strlen (result)); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
392 free (result); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
393 } |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
394 |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
395 { /* FLAG_SHOWSIGN. */ |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
396 char *result; |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
397 int retval = |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
398 my_asprintf (&result, "%+a %d", 1.75, 33, 44, 55); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
399 ASSERT (result != NULL); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
400 ASSERT (strcmp (result, "+0x1.cp+0 33") == 0 |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
401 || strcmp (result, "+0x3.8p-1 33") == 0 |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
402 || strcmp (result, "+0x7p-2 33") == 0 |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
403 || strcmp (result, "+0xep-3 33") == 0); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
404 ASSERT (retval == strlen (result)); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
405 free (result); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
406 } |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
407 |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
408 { /* FLAG_SPACE. */ |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
409 char *result; |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
410 int retval = |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
411 my_asprintf (&result, "% a %d", 1.75, 33, 44, 55); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
412 ASSERT (result != NULL); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
413 ASSERT (strcmp (result, " 0x1.cp+0 33") == 0 |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
414 || strcmp (result, " 0x3.8p-1 33") == 0 |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
415 || strcmp (result, " 0x7p-2 33") == 0 |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
416 || strcmp (result, " 0xep-3 33") == 0); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
417 ASSERT (retval == strlen (result)); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
418 free (result); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
419 } |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
420 |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
421 { /* FLAG_ALT. */ |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
422 char *result; |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
423 int retval = |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
424 my_asprintf (&result, "%#a %d", 1.75, 33, 44, 55); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
425 ASSERT (result != NULL); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
426 ASSERT (strcmp (result, "0x1.cp+0 33") == 0 |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
427 || strcmp (result, "0x3.8p-1 33") == 0 |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
428 || strcmp (result, "0x7.p-2 33") == 0 |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
429 || strcmp (result, "0xe.p-3 33") == 0); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
430 ASSERT (retval == strlen (result)); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
431 free (result); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
432 } |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
433 |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
434 { /* FLAG_ALT. */ |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
435 char *result; |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
436 int retval = |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
437 my_asprintf (&result, "%#a %d", 1.0, 33, 44, 55); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
438 ASSERT (result != NULL); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
439 ASSERT (strcmp (result, "0x1.p+0 33") == 0 |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
440 || strcmp (result, "0x2.p-1 33") == 0 |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
441 || strcmp (result, "0x4.p-2 33") == 0 |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
442 || strcmp (result, "0x8.p-3 33") == 0); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
443 ASSERT (retval == strlen (result)); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
444 free (result); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
445 } |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
446 |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
447 { /* FLAG_ZERO with finite number. */ |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
448 char *result; |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
449 int retval = |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
450 my_asprintf (&result, "%010a %d", 1.75, 33, 44, 55); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
451 ASSERT (result != NULL); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
452 ASSERT (strcmp (result, "0x001.cp+0 33") == 0 |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
453 || strcmp (result, "0x003.8p-1 33") == 0 |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
454 || strcmp (result, "0x00007p-2 33") == 0 |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
455 || strcmp (result, "0x0000ep-3 33") == 0); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
456 ASSERT (retval == strlen (result)); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
457 free (result); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
458 } |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
459 |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
460 { /* FLAG_ZERO with infinite number. */ |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
461 char *result; |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
462 int retval = |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
463 my_asprintf (&result, "%010a %d", 1.0 / 0.0, 33, 44, 55); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
464 ASSERT (result != NULL); |
8662
023aa5c883a7
Guard against FreeBSD 6.1 bug.
Bruno Haible <bruno@clisp.org>
parents:
8648
diff
changeset
|
465 /* "0000000inf 33" is not a valid result; see |
023aa5c883a7
Guard against FreeBSD 6.1 bug.
Bruno Haible <bruno@clisp.org>
parents:
8648
diff
changeset
|
466 <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
|
467 ASSERT (strcmp (result, " inf 33") == 0); |
8342
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
468 ASSERT (retval == strlen (result)); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
469 free (result); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
470 } |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
471 |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
472 { /* FLAG_ZERO with NaN. */ |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
473 char *result; |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
474 int retval = |
8870
4e1f2ea486b4
Allow for a longer printed representation of NaN.
Bruno Haible <bruno@clisp.org>
parents:
8865
diff
changeset
|
475 my_asprintf (&result, "%050a %d", NaN (), 33, 44, 55); |
8342
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
476 ASSERT (result != NULL); |
8662
023aa5c883a7
Guard against FreeBSD 6.1 bug.
Bruno Haible <bruno@clisp.org>
parents:
8648
diff
changeset
|
477 /* "0000000nan 33" is not a valid result; see |
023aa5c883a7
Guard against FreeBSD 6.1 bug.
Bruno Haible <bruno@clisp.org>
parents:
8648
diff
changeset
|
478 <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
|
479 ASSERT (strlen (result) == 50 + 3 |
8865
9e203d8ade65
Stricter check for printf result for NaN arguments.
Bruno Haible <bruno@clisp.org>
parents:
8857
diff
changeset
|
480 && 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
|
481 && strcmp (result + strlen (result) - 3, " 33") == 0); |
8342
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
482 ASSERT (retval == strlen (result)); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
483 free (result); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
484 } |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
485 |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
486 { /* A positive number. */ |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
487 char *result; |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
488 int retval = |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
489 my_asprintf (&result, "%La %d", 3.1416015625L, 33, 44, 55); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
490 ASSERT (result != NULL); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
491 ASSERT (strcmp (result, "0x1.922p+1 33") == 0 |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
492 || strcmp (result, "0x3.244p+0 33") == 0 |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
493 || strcmp (result, "0x6.488p-1 33") == 0 |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
494 || strcmp (result, "0xc.91p-2 33") == 0); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
495 ASSERT (retval == strlen (result)); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
496 free (result); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
497 } |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
498 |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
499 { /* A negative number. */ |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
500 char *result; |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
501 int retval = |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
502 my_asprintf (&result, "%LA %d", -3.1416015625L, 33, 44, 55); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
503 ASSERT (result != NULL); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
504 ASSERT (strcmp (result, "-0X1.922P+1 33") == 0 |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
505 || strcmp (result, "-0X3.244P+0 33") == 0 |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
506 || strcmp (result, "-0X6.488P-1 33") == 0 |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
507 || strcmp (result, "-0XC.91P-2 33") == 0); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
508 ASSERT (retval == strlen (result)); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
509 free (result); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
510 } |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
511 |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
512 { /* Positive zero. */ |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
513 char *result; |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
514 int retval = |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
515 my_asprintf (&result, "%La %d", 0.0L, 33, 44, 55); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
516 ASSERT (result != NULL); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
517 ASSERT (strcmp (result, "0x0p+0 33") == 0); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
518 ASSERT (retval == strlen (result)); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
519 free (result); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
520 } |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
521 |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
522 { /* Negative zero. */ |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
523 char *result; |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
524 int retval = |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
525 my_asprintf (&result, "%La %d", -0.0L, 33, 44, 55); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
526 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
|
527 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
|
528 ASSERT (strcmp (result, "-0x0p+0 33") == 0); |
8342
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
529 ASSERT (retval == strlen (result)); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
530 free (result); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
531 } |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
532 |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
533 { /* Positive infinity. */ |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
534 char *result; |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
535 int retval = |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
536 my_asprintf (&result, "%La %d", 1.0L / 0.0L, 33, 44, 55); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
537 ASSERT (result != NULL); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
538 ASSERT (strcmp (result, "inf 33") == 0); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
539 ASSERT (retval == strlen (result)); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
540 free (result); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
541 } |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
542 |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
543 { /* Negative infinity. */ |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
544 char *result; |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
545 int retval = |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
546 my_asprintf (&result, "%La %d", -1.0L / 0.0L, 33, 44, 55); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
547 ASSERT (result != NULL); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
548 ASSERT (strcmp (result, "-inf 33") == 0); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
549 ASSERT (retval == strlen (result)); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
550 free (result); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
551 } |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
552 |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
553 { /* NaN. */ |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
554 char *result; |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
555 int retval = |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
556 my_asprintf (&result, "%La %d", 0.0L / 0.0L, 33, 44, 55); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
557 ASSERT (result != NULL); |
8850
d1fe16dfbfee
Avoid test failures on IRIX 6.5.
Bruno Haible <bruno@clisp.org>
parents:
8839
diff
changeset
|
558 ASSERT (strlen (result) >= 3 + 3 |
8865
9e203d8ade65
Stricter check for printf result for NaN arguments.
Bruno Haible <bruno@clisp.org>
parents:
8857
diff
changeset
|
559 && 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
|
560 && strcmp (result + strlen (result) - 3, " 33") == 0); |
8342
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
561 ASSERT (retval == strlen (result)); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
562 free (result); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
563 } |
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
|
564 #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
|
565 { /* 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
|
566 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
|
567 { 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
|
568 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
|
569 int retval = |
42e2847583f9
Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
570 my_asprintf (&result, "%La %d", x.value, 33, 44, 55); |
42e2847583f9
Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
571 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
|
572 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
|
573 && 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
|
574 && 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
|
575 ASSERT (retval == strlen (result)); |
42e2847583f9
Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
576 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
|
577 } |
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 { |
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 /* 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
|
580 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
|
581 { 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
|
582 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
|
583 int retval = |
42e2847583f9
Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
584 my_asprintf (&result, "%La %d", x.value, 33, 44, 55); |
42e2847583f9
Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
585 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
|
586 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
|
587 && 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
|
588 && 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
|
589 ASSERT (retval == strlen (result)); |
42e2847583f9
Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
590 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
|
591 } |
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 /* 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
|
593 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
|
594 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
|
595 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
|
596 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
|
597 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
|
598 */ |
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 { /* 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
|
600 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
|
601 { 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
|
602 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
|
603 int retval = |
42e2847583f9
Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
604 my_asprintf (&result, "%La %d", x.value, 33, 44, 55); |
42e2847583f9
Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
605 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
|
606 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
|
607 && 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
|
608 && 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
|
609 ASSERT (retval == strlen (result)); |
42e2847583f9
Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
610 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
|
611 } |
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 { /* 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
|
613 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
|
614 { 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
|
615 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
|
616 int retval = |
42e2847583f9
Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
617 my_asprintf (&result, "%La %d", x.value, 33, 44, 55); |
42e2847583f9
Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
618 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
|
619 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
|
620 && 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
|
621 && 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
|
622 ASSERT (retval == strlen (result)); |
42e2847583f9
Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
623 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
|
624 } |
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 { /* 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
|
626 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
|
627 { 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
|
628 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
|
629 int retval = |
42e2847583f9
Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
630 my_asprintf (&result, "%La %d", x.value, 33, 44, 55); |
42e2847583f9
Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
631 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
|
632 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
|
633 && 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
|
634 && 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
|
635 ASSERT (retval == strlen (result)); |
42e2847583f9
Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
636 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
|
637 } |
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 { /* 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
|
639 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
|
640 { 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
|
641 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
|
642 int retval = |
42e2847583f9
Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
643 my_asprintf (&result, "%La %d", x.value, 33, 44, 55); |
42e2847583f9
Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
644 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
|
645 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
|
646 && 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
|
647 && 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
|
648 ASSERT (retval == strlen (result)); |
42e2847583f9
Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
649 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
|
650 } |
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 { /* 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
|
652 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
|
653 { 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
|
654 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
|
655 int retval = |
42e2847583f9
Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
656 my_asprintf (&result, "%La %d", x.value, 33, 44, 55); |
42e2847583f9
Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
657 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
|
658 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
|
659 && 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
|
660 && 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
|
661 ASSERT (retval == strlen (result)); |
42e2847583f9
Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
662 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
|
663 } |
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 #endif |
8342
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
665 |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
666 { /* Rounding near the decimal point. */ |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
667 char *result; |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
668 int retval = |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
669 my_asprintf (&result, "%.0La %d", 1.5L, 33, 44, 55); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
670 ASSERT (result != NULL); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
671 ASSERT (strcmp (result, "0x2p+0 33") == 0 |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
672 || strcmp (result, "0x3p-1 33") == 0 |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
673 || strcmp (result, "0x6p-2 33") == 0 |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
674 || strcmp (result, "0xcp-3 33") == 0); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
675 ASSERT (retval == strlen (result)); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
676 free (result); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
677 } |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
678 |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
679 { /* Rounding with precision 0. */ |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
680 char *result; |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
681 int retval = |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
682 my_asprintf (&result, "%.0La %d", 1.51L, 33, 44, 55); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
683 ASSERT (result != NULL); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
684 ASSERT (strcmp (result, "0x2p+0 33") == 0 |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
685 || strcmp (result, "0x3p-1 33") == 0 |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
686 || strcmp (result, "0x6p-2 33") == 0 |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
687 || strcmp (result, "0xcp-3 33") == 0); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
688 ASSERT (retval == strlen (result)); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
689 free (result); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
690 } |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
691 |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
692 { /* Rounding with precision 1. */ |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
693 char *result; |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
694 int retval = |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
695 my_asprintf (&result, "%.1La %d", 1.51L, 33, 44, 55); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
696 ASSERT (result != NULL); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
697 ASSERT (strcmp (result, "0x1.8p+0 33") == 0 |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
698 || strcmp (result, "0x3.0p-1 33") == 0 |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
699 || strcmp (result, "0x6.1p-2 33") == 0 |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
700 || strcmp (result, "0xc.1p-3 33") == 0); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
701 ASSERT (retval == strlen (result)); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
702 free (result); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
703 } |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
704 |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
705 { /* Rounding with precision 2. */ |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
706 char *result; |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
707 int retval = |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
708 my_asprintf (&result, "%.2La %d", 1.51L, 33, 44, 55); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
709 ASSERT (result != NULL); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
710 ASSERT (strcmp (result, "0x1.83p+0 33") == 0 |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
711 || strcmp (result, "0x3.05p-1 33") == 0 |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
712 || strcmp (result, "0x6.0ap-2 33") == 0 |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
713 || strcmp (result, "0xc.14p-3 33") == 0); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
714 ASSERT (retval == strlen (result)); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
715 free (result); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
716 } |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
717 |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
718 { /* Rounding with precision 3. */ |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
719 char *result; |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
720 int retval = |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
721 my_asprintf (&result, "%.3La %d", 1.51L, 33, 44, 55); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
722 ASSERT (result != NULL); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
723 ASSERT (strcmp (result, "0x1.829p+0 33") == 0 |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
724 || strcmp (result, "0x3.052p-1 33") == 0 |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
725 || strcmp (result, "0x6.0a4p-2 33") == 0 |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
726 || strcmp (result, "0xc.148p-3 33") == 0); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
727 ASSERT (retval == strlen (result)); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
728 free (result); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
729 } |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
730 |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
731 { /* Rounding can turn a ...FFF into a ...000. */ |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
732 char *result; |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
733 int retval = |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
734 my_asprintf (&result, "%.3La %d", 1.49999L, 33, 44, 55); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
735 ASSERT (result != NULL); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
736 ASSERT (strcmp (result, "0x1.800p+0 33") == 0 |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
737 || strcmp (result, "0x3.000p-1 33") == 0 |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
738 || strcmp (result, "0x6.000p-2 33") == 0 |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
739 || strcmp (result, "0xc.000p-3 33") == 0); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
740 ASSERT (retval == strlen (result)); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
741 free (result); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
742 } |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
743 |
8344
c8055280f68e
Test a corner case. Exclude two buggy implementations.
Bruno Haible <bruno@clisp.org>
parents:
8342
diff
changeset
|
744 { /* Rounding can turn a ...FFF into a ...000. |
c8055280f68e
Test a corner case. Exclude two buggy implementations.
Bruno Haible <bruno@clisp.org>
parents:
8342
diff
changeset
|
745 This shows a MacOS X 10.3.9 (Darwin 7.9) bug and a |
c8055280f68e
Test a corner case. Exclude two buggy implementations.
Bruno Haible <bruno@clisp.org>
parents:
8342
diff
changeset
|
746 glibc 2.4 bug <http://sourceware.org/bugzilla/show_bug.cgi?id=2908>. */ |
c8055280f68e
Test a corner case. Exclude two buggy implementations.
Bruno Haible <bruno@clisp.org>
parents:
8342
diff
changeset
|
747 char *result; |
c8055280f68e
Test a corner case. Exclude two buggy implementations.
Bruno Haible <bruno@clisp.org>
parents:
8342
diff
changeset
|
748 int retval = |
c8055280f68e
Test a corner case. Exclude two buggy implementations.
Bruno Haible <bruno@clisp.org>
parents:
8342
diff
changeset
|
749 my_asprintf (&result, "%.1La %d", 1.999L, 33, 44, 55); |
c8055280f68e
Test a corner case. Exclude two buggy implementations.
Bruno Haible <bruno@clisp.org>
parents:
8342
diff
changeset
|
750 ASSERT (result != NULL); |
c8055280f68e
Test a corner case. Exclude two buggy implementations.
Bruno Haible <bruno@clisp.org>
parents:
8342
diff
changeset
|
751 ASSERT (strcmp (result, "0x1.0p+1 33") == 0 |
c8055280f68e
Test a corner case. Exclude two buggy implementations.
Bruno Haible <bruno@clisp.org>
parents:
8342
diff
changeset
|
752 || strcmp (result, "0x2.0p+0 33") == 0 |
c8055280f68e
Test a corner case. Exclude two buggy implementations.
Bruno Haible <bruno@clisp.org>
parents:
8342
diff
changeset
|
753 || strcmp (result, "0x4.0p-1 33") == 0 |
c8055280f68e
Test a corner case. Exclude two buggy implementations.
Bruno Haible <bruno@clisp.org>
parents:
8342
diff
changeset
|
754 || strcmp (result, "0x8.0p-2 33") == 0); |
c8055280f68e
Test a corner case. Exclude two buggy implementations.
Bruno Haible <bruno@clisp.org>
parents:
8342
diff
changeset
|
755 ASSERT (retval == strlen (result)); |
c8055280f68e
Test a corner case. Exclude two buggy implementations.
Bruno Haible <bruno@clisp.org>
parents:
8342
diff
changeset
|
756 free (result); |
c8055280f68e
Test a corner case. Exclude two buggy implementations.
Bruno Haible <bruno@clisp.org>
parents:
8342
diff
changeset
|
757 } |
c8055280f68e
Test a corner case. Exclude two buggy implementations.
Bruno Haible <bruno@clisp.org>
parents:
8342
diff
changeset
|
758 |
8342
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
759 { /* Width. */ |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
760 char *result; |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
761 int retval = |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
762 my_asprintf (&result, "%10La %d", 1.75L, 33, 44, 55); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
763 ASSERT (result != NULL); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
764 ASSERT (strcmp (result, " 0x1.cp+0 33") == 0 |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
765 || strcmp (result, " 0x3.8p-1 33") == 0 |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
766 || strcmp (result, " 0x7p-2 33") == 0 |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
767 || strcmp (result, " 0xep-3 33") == 0); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
768 ASSERT (retval == strlen (result)); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
769 free (result); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
770 } |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
771 |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
772 { /* Small precision. */ |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
773 char *result; |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
774 int retval = |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
775 my_asprintf (&result, "%.10La %d", 1.75L, 33, 44, 55); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
776 ASSERT (result != NULL); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
777 ASSERT (strcmp (result, "0x1.c000000000p+0 33") == 0 |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
778 || strcmp (result, "0x3.8000000000p-1 33") == 0 |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
779 || strcmp (result, "0x7.0000000000p-2 33") == 0 |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
780 || strcmp (result, "0xe.0000000000p-3 33") == 0); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
781 ASSERT (retval == strlen (result)); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
782 free (result); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
783 } |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
784 |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
785 { /* Large precision. */ |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
786 char *result; |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
787 int retval = |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
788 my_asprintf (&result, "%.50La %d", 1.75L, 33, 44, 55); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
789 ASSERT (result != NULL); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
790 ASSERT (strcmp (result, "0x1.c0000000000000000000000000000000000000000000000000p+0 33") == 0 |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
791 || strcmp (result, "0x3.80000000000000000000000000000000000000000000000000p-1 33") == 0 |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
792 || strcmp (result, "0x7.00000000000000000000000000000000000000000000000000p-2 33") == 0 |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
793 || strcmp (result, "0xe.00000000000000000000000000000000000000000000000000p-3 33") == 0); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
794 ASSERT (retval == strlen (result)); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
795 free (result); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
796 } |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
797 |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
798 { /* FLAG_LEFT. */ |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
799 char *result; |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
800 int retval = |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
801 my_asprintf (&result, "%-10La %d", 1.75L, 33, 44, 55); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
802 ASSERT (result != NULL); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
803 ASSERT (strcmp (result, "0x1.cp+0 33") == 0 |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
804 || strcmp (result, "0x3.8p-1 33") == 0 |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
805 || strcmp (result, "0x7p-2 33") == 0 |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
806 || strcmp (result, "0xep-3 33") == 0); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
807 ASSERT (retval == strlen (result)); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
808 free (result); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
809 } |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
810 |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
811 { /* FLAG_SHOWSIGN. */ |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
812 char *result; |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
813 int retval = |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
814 my_asprintf (&result, "%+La %d", 1.75L, 33, 44, 55); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
815 ASSERT (result != NULL); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
816 ASSERT (strcmp (result, "+0x1.cp+0 33") == 0 |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
817 || strcmp (result, "+0x3.8p-1 33") == 0 |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
818 || strcmp (result, "+0x7p-2 33") == 0 |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
819 || strcmp (result, "+0xep-3 33") == 0); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
820 ASSERT (retval == strlen (result)); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
821 free (result); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
822 } |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
823 |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
824 { /* FLAG_SPACE. */ |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
825 char *result; |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
826 int retval = |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
827 my_asprintf (&result, "% La %d", 1.75L, 33, 44, 55); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
828 ASSERT (result != NULL); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
829 ASSERT (strcmp (result, " 0x1.cp+0 33") == 0 |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
830 || strcmp (result, " 0x3.8p-1 33") == 0 |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
831 || strcmp (result, " 0x7p-2 33") == 0 |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
832 || strcmp (result, " 0xep-3 33") == 0); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
833 ASSERT (retval == strlen (result)); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
834 free (result); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
835 } |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
836 |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
837 { /* FLAG_ALT. */ |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
838 char *result; |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
839 int retval = |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
840 my_asprintf (&result, "%#La %d", 1.75L, 33, 44, 55); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
841 ASSERT (result != NULL); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
842 ASSERT (strcmp (result, "0x1.cp+0 33") == 0 |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
843 || strcmp (result, "0x3.8p-1 33") == 0 |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
844 || strcmp (result, "0x7.p-2 33") == 0 |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
845 || strcmp (result, "0xe.p-3 33") == 0); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
846 ASSERT (retval == strlen (result)); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
847 free (result); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
848 } |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
849 |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
850 { /* FLAG_ALT. */ |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
851 char *result; |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
852 int retval = |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
853 my_asprintf (&result, "%#La %d", 1.0L, 33, 44, 55); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
854 ASSERT (result != NULL); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
855 ASSERT (strcmp (result, "0x1.p+0 33") == 0 |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
856 || strcmp (result, "0x2.p-1 33") == 0 |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
857 || strcmp (result, "0x4.p-2 33") == 0 |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
858 || strcmp (result, "0x8.p-3 33") == 0); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
859 ASSERT (retval == strlen (result)); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
860 free (result); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
861 } |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
862 |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
863 { /* FLAG_ZERO with finite number. */ |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
864 char *result; |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
865 int retval = |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
866 my_asprintf (&result, "%010La %d", 1.75L, 33, 44, 55); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
867 ASSERT (result != NULL); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
868 ASSERT (strcmp (result, "0x001.cp+0 33") == 0 |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
869 || strcmp (result, "0x003.8p-1 33") == 0 |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
870 || strcmp (result, "0x00007p-2 33") == 0 |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
871 || strcmp (result, "0x0000ep-3 33") == 0); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
872 ASSERT (retval == strlen (result)); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
873 free (result); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
874 } |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
875 |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
876 { /* FLAG_ZERO with infinite number. */ |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
877 char *result; |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
878 int retval = |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
879 my_asprintf (&result, "%010La %d", 1.0L / 0.0L, 33, 44, 55); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
880 ASSERT (result != NULL); |
8662
023aa5c883a7
Guard against FreeBSD 6.1 bug.
Bruno Haible <bruno@clisp.org>
parents:
8648
diff
changeset
|
881 /* "0000000inf 33" is not a valid result; see |
023aa5c883a7
Guard against FreeBSD 6.1 bug.
Bruno Haible <bruno@clisp.org>
parents:
8648
diff
changeset
|
882 <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
|
883 ASSERT (strcmp (result, " inf 33") == 0); |
8342
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
884 ASSERT (retval == strlen (result)); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
885 free (result); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
886 } |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
887 |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
888 { /* FLAG_ZERO with NaN. */ |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
889 char *result; |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
890 int retval = |
8870
4e1f2ea486b4
Allow for a longer printed representation of NaN.
Bruno Haible <bruno@clisp.org>
parents:
8865
diff
changeset
|
891 my_asprintf (&result, "%050La %d", 0.0L / 0.0L, 33, 44, 55); |
8342
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
892 ASSERT (result != NULL); |
8662
023aa5c883a7
Guard against FreeBSD 6.1 bug.
Bruno Haible <bruno@clisp.org>
parents:
8648
diff
changeset
|
893 /* "0000000nan 33" is not a valid result; see |
023aa5c883a7
Guard against FreeBSD 6.1 bug.
Bruno Haible <bruno@clisp.org>
parents:
8648
diff
changeset
|
894 <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
|
895 ASSERT (strlen (result) == 50 + 3 |
8865
9e203d8ade65
Stricter check for printf result for NaN arguments.
Bruno Haible <bruno@clisp.org>
parents:
8857
diff
changeset
|
896 && 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
|
897 && strcmp (result + strlen (result) - 3, " 33") == 0); |
8342
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
898 ASSERT (retval == strlen (result)); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
899 free (result); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
900 } |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
901 |
8684
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
902 /* 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
|
903 |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
904 { /* A positive number. */ |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
905 char *result; |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
906 int retval = |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
907 my_asprintf (&result, "%f %d", 12.75, 33, 44, 55); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
908 ASSERT (result != NULL); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
909 ASSERT (strcmp (result, "12.750000 33") == 0); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
910 ASSERT (retval == strlen (result)); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
911 free (result); |
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 |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
914 { /* A larger positive number. */ |
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 int retval = |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
917 my_asprintf (&result, "%f %d", 1234567.0, 33, 44, 55); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
918 ASSERT (result != NULL); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
919 ASSERT (strcmp (result, "1234567.000000 33") == 0); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
920 ASSERT (retval == strlen (result)); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
921 free (result); |
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 |
8834 | 924 { /* Small and large positive numbers. */ |
925 static struct { double value; const char *string; } data[] = | |
926 { | |
927 { 1.234321234321234e-37, "0.000000" }, | |
928 { 1.234321234321234e-36, "0.000000" }, | |
929 { 1.234321234321234e-35, "0.000000" }, | |
930 { 1.234321234321234e-34, "0.000000" }, | |
931 { 1.234321234321234e-33, "0.000000" }, | |
932 { 1.234321234321234e-32, "0.000000" }, | |
933 { 1.234321234321234e-31, "0.000000" }, | |
934 { 1.234321234321234e-30, "0.000000" }, | |
935 { 1.234321234321234e-29, "0.000000" }, | |
936 { 1.234321234321234e-28, "0.000000" }, | |
937 { 1.234321234321234e-27, "0.000000" }, | |
938 { 1.234321234321234e-26, "0.000000" }, | |
939 { 1.234321234321234e-25, "0.000000" }, | |
940 { 1.234321234321234e-24, "0.000000" }, | |
941 { 1.234321234321234e-23, "0.000000" }, | |
942 { 1.234321234321234e-22, "0.000000" }, | |
943 { 1.234321234321234e-21, "0.000000" }, | |
944 { 1.234321234321234e-20, "0.000000" }, | |
945 { 1.234321234321234e-19, "0.000000" }, | |
946 { 1.234321234321234e-18, "0.000000" }, | |
947 { 1.234321234321234e-17, "0.000000" }, | |
948 { 1.234321234321234e-16, "0.000000" }, | |
949 { 1.234321234321234e-15, "0.000000" }, | |
950 { 1.234321234321234e-14, "0.000000" }, | |
951 { 1.234321234321234e-13, "0.000000" }, | |
952 { 1.234321234321234e-12, "0.000000" }, | |
953 { 1.234321234321234e-11, "0.000000" }, | |
954 { 1.234321234321234e-10, "0.000000" }, | |
955 { 1.234321234321234e-9, "0.000000" }, | |
956 { 1.234321234321234e-8, "0.000000" }, | |
957 { 1.234321234321234e-7, "0.000000" }, | |
958 { 1.234321234321234e-6, "0.000001" }, | |
959 { 1.234321234321234e-5, "0.000012" }, | |
960 { 1.234321234321234e-4, "0.000123" }, | |
961 { 1.234321234321234e-3, "0.001234" }, | |
962 { 1.234321234321234e-2, "0.012343" }, | |
963 { 1.234321234321234e-1, "0.123432" }, | |
964 { 1.234321234321234, "1.234321" }, | |
965 { 1.234321234321234e1, "12.343212" }, | |
966 { 1.234321234321234e2, "123.432123" }, | |
967 { 1.234321234321234e3, "1234.321234" }, | |
968 { 1.234321234321234e4, "12343.212343" }, | |
969 { 1.234321234321234e5, "123432.123432" }, | |
970 { 1.234321234321234e6, "1234321.234321" }, | |
971 { 1.234321234321234e7, "12343212.343212" }, | |
972 { 1.234321234321234e8, "123432123.432123" }, | |
973 { 1.234321234321234e9, "1234321234.321234" }, | |
974 { 1.234321234321234e10, "12343212343.2123**" }, | |
975 { 1.234321234321234e11, "123432123432.123***" }, | |
976 { 1.234321234321234e12, "1234321234321.23****" }, | |
977 { 1.234321234321234e13, "12343212343212.3*****" }, | |
978 { 1.234321234321234e14, "123432123432123.******" }, | |
979 { 1.234321234321234e15, "1234321234321234.000000" }, | |
980 { 1.234321234321234e16, "123432123432123**.000000" }, | |
981 { 1.234321234321234e17, "123432123432123***.000000" }, | |
982 { 1.234321234321234e18, "123432123432123****.000000" }, | |
983 { 1.234321234321234e19, "123432123432123*****.000000" }, | |
984 { 1.234321234321234e20, "123432123432123******.000000" }, | |
985 { 1.234321234321234e21, "123432123432123*******.000000" }, | |
986 { 1.234321234321234e22, "123432123432123********.000000" }, | |
987 { 1.234321234321234e23, "123432123432123*********.000000" }, | |
988 { 1.234321234321234e24, "123432123432123**********.000000" }, | |
989 { 1.234321234321234e25, "123432123432123***********.000000" }, | |
990 { 1.234321234321234e26, "123432123432123************.000000" }, | |
991 { 1.234321234321234e27, "123432123432123*************.000000" }, | |
992 { 1.234321234321234e28, "123432123432123**************.000000" }, | |
993 { 1.234321234321234e29, "123432123432123***************.000000" }, | |
994 { 1.234321234321234e30, "123432123432123****************.000000" }, | |
995 { 1.234321234321234e31, "123432123432123*****************.000000" }, | |
996 { 1.234321234321234e32, "123432123432123******************.000000" }, | |
997 { 1.234321234321234e33, "123432123432123*******************.000000" }, | |
998 { 1.234321234321234e34, "123432123432123********************.000000" }, | |
999 { 1.234321234321234e35, "123432123432123*********************.000000" }, | |
1000 { 1.234321234321234e36, "123432123432123**********************.000000" } | |
1001 }; | |
1002 size_t k; | |
1003 for (k = 0; k < SIZEOF (data); k++) | |
1004 { | |
1005 char *result; | |
1006 int retval = | |
1007 my_asprintf (&result, "%f", data[k].value); | |
1008 ASSERT (result != NULL); | |
1009 ASSERT (strmatch (data[k].string, result)); | |
1010 ASSERT (retval == strlen (result)); | |
1011 free (result); | |
1012 } | |
1013 } | |
1014 | |
8684
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1015 { /* A negative number. */ |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1016 char *result; |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1017 int retval = |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1018 my_asprintf (&result, "%f %d", -0.03125, 33, 44, 55); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1019 ASSERT (result != NULL); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1020 ASSERT (strcmp (result, "-0.031250 33") == 0); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1021 ASSERT (retval == strlen (result)); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1022 free (result); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1023 } |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1024 |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1025 { /* Positive zero. */ |
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 int retval = |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1028 my_asprintf (&result, "%f %d", 0.0, 33, 44, 55); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1029 ASSERT (result != NULL); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1030 ASSERT (strcmp (result, "0.000000 33") == 0); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1031 ASSERT (retval == strlen (result)); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1032 free (result); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1033 } |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1034 |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1035 { /* Negative zero. */ |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1036 char *result; |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1037 int retval = |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1038 my_asprintf (&result, "%f %d", -0.0, 33, 44, 55); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1039 ASSERT (result != NULL); |
8852
df0b5e8ea770
Avoid test failures on platforms where -0.0 and 0.0 are identical.
Bruno Haible <bruno@clisp.org>
parents:
8850
diff
changeset
|
1040 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
|
1041 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
|
1042 ASSERT (retval == strlen (result)); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1043 free (result); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1044 } |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1045 |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1046 { /* Positive infinity. */ |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1047 char *result; |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1048 int retval = |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1049 my_asprintf (&result, "%f %d", 1.0 / 0.0, 33, 44, 55); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1050 ASSERT (result != NULL); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1051 ASSERT (strcmp (result, "inf 33") == 0 |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1052 || strcmp (result, "infinity 33") == 0); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1053 ASSERT (retval == strlen (result)); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1054 free (result); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1055 } |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1056 |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1057 { /* Negative infinity. */ |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1058 char *result; |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1059 int retval = |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1060 my_asprintf (&result, "%f %d", -1.0 / 0.0, 33, 44, 55); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1061 ASSERT (result != NULL); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1062 ASSERT (strcmp (result, "-inf 33") == 0 |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1063 || strcmp (result, "-infinity 33") == 0); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1064 ASSERT (retval == strlen (result)); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1065 free (result); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1066 } |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1067 |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1068 { /* NaN. */ |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1069 char *result; |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1070 int retval = |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1071 my_asprintf (&result, "%f %d", NaN (), 33, 44, 55); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1072 ASSERT (result != NULL); |
8850
d1fe16dfbfee
Avoid test failures on IRIX 6.5.
Bruno Haible <bruno@clisp.org>
parents:
8839
diff
changeset
|
1073 ASSERT (strlen (result) >= 3 + 3 |
8865
9e203d8ade65
Stricter check for printf result for NaN arguments.
Bruno Haible <bruno@clisp.org>
parents:
8857
diff
changeset
|
1074 && 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
|
1075 && 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
|
1076 ASSERT (retval == strlen (result)); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1077 free (result); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1078 } |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1079 |
8804
6ce313658b4d
Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents:
8803
diff
changeset
|
1080 { /* Width. */ |
6ce313658b4d
Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents:
8803
diff
changeset
|
1081 char *result; |
6ce313658b4d
Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents:
8803
diff
changeset
|
1082 int retval = |
6ce313658b4d
Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents:
8803
diff
changeset
|
1083 my_asprintf (&result, "%10f %d", 1.75, 33, 44, 55); |
6ce313658b4d
Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents:
8803
diff
changeset
|
1084 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
|
1085 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
|
1086 ASSERT (retval == strlen (result)); |
6ce313658b4d
Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents:
8803
diff
changeset
|
1087 free (result); |
6ce313658b4d
Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents:
8803
diff
changeset
|
1088 } |
6ce313658b4d
Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents:
8803
diff
changeset
|
1089 |
6ce313658b4d
Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents:
8803
diff
changeset
|
1090 { /* FLAG_LEFT. */ |
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 int retval = |
6ce313658b4d
Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents:
8803
diff
changeset
|
1093 my_asprintf (&result, "%-10f %d", 1.75, 33, 44, 55); |
6ce313658b4d
Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents:
8803
diff
changeset
|
1094 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
|
1095 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
|
1096 ASSERT (retval == strlen (result)); |
6ce313658b4d
Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents:
8803
diff
changeset
|
1097 free (result); |
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 |
6ce313658b4d
Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents:
8803
diff
changeset
|
1100 { /* FLAG_SHOWSIGN. */ |
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 int retval = |
6ce313658b4d
Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents:
8803
diff
changeset
|
1103 my_asprintf (&result, "%+f %d", 1.75, 33, 44, 55); |
6ce313658b4d
Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents:
8803
diff
changeset
|
1104 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
|
1105 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
|
1106 ASSERT (retval == strlen (result)); |
6ce313658b4d
Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents:
8803
diff
changeset
|
1107 free (result); |
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 |
6ce313658b4d
Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents:
8803
diff
changeset
|
1110 { /* FLAG_SPACE. */ |
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 int retval = |
6ce313658b4d
Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents:
8803
diff
changeset
|
1113 my_asprintf (&result, "% f %d", 1.75, 33, 44, 55); |
6ce313658b4d
Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents:
8803
diff
changeset
|
1114 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
|
1115 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
|
1116 ASSERT (retval == strlen (result)); |
6ce313658b4d
Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents:
8803
diff
changeset
|
1117 free (result); |
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 |
6ce313658b4d
Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents:
8803
diff
changeset
|
1120 { /* FLAG_ALT. */ |
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 int retval = |
6ce313658b4d
Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents:
8803
diff
changeset
|
1123 my_asprintf (&result, "%#f %d", 1.75, 33, 44, 55); |
6ce313658b4d
Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents:
8803
diff
changeset
|
1124 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
|
1125 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
|
1126 ASSERT (retval == strlen (result)); |
6ce313658b4d
Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents:
8803
diff
changeset
|
1127 free (result); |
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 |
6ce313658b4d
Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents:
8803
diff
changeset
|
1130 { /* FLAG_ALT. */ |
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 int retval = |
6ce313658b4d
Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents:
8803
diff
changeset
|
1133 my_asprintf (&result, "%#.f %d", 1.75, 33, 44, 55); |
6ce313658b4d
Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents:
8803
diff
changeset
|
1134 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
|
1135 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
|
1136 ASSERT (retval == strlen (result)); |
6ce313658b4d
Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents:
8803
diff
changeset
|
1137 free (result); |
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 |
6ce313658b4d
Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents:
8803
diff
changeset
|
1140 { /* FLAG_ZERO with finite number. */ |
8684
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1141 char *result; |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1142 int retval = |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1143 my_asprintf (&result, "%015f %d", 1234.0, 33, 44, 55); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1144 ASSERT (result != NULL); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1145 ASSERT (strcmp (result, "00001234.000000 33") == 0); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1146 ASSERT (retval == strlen (result)); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1147 free (result); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1148 } |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1149 |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1150 { /* FLAG_ZERO with infinite number. */ |
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 int retval = |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1153 my_asprintf (&result, "%015f %d", -1.0 / 0.0, 33, 44, 55); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1154 ASSERT (result != NULL); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1155 ASSERT (strcmp (result, " -inf 33") == 0 |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1156 || strcmp (result, " -infinity 33") == 0); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1157 ASSERT (retval == strlen (result)); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1158 free (result); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1159 } |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1160 |
8804
6ce313658b4d
Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents:
8803
diff
changeset
|
1161 { /* 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
|
1162 char *result; |
6ce313658b4d
Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents:
8803
diff
changeset
|
1163 int retval = |
8870
4e1f2ea486b4
Allow for a longer printed representation of NaN.
Bruno Haible <bruno@clisp.org>
parents:
8865
diff
changeset
|
1164 my_asprintf (&result, "%050f %d", NaN (), 33, 44, 55); |
8804
6ce313658b4d
Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents:
8803
diff
changeset
|
1165 ASSERT (result != NULL); |
8870
4e1f2ea486b4
Allow for a longer printed representation of NaN.
Bruno Haible <bruno@clisp.org>
parents:
8865
diff
changeset
|
1166 ASSERT (strlen (result) == 50 + 3 |
8865
9e203d8ade65
Stricter check for printf result for NaN arguments.
Bruno Haible <bruno@clisp.org>
parents:
8857
diff
changeset
|
1167 && 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
|
1168 && 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
|
1169 ASSERT (retval == strlen (result)); |
6ce313658b4d
Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents:
8803
diff
changeset
|
1170 free (result); |
6ce313658b4d
Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents:
8803
diff
changeset
|
1171 } |
6ce313658b4d
Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents:
8803
diff
changeset
|
1172 |
8684
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1173 { /* Precision. */ |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1174 char *result; |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1175 int retval = |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1176 my_asprintf (&result, "%.f %d", 1234.0, 33, 44, 55); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1177 ASSERT (result != NULL); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1178 ASSERT (strcmp (result, "1234 33") == 0); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1179 ASSERT (retval == strlen (result)); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1180 free (result); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1181 } |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1182 |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1183 { /* A positive number. */ |
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 int retval = |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1186 my_asprintf (&result, "%Lf %d", 12.75L, 33, 44, 55); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1187 ASSERT (result != NULL); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1188 ASSERT (strcmp (result, "12.750000 33") == 0); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1189 ASSERT (retval == strlen (result)); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1190 free (result); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1191 } |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1192 |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1193 { /* A larger positive number. */ |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1194 char *result; |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1195 int retval = |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1196 my_asprintf (&result, "%Lf %d", 1234567.0L, 33, 44, 55); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1197 ASSERT (result != NULL); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1198 ASSERT (strcmp (result, "1234567.000000 33") == 0); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1199 ASSERT (retval == strlen (result)); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1200 free (result); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1201 } |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1202 |
8834 | 1203 { /* Small and large positive numbers. */ |
1204 static struct { long double value; const char *string; } data[] = | |
1205 { | |
1206 { 1.234321234321234e-37L, "0.000000" }, | |
1207 { 1.234321234321234e-36L, "0.000000" }, | |
1208 { 1.234321234321234e-35L, "0.000000" }, | |
1209 { 1.234321234321234e-34L, "0.000000" }, | |
1210 { 1.234321234321234e-33L, "0.000000" }, | |
1211 { 1.234321234321234e-32L, "0.000000" }, | |
1212 { 1.234321234321234e-31L, "0.000000" }, | |
1213 { 1.234321234321234e-30L, "0.000000" }, | |
1214 { 1.234321234321234e-29L, "0.000000" }, | |
1215 { 1.234321234321234e-28L, "0.000000" }, | |
1216 { 1.234321234321234e-27L, "0.000000" }, | |
1217 { 1.234321234321234e-26L, "0.000000" }, | |
1218 { 1.234321234321234e-25L, "0.000000" }, | |
1219 { 1.234321234321234e-24L, "0.000000" }, | |
1220 { 1.234321234321234e-23L, "0.000000" }, | |
1221 { 1.234321234321234e-22L, "0.000000" }, | |
1222 { 1.234321234321234e-21L, "0.000000" }, | |
1223 { 1.234321234321234e-20L, "0.000000" }, | |
1224 { 1.234321234321234e-19L, "0.000000" }, | |
1225 { 1.234321234321234e-18L, "0.000000" }, | |
1226 { 1.234321234321234e-17L, "0.000000" }, | |
1227 { 1.234321234321234e-16L, "0.000000" }, | |
1228 { 1.234321234321234e-15L, "0.000000" }, | |
1229 { 1.234321234321234e-14L, "0.000000" }, | |
1230 { 1.234321234321234e-13L, "0.000000" }, | |
1231 { 1.234321234321234e-12L, "0.000000" }, | |
1232 { 1.234321234321234e-11L, "0.000000" }, | |
1233 { 1.234321234321234e-10L, "0.000000" }, | |
1234 { 1.234321234321234e-9L, "0.000000" }, | |
1235 { 1.234321234321234e-8L, "0.000000" }, | |
1236 { 1.234321234321234e-7L, "0.000000" }, | |
1237 { 1.234321234321234e-6L, "0.000001" }, | |
1238 { 1.234321234321234e-5L, "0.000012" }, | |
1239 { 1.234321234321234e-4L, "0.000123" }, | |
1240 { 1.234321234321234e-3L, "0.001234" }, | |
1241 { 1.234321234321234e-2L, "0.012343" }, | |
1242 { 1.234321234321234e-1L, "0.123432" }, | |
1243 { 1.234321234321234L, "1.234321" }, | |
1244 { 1.234321234321234e1L, "12.343212" }, | |
1245 { 1.234321234321234e2L, "123.432123" }, | |
1246 { 1.234321234321234e3L, "1234.321234" }, | |
1247 { 1.234321234321234e4L, "12343.212343" }, | |
1248 { 1.234321234321234e5L, "123432.123432" }, | |
1249 { 1.234321234321234e6L, "1234321.234321" }, | |
1250 { 1.234321234321234e7L, "12343212.343212" }, | |
1251 { 1.234321234321234e8L, "123432123.432123" }, | |
1252 { 1.234321234321234e9L, "1234321234.321234" }, | |
1253 { 1.234321234321234e10L, "12343212343.2123**" }, | |
1254 { 1.234321234321234e11L, "123432123432.123***" }, | |
1255 { 1.234321234321234e12L, "1234321234321.23****" }, | |
1256 { 1.234321234321234e13L, "12343212343212.3*****" }, | |
1257 { 1.234321234321234e14L, "123432123432123.******" }, | |
1258 { 1.234321234321234e15L, "1234321234321234.000000" }, | |
1259 { 1.234321234321234e16L, "123432123432123**.000000" }, | |
1260 { 1.234321234321234e17L, "123432123432123***.000000" }, | |
1261 { 1.234321234321234e18L, "123432123432123****.000000" }, | |
1262 { 1.234321234321234e19L, "123432123432123*****.000000" }, | |
1263 { 1.234321234321234e20L, "123432123432123******.000000" }, | |
1264 { 1.234321234321234e21L, "123432123432123*******.000000" }, | |
1265 { 1.234321234321234e22L, "123432123432123********.000000" }, | |
1266 { 1.234321234321234e23L, "123432123432123*********.000000" }, | |
1267 { 1.234321234321234e24L, "123432123432123**********.000000" }, | |
1268 { 1.234321234321234e25L, "123432123432123***********.000000" }, | |
1269 { 1.234321234321234e26L, "123432123432123************.000000" }, | |
1270 { 1.234321234321234e27L, "123432123432123*************.000000" }, | |
1271 { 1.234321234321234e28L, "123432123432123**************.000000" }, | |
1272 { 1.234321234321234e29L, "123432123432123***************.000000" }, | |
1273 { 1.234321234321234e30L, "123432123432123****************.000000" }, | |
1274 { 1.234321234321234e31L, "123432123432123*****************.000000" }, | |
1275 { 1.234321234321234e32L, "123432123432123******************.000000" }, | |
1276 { 1.234321234321234e33L, "123432123432123*******************.000000" }, | |
1277 { 1.234321234321234e34L, "123432123432123********************.000000" }, | |
1278 { 1.234321234321234e35L, "123432123432123*********************.000000" }, | |
1279 { 1.234321234321234e36L, "123432123432123**********************.000000" } | |
1280 }; | |
1281 size_t k; | |
1282 for (k = 0; k < SIZEOF (data); k++) | |
1283 { | |
1284 char *result; | |
1285 int retval = | |
1286 my_asprintf (&result, "%Lf", data[k].value); | |
1287 ASSERT (result != NULL); | |
1288 ASSERT (strmatch (data[k].string, result)); | |
1289 ASSERT (retval == strlen (result)); | |
1290 free (result); | |
1291 } | |
1292 } | |
1293 | |
8684
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1294 { /* A negative number. */ |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1295 char *result; |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1296 int retval = |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1297 my_asprintf (&result, "%Lf %d", -0.03125L, 33, 44, 55); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1298 ASSERT (result != NULL); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1299 ASSERT (strcmp (result, "-0.031250 33") == 0); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1300 ASSERT (retval == strlen (result)); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1301 free (result); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1302 } |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1303 |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1304 { /* Positive zero. */ |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1305 char *result; |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1306 int retval = |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1307 my_asprintf (&result, "%Lf %d", 0.0L, 33, 44, 55); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1308 ASSERT (result != NULL); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1309 ASSERT (strcmp (result, "0.000000 33") == 0); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1310 ASSERT (retval == strlen (result)); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1311 free (result); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1312 } |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1313 |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1314 { /* Negative zero. */ |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1315 char *result; |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1316 int retval = |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1317 my_asprintf (&result, "%Lf %d", -0.0L, 33, 44, 55); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1318 ASSERT (result != NULL); |
8852
df0b5e8ea770
Avoid test failures on platforms where -0.0 and 0.0 are identical.
Bruno Haible <bruno@clisp.org>
parents:
8850
diff
changeset
|
1319 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
|
1320 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
|
1321 ASSERT (retval == strlen (result)); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1322 free (result); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1323 } |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1324 |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1325 { /* Positive infinity. */ |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1326 char *result; |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1327 int retval = |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1328 my_asprintf (&result, "%Lf %d", 1.0L / 0.0L, 33, 44, 55); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1329 ASSERT (result != NULL); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1330 ASSERT (strcmp (result, "inf 33") == 0 |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1331 || strcmp (result, "infinity 33") == 0); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1332 ASSERT (retval == strlen (result)); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1333 free (result); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1334 } |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1335 |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1336 { /* Negative infinity. */ |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1337 char *result; |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1338 int retval = |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1339 my_asprintf (&result, "%Lf %d", -1.0L / 0.0L, 33, 44, 55); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1340 ASSERT (result != NULL); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1341 ASSERT (strcmp (result, "-inf 33") == 0 |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1342 || strcmp (result, "-infinity 33") == 0); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1343 ASSERT (retval == strlen (result)); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1344 free (result); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1345 } |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1346 |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1347 { /* NaN. */ |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1348 static long double zero = 0.0L; |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1349 char *result; |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1350 int retval = |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1351 my_asprintf (&result, "%Lf %d", zero / zero, 33, 44, 55); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1352 ASSERT (result != NULL); |
8850
d1fe16dfbfee
Avoid test failures on IRIX 6.5.
Bruno Haible <bruno@clisp.org>
parents:
8839
diff
changeset
|
1353 ASSERT (strlen (result) >= 3 + 3 |
8865
9e203d8ade65
Stricter check for printf result for NaN arguments.
Bruno Haible <bruno@clisp.org>
parents:
8857
diff
changeset
|
1354 && 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
|
1355 && strcmp (result + strlen (result) - 3, " 33") == 0); |
8684
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1356 ASSERT (retval == strlen (result)); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1357 free (result); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1358 } |
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
|
1359 #if CHECK_PRINTF_SAFE && ((defined __ia64 && LDBL_MANT_DIG == 64) || (defined __x86_64__ || defined __amd64__) || (defined __i386 || defined __i386__ || defined _I386 || defined _M_IX86 || defined _X86_)) |
42e2847583f9
Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
1360 { /* Quiet NaN. */ |
42e2847583f9
Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
1361 static union { unsigned int word[4]; long double value; } x = |
42e2847583f9
Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
1362 { LDBL80_WORDS (0xFFFF, 0xC3333333, 0x00000000) }; |
42e2847583f9
Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
1363 char *result; |
42e2847583f9
Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
1364 int retval = |
42e2847583f9
Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
1365 my_asprintf (&result, "%Lf %d", x.value, 33, 44, 55); |
42e2847583f9
Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
1366 ASSERT (result != NULL); |
42e2847583f9
Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
1367 ASSERT (strlen (result) >= 3 + 3 |
42e2847583f9
Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
1368 && 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
|
1369 && 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
|
1370 ASSERT (retval == strlen (result)); |
42e2847583f9
Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
1371 free (result); |
42e2847583f9
Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
1372 } |
42e2847583f9
Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
1373 { |
42e2847583f9
Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
1374 /* Signalling NaN. */ |
42e2847583f9
Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
1375 static union { unsigned int word[4]; long double value; } x = |
42e2847583f9
Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
1376 { LDBL80_WORDS (0xFFFF, 0x83333333, 0x00000000) }; |
42e2847583f9
Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
1377 char *result; |
42e2847583f9
Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
1378 int retval = |
42e2847583f9
Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
1379 my_asprintf (&result, "%Lf %d", x.value, 33, 44, 55); |
42e2847583f9
Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
1380 ASSERT (result != NULL); |
42e2847583f9
Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
1381 ASSERT (strlen (result) >= 3 + 3 |
42e2847583f9
Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
1382 && 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
|
1383 && 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
|
1384 ASSERT (retval == strlen (result)); |
42e2847583f9
Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
1385 free (result); |
42e2847583f9
Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
1386 } |
42e2847583f9
Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
1387 /* The isnanl function should recognize Pseudo-NaNs, Pseudo-Infinities, |
42e2847583f9
Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
1388 Pseudo-Zeroes, Unnormalized Numbers, and Pseudo-Denormals, as defined in |
42e2847583f9
Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
1389 Intel IA-64 Architecture Software Developer's Manual, Volume 1: |
42e2847583f9
Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
1390 Application Architecture. |
42e2847583f9
Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
1391 Table 5-2 "Floating-Point Register Encodings" |
42e2847583f9
Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
1392 Figure 5-6 "Memory to Floating-Point Register Data Translation" |
42e2847583f9
Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
1393 */ |
42e2847583f9
Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
1394 { /* Pseudo-NaN. */ |
42e2847583f9
Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
1395 static union { unsigned int word[4]; long double value; } x = |
42e2847583f9
Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
1396 { LDBL80_WORDS (0xFFFF, 0x40000001, 0x00000000) }; |
42e2847583f9
Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
1397 char *result; |
42e2847583f9
Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
1398 int retval = |
42e2847583f9
Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
1399 my_asprintf (&result, "%Lf %d", x.value, 33, 44, 55); |
42e2847583f9
Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
1400 ASSERT (result != NULL); |
42e2847583f9
Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
1401 ASSERT (strlen (result) >= 3 + 3 |
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 && 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
|
1403 && 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
|
1404 ASSERT (retval == strlen (result)); |
42e2847583f9
Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
1405 free (result); |
42e2847583f9
Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
1406 } |
42e2847583f9
Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
1407 { /* Pseudo-Infinity. */ |
42e2847583f9
Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
1408 static union { unsigned int word[4]; long double value; } x = |
42e2847583f9
Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
1409 { LDBL80_WORDS (0xFFFF, 0x00000000, 0x00000000) }; |
42e2847583f9
Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
1410 char *result; |
42e2847583f9
Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
1411 int retval = |
42e2847583f9
Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
1412 my_asprintf (&result, "%Lf %d", x.value, 33, 44, 55); |
42e2847583f9
Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
1413 ASSERT (result != NULL); |
42e2847583f9
Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
1414 ASSERT (strlen (result) >= 3 + 3 |
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 && 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
|
1416 && 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
|
1417 ASSERT (retval == strlen (result)); |
42e2847583f9
Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
1418 free (result); |
42e2847583f9
Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
1419 } |
42e2847583f9
Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
1420 { /* Pseudo-Zero. */ |
42e2847583f9
Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
1421 static union { unsigned int word[4]; long double value; } x = |
42e2847583f9
Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
1422 { LDBL80_WORDS (0x4004, 0x00000000, 0x00000000) }; |
42e2847583f9
Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
1423 char *result; |
42e2847583f9
Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
1424 int retval = |
42e2847583f9
Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
1425 my_asprintf (&result, "%Lf %d", x.value, 33, 44, 55); |
42e2847583f9
Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
1426 ASSERT (result != NULL); |
42e2847583f9
Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
1427 ASSERT (strlen (result) >= 3 + 3 |
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 && 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
|
1429 && 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
|
1430 ASSERT (retval == strlen (result)); |
42e2847583f9
Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
1431 free (result); |
42e2847583f9
Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
1432 } |
42e2847583f9
Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
1433 { /* Unnormalized number. */ |
42e2847583f9
Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
1434 static union { unsigned int word[4]; long double value; } x = |
42e2847583f9
Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
1435 { LDBL80_WORDS (0x4000, 0x63333333, 0x00000000) }; |
42e2847583f9
Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
1436 char *result; |
42e2847583f9
Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
1437 int retval = |
42e2847583f9
Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
1438 my_asprintf (&result, "%Lf %d", x.value, 33, 44, 55); |
42e2847583f9
Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
1439 ASSERT (result != NULL); |
42e2847583f9
Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
1440 ASSERT (strlen (result) >= 3 + 3 |
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 && 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
|
1442 && 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
|
1443 ASSERT (retval == strlen (result)); |
42e2847583f9
Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
1444 free (result); |
42e2847583f9
Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
1445 } |
42e2847583f9
Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
1446 { /* Pseudo-Denormal. */ |
42e2847583f9
Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
1447 static union { unsigned int word[4]; long double value; } x = |
42e2847583f9
Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
1448 { LDBL80_WORDS (0x0000, 0x83333333, 0x00000000) }; |
42e2847583f9
Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
1449 char *result; |
42e2847583f9
Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
1450 int retval = |
42e2847583f9
Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
1451 my_asprintf (&result, "%Lf %d", x.value, 33, 44, 55); |
42e2847583f9
Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
1452 ASSERT (result != NULL); |
42e2847583f9
Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
1453 ASSERT (strlen (result) >= 3 + 3 |
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 && 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
|
1455 && 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
|
1456 ASSERT (retval == strlen (result)); |
42e2847583f9
Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
1457 free (result); |
42e2847583f9
Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
1458 } |
42e2847583f9
Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
1459 #endif |
8684
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1460 |
8804
6ce313658b4d
Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents:
8803
diff
changeset
|
1461 { /* Width. */ |
6ce313658b4d
Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents:
8803
diff
changeset
|
1462 char *result; |
6ce313658b4d
Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents:
8803
diff
changeset
|
1463 int retval = |
6ce313658b4d
Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents:
8803
diff
changeset
|
1464 my_asprintf (&result, "%10Lf %d", 1.75L, 33, 44, 55); |
6ce313658b4d
Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents:
8803
diff
changeset
|
1465 ASSERT (result != NULL); |
6ce313658b4d
Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents:
8803
diff
changeset
|
1466 ASSERT (strcmp (result, " 1.750000 33") == 0); |
6ce313658b4d
Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents:
8803
diff
changeset
|
1467 ASSERT (retval == strlen (result)); |
6ce313658b4d
Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents:
8803
diff
changeset
|
1468 free (result); |
6ce313658b4d
Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents:
8803
diff
changeset
|
1469 } |
6ce313658b4d
Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents:
8803
diff
changeset
|
1470 |
6ce313658b4d
Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents:
8803
diff
changeset
|
1471 { /* FLAG_LEFT. */ |
6ce313658b4d
Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents:
8803
diff
changeset
|
1472 char *result; |
6ce313658b4d
Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents:
8803
diff
changeset
|
1473 int retval = |
6ce313658b4d
Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents:
8803
diff
changeset
|
1474 my_asprintf (&result, "%-10Lf %d", 1.75L, 33, 44, 55); |
6ce313658b4d
Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents:
8803
diff
changeset
|
1475 ASSERT (result != NULL); |
6ce313658b4d
Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents:
8803
diff
changeset
|
1476 ASSERT (strcmp (result, "1.750000 33") == 0); |
6ce313658b4d
Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents:
8803
diff
changeset
|
1477 ASSERT (retval == strlen (result)); |
6ce313658b4d
Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents:
8803
diff
changeset
|
1478 free (result); |
6ce313658b4d
Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents:
8803
diff
changeset
|
1479 } |
6ce313658b4d
Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents:
8803
diff
changeset
|
1480 |
6ce313658b4d
Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents:
8803
diff
changeset
|
1481 { /* FLAG_SHOWSIGN. */ |
6ce313658b4d
Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents:
8803
diff
changeset
|
1482 char *result; |
6ce313658b4d
Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents:
8803
diff
changeset
|
1483 int retval = |
6ce313658b4d
Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents:
8803
diff
changeset
|
1484 my_asprintf (&result, "%+Lf %d", 1.75L, 33, 44, 55); |
6ce313658b4d
Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents:
8803
diff
changeset
|
1485 ASSERT (result != NULL); |
6ce313658b4d
Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents:
8803
diff
changeset
|
1486 ASSERT (strcmp (result, "+1.750000 33") == 0); |
6ce313658b4d
Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents:
8803
diff
changeset
|
1487 ASSERT (retval == strlen (result)); |
6ce313658b4d
Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents:
8803
diff
changeset
|
1488 free (result); |
6ce313658b4d
Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents:
8803
diff
changeset
|
1489 } |
6ce313658b4d
Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents:
8803
diff
changeset
|
1490 |
6ce313658b4d
Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents:
8803
diff
changeset
|
1491 { /* FLAG_SPACE. */ |
6ce313658b4d
Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents:
8803
diff
changeset
|
1492 char *result; |
6ce313658b4d
Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents:
8803
diff
changeset
|
1493 int retval = |
6ce313658b4d
Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents:
8803
diff
changeset
|
1494 my_asprintf (&result, "% Lf %d", 1.75L, 33, 44, 55); |
6ce313658b4d
Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents:
8803
diff
changeset
|
1495 ASSERT (result != NULL); |
6ce313658b4d
Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents:
8803
diff
changeset
|
1496 ASSERT (strcmp (result, " 1.750000 33") == 0); |
6ce313658b4d
Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents:
8803
diff
changeset
|
1497 ASSERT (retval == strlen (result)); |
6ce313658b4d
Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents:
8803
diff
changeset
|
1498 free (result); |
6ce313658b4d
Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents:
8803
diff
changeset
|
1499 } |
6ce313658b4d
Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents:
8803
diff
changeset
|
1500 |
6ce313658b4d
Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents:
8803
diff
changeset
|
1501 { /* FLAG_ALT. */ |
6ce313658b4d
Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents:
8803
diff
changeset
|
1502 char *result; |
6ce313658b4d
Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents:
8803
diff
changeset
|
1503 int retval = |
6ce313658b4d
Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents:
8803
diff
changeset
|
1504 my_asprintf (&result, "%#Lf %d", 1.75L, 33, 44, 55); |
6ce313658b4d
Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents:
8803
diff
changeset
|
1505 ASSERT (result != NULL); |
6ce313658b4d
Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents:
8803
diff
changeset
|
1506 ASSERT (strcmp (result, "1.750000 33") == 0); |
6ce313658b4d
Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents:
8803
diff
changeset
|
1507 ASSERT (retval == strlen (result)); |
6ce313658b4d
Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents:
8803
diff
changeset
|
1508 free (result); |
6ce313658b4d
Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents:
8803
diff
changeset
|
1509 } |
6ce313658b4d
Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents:
8803
diff
changeset
|
1510 |
6ce313658b4d
Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents:
8803
diff
changeset
|
1511 { /* FLAG_ALT. */ |
6ce313658b4d
Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents:
8803
diff
changeset
|
1512 char *result; |
6ce313658b4d
Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents:
8803
diff
changeset
|
1513 int retval = |
6ce313658b4d
Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents:
8803
diff
changeset
|
1514 my_asprintf (&result, "%#.Lf %d", 1.75L, 33, 44, 55); |
6ce313658b4d
Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents:
8803
diff
changeset
|
1515 ASSERT (result != NULL); |
6ce313658b4d
Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents:
8803
diff
changeset
|
1516 ASSERT (strcmp (result, "2. 33") == 0); |
6ce313658b4d
Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents:
8803
diff
changeset
|
1517 ASSERT (retval == strlen (result)); |
6ce313658b4d
Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents:
8803
diff
changeset
|
1518 free (result); |
6ce313658b4d
Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents:
8803
diff
changeset
|
1519 } |
6ce313658b4d
Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents:
8803
diff
changeset
|
1520 |
6ce313658b4d
Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents:
8803
diff
changeset
|
1521 { /* FLAG_ZERO with finite number. */ |
8684
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1522 char *result; |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1523 int retval = |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1524 my_asprintf (&result, "%015Lf %d", 1234.0L, 33, 44, 55); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1525 ASSERT (result != NULL); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1526 ASSERT (strcmp (result, "00001234.000000 33") == 0); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1527 ASSERT (retval == strlen (result)); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1528 free (result); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1529 } |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1530 |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1531 { /* FLAG_ZERO with infinite number. */ |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1532 char *result; |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1533 int retval = |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1534 my_asprintf (&result, "%015Lf %d", -1.0L / 0.0L, 33, 44, 55); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1535 ASSERT (result != NULL); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1536 ASSERT (strcmp (result, " -inf 33") == 0 |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1537 || strcmp (result, " -infinity 33") == 0); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1538 ASSERT (retval == strlen (result)); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1539 free (result); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1540 } |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1541 |
8804
6ce313658b4d
Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents:
8803
diff
changeset
|
1542 { /* FLAG_ZERO with NaN. */ |
6ce313658b4d
Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents:
8803
diff
changeset
|
1543 static long double zero = 0.0L; |
6ce313658b4d
Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents:
8803
diff
changeset
|
1544 char *result; |
6ce313658b4d
Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents:
8803
diff
changeset
|
1545 int retval = |
8870
4e1f2ea486b4
Allow for a longer printed representation of NaN.
Bruno Haible <bruno@clisp.org>
parents:
8865
diff
changeset
|
1546 my_asprintf (&result, "%050Lf %d", zero / zero, 33, 44, 55); |
8804
6ce313658b4d
Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents:
8803
diff
changeset
|
1547 ASSERT (result != NULL); |
8870
4e1f2ea486b4
Allow for a longer printed representation of NaN.
Bruno Haible <bruno@clisp.org>
parents:
8865
diff
changeset
|
1548 ASSERT (strlen (result) == 50 + 3 |
8865
9e203d8ade65
Stricter check for printf result for NaN arguments.
Bruno Haible <bruno@clisp.org>
parents:
8857
diff
changeset
|
1549 && 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
|
1550 && 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
|
1551 ASSERT (retval == strlen (result)); |
6ce313658b4d
Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents:
8803
diff
changeset
|
1552 free (result); |
6ce313658b4d
Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents:
8803
diff
changeset
|
1553 } |
6ce313658b4d
Work around an incorrect implementation of the 0 flag on most platforms.
Bruno Haible <bruno@clisp.org>
parents:
8803
diff
changeset
|
1554 |
8684
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1555 { /* Precision. */ |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1556 char *result; |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1557 int retval = |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1558 my_asprintf (&result, "%.Lf %d", 1234.0L, 33, 44, 55); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1559 ASSERT (result != NULL); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1560 ASSERT (strcmp (result, "1234 33") == 0); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1561 ASSERT (retval == strlen (result)); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1562 free (result); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1563 } |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1564 |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1565 /* 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
|
1566 |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1567 { /* A positive number. */ |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1568 char *result; |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1569 int retval = |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1570 my_asprintf (&result, "%F %d", 12.75, 33, 44, 55); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1571 ASSERT (result != NULL); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1572 ASSERT (strcmp (result, "12.750000 33") == 0); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1573 ASSERT (retval == strlen (result)); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1574 free (result); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1575 } |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1576 |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1577 { /* A larger positive number. */ |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1578 char *result; |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1579 int retval = |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1580 my_asprintf (&result, "%F %d", 1234567.0, 33, 44, 55); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1581 ASSERT (result != NULL); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1582 ASSERT (strcmp (result, "1234567.000000 33") == 0); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1583 ASSERT (retval == strlen (result)); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1584 free (result); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1585 } |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1586 |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1587 { /* A negative number. */ |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1588 char *result; |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1589 int retval = |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1590 my_asprintf (&result, "%F %d", -0.03125, 33, 44, 55); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1591 ASSERT (result != NULL); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1592 ASSERT (strcmp (result, "-0.031250 33") == 0); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1593 ASSERT (retval == strlen (result)); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1594 free (result); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1595 } |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1596 |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1597 { /* Positive zero. */ |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1598 char *result; |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1599 int retval = |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1600 my_asprintf (&result, "%F %d", 0.0, 33, 44, 55); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1601 ASSERT (result != NULL); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1602 ASSERT (strcmp (result, "0.000000 33") == 0); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1603 ASSERT (retval == strlen (result)); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1604 free (result); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1605 } |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1606 |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1607 { /* Negative zero. */ |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1608 char *result; |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1609 int retval = |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1610 my_asprintf (&result, "%F %d", -0.0, 33, 44, 55); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1611 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
|
1612 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
|
1613 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
|
1614 ASSERT (retval == strlen (result)); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1615 free (result); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1616 } |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1617 |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1618 { /* Positive infinity. */ |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1619 char *result; |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1620 int retval = |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1621 my_asprintf (&result, "%F %d", 1.0 / 0.0, 33, 44, 55); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1622 ASSERT (result != NULL); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1623 ASSERT (strcmp (result, "INF 33") == 0 |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1624 || strcmp (result, "INFINITY 33") == 0); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1625 ASSERT (retval == strlen (result)); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1626 free (result); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1627 } |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1628 |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1629 { /* Negative infinity. */ |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1630 char *result; |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1631 int retval = |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1632 my_asprintf (&result, "%F %d", -1.0 / 0.0, 33, 44, 55); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1633 ASSERT (result != NULL); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1634 ASSERT (strcmp (result, "-INF 33") == 0 |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1635 || strcmp (result, "-INFINITY 33") == 0); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1636 ASSERT (retval == strlen (result)); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1637 free (result); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1638 } |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1639 |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1640 { /* NaN. */ |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1641 char *result; |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1642 int retval = |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1643 my_asprintf (&result, "%F %d", NaN (), 33, 44, 55); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1644 ASSERT (result != NULL); |
8850
d1fe16dfbfee
Avoid test failures on IRIX 6.5.
Bruno Haible <bruno@clisp.org>
parents:
8839
diff
changeset
|
1645 ASSERT (strlen (result) >= 3 + 3 |
8865
9e203d8ade65
Stricter check for printf result for NaN arguments.
Bruno Haible <bruno@clisp.org>
parents:
8857
diff
changeset
|
1646 && 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
|
1647 && 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
|
1648 ASSERT (retval == strlen (result)); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1649 free (result); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1650 } |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1651 |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1652 { /* FLAG_ZERO. */ |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1653 char *result; |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1654 int retval = |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1655 my_asprintf (&result, "%015F %d", 1234.0, 33, 44, 55); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1656 ASSERT (result != NULL); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1657 ASSERT (strcmp (result, "00001234.000000 33") == 0); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1658 ASSERT (retval == strlen (result)); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1659 free (result); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1660 } |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1661 |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1662 { /* FLAG_ZERO with infinite number. */ |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1663 char *result; |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1664 int retval = |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1665 my_asprintf (&result, "%015F %d", -1.0 / 0.0, 33, 44, 55); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1666 ASSERT (result != NULL); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1667 ASSERT (strcmp (result, " -INF 33") == 0 |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1668 || strcmp (result, " -INFINITY 33") == 0); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1669 ASSERT (retval == strlen (result)); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1670 free (result); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1671 } |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1672 |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1673 { /* Precision. */ |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1674 char *result; |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1675 int retval = |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1676 my_asprintf (&result, "%.F %d", 1234.0, 33, 44, 55); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1677 ASSERT (result != NULL); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1678 ASSERT (strcmp (result, "1234 33") == 0); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1679 ASSERT (retval == strlen (result)); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1680 free (result); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1681 } |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1682 |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1683 { /* A positive number. */ |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1684 char *result; |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1685 int retval = |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1686 my_asprintf (&result, "%LF %d", 12.75L, 33, 44, 55); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1687 ASSERT (result != NULL); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1688 ASSERT (strcmp (result, "12.750000 33") == 0); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1689 ASSERT (retval == strlen (result)); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1690 free (result); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1691 } |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1692 |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1693 { /* A larger positive number. */ |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1694 char *result; |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1695 int retval = |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1696 my_asprintf (&result, "%LF %d", 1234567.0L, 33, 44, 55); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1697 ASSERT (result != NULL); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1698 ASSERT (strcmp (result, "1234567.000000 33") == 0); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1699 ASSERT (retval == strlen (result)); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1700 free (result); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1701 } |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1702 |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1703 { /* A negative number. */ |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1704 char *result; |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1705 int retval = |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1706 my_asprintf (&result, "%LF %d", -0.03125L, 33, 44, 55); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1707 ASSERT (result != NULL); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1708 ASSERT (strcmp (result, "-0.031250 33") == 0); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1709 ASSERT (retval == strlen (result)); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1710 free (result); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1711 } |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1712 |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1713 { /* Positive zero. */ |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1714 char *result; |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1715 int retval = |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1716 my_asprintf (&result, "%LF %d", 0.0L, 33, 44, 55); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1717 ASSERT (result != NULL); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1718 ASSERT (strcmp (result, "0.000000 33") == 0); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1719 ASSERT (retval == strlen (result)); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1720 free (result); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1721 } |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1722 |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1723 { /* Negative zero. */ |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1724 char *result; |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1725 int retval = |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1726 my_asprintf (&result, "%LF %d", -0.0L, 33, 44, 55); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1727 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
|
1728 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
|
1729 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
|
1730 ASSERT (retval == strlen (result)); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1731 free (result); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1732 } |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1733 |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1734 { /* Positive infinity. */ |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1735 char *result; |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1736 int retval = |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1737 my_asprintf (&result, "%LF %d", 1.0L / 0.0L, 33, 44, 55); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1738 ASSERT (result != NULL); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1739 ASSERT (strcmp (result, "INF 33") == 0 |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1740 || strcmp (result, "INFINITY 33") == 0); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1741 ASSERT (retval == strlen (result)); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1742 free (result); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1743 } |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1744 |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1745 { /* Negative infinity. */ |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1746 char *result; |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1747 int retval = |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1748 my_asprintf (&result, "%LF %d", -1.0L / 0.0L, 33, 44, 55); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1749 ASSERT (result != NULL); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1750 ASSERT (strcmp (result, "-INF 33") == 0 |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1751 || strcmp (result, "-INFINITY 33") == 0); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1752 ASSERT (retval == strlen (result)); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1753 free (result); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1754 } |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1755 |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1756 { /* NaN. */ |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1757 static long double zero = 0.0L; |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1758 char *result; |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1759 int retval = |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1760 my_asprintf (&result, "%LF %d", zero / zero, 33, 44, 55); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1761 ASSERT (result != NULL); |
8850
d1fe16dfbfee
Avoid test failures on IRIX 6.5.
Bruno Haible <bruno@clisp.org>
parents:
8839
diff
changeset
|
1762 ASSERT (strlen (result) >= 3 + 3 |
8865
9e203d8ade65
Stricter check for printf result for NaN arguments.
Bruno Haible <bruno@clisp.org>
parents:
8857
diff
changeset
|
1763 && 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
|
1764 && 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
|
1765 ASSERT (retval == strlen (result)); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1766 free (result); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1767 } |
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 { /* FLAG_ZERO. */ |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1770 char *result; |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1771 int retval = |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1772 my_asprintf (&result, "%015LF %d", 1234.0L, 33, 44, 55); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1773 ASSERT (result != NULL); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1774 ASSERT (strcmp (result, "00001234.000000 33") == 0); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1775 ASSERT (retval == strlen (result)); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1776 free (result); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1777 } |
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 { /* FLAG_ZERO with infinite number. */ |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1780 char *result; |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1781 int retval = |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1782 my_asprintf (&result, "%015LF %d", -1.0L / 0.0L, 33, 44, 55); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1783 ASSERT (result != NULL); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1784 ASSERT (strcmp (result, " -INF 33") == 0 |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1785 || strcmp (result, " -INFINITY 33") == 0); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1786 ASSERT (retval == 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 { /* Precision. */ |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1791 char *result; |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1792 int retval = |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1793 my_asprintf (&result, "%.LF %d", 1234.0L, 33, 44, 55); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1794 ASSERT (result != NULL); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1795 ASSERT (strcmp (result, "1234 33") == 0); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1796 ASSERT (retval == strlen (result)); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1797 free (result); |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1798 } |
9ea5590b49d1
Add tests for %f and %F directives.
Bruno Haible <bruno@clisp.org>
parents:
8662
diff
changeset
|
1799 |
8836
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
1800 /* 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
|
1801 |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
1802 { /* A positive number. */ |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
1803 char *result; |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
1804 int retval = |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
1805 my_asprintf (&result, "%e %d", 12.75, 33, 44, 55); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
1806 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
|
1807 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
|
1808 || 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
|
1809 ASSERT (retval == strlen (result)); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
1810 free (result); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
1811 } |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
1812 |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
1813 { /* A larger positive number. */ |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
1814 char *result; |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
1815 int retval = |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
1816 my_asprintf (&result, "%e %d", 1234567.0, 33, 44, 55); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
1817 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
|
1818 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
|
1819 || 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
|
1820 ASSERT (retval == strlen (result)); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
1821 free (result); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
1822 } |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
1823 |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
1824 { /* Small and large positive numbers. */ |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
1825 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
|
1826 { |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
1827 { 1.234321234321234e-37, "1.234321e-37" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
1828 { 1.234321234321234e-36, "1.234321e-36" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
1829 { 1.234321234321234e-35, "1.234321e-35" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
1830 { 1.234321234321234e-34, "1.234321e-34" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
1831 { 1.234321234321234e-33, "1.234321e-33" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
1832 { 1.234321234321234e-32, "1.234321e-32" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
1833 { 1.234321234321234e-31, "1.234321e-31" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
1834 { 1.234321234321234e-30, "1.234321e-30" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
1835 { 1.234321234321234e-29, "1.234321e-29" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
1836 { 1.234321234321234e-28, "1.234321e-28" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
1837 { 1.234321234321234e-27, "1.234321e-27" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
1838 { 1.234321234321234e-26, "1.234321e-26" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
1839 { 1.234321234321234e-25, "1.234321e-25" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
1840 { 1.234321234321234e-24, "1.234321e-24" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
1841 { 1.234321234321234e-23, "1.234321e-23" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
1842 { 1.234321234321234e-22, "1.234321e-22" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
1843 { 1.234321234321234e-21, "1.234321e-21" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
1844 { 1.234321234321234e-20, "1.234321e-20" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
1845 { 1.234321234321234e-19, "1.234321e-19" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
1846 { 1.234321234321234e-18, "1.234321e-18" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
1847 { 1.234321234321234e-17, "1.234321e-17" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
1848 { 1.234321234321234e-16, "1.234321e-16" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
1849 { 1.234321234321234e-15, "1.234321e-15" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
1850 { 1.234321234321234e-14, "1.234321e-14" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
1851 { 1.234321234321234e-13, "1.234321e-13" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
1852 { 1.234321234321234e-12, "1.234321e-12" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
1853 { 1.234321234321234e-11, "1.234321e-11" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
1854 { 1.234321234321234e-10, "1.234321e-10" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
1855 { 1.234321234321234e-9, "1.234321e-09" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
1856 { 1.234321234321234e-8, "1.234321e-08" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
1857 { 1.234321234321234e-7, "1.234321e-07" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
1858 { 1.234321234321234e-6, "1.234321e-06" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
1859 { 1.234321234321234e-5, "1.234321e-05" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
1860 { 1.234321234321234e-4, "1.234321e-04" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
1861 { 1.234321234321234e-3, "1.234321e-03" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
1862 { 1.234321234321234e-2, "1.234321e-02" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
1863 { 1.234321234321234e-1, "1.234321e-01" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
1864 { 1.234321234321234, "1.234321e+00" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
1865 { 1.234321234321234e1, "1.234321e+01" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
1866 { 1.234321234321234e2, "1.234321e+02" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
1867 { 1.234321234321234e3, "1.234321e+03" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
1868 { 1.234321234321234e4, "1.234321e+04" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
1869 { 1.234321234321234e5, "1.234321e+05" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
1870 { 1.234321234321234e6, "1.234321e+06" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
1871 { 1.234321234321234e7, "1.234321e+07" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
1872 { 1.234321234321234e8, "1.234321e+08" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
1873 { 1.234321234321234e9, "1.234321e+09" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
1874 { 1.234321234321234e10, "1.234321e+10" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
1875 { 1.234321234321234e11, "1.234321e+11" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
1876 { 1.234321234321234e12, "1.234321e+12" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
1877 { 1.234321234321234e13, "1.234321e+13" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
1878 { 1.234321234321234e14, "1.234321e+14" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
1879 { 1.234321234321234e15, "1.234321e+15" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
1880 { 1.234321234321234e16, "1.234321e+16" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
1881 { 1.234321234321234e17, "1.234321e+17" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
1882 { 1.234321234321234e18, "1.234321e+18" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
1883 { 1.234321234321234e19, "1.234321e+19" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
1884 { 1.234321234321234e20, "1.234321e+20" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
1885 { 1.234321234321234e21, "1.234321e+21" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
1886 { 1.234321234321234e22, "1.234321e+22" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
1887 { 1.234321234321234e23, "1.234321e+23" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
1888 { 1.234321234321234e24, "1.234321e+24" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
1889 { 1.234321234321234e25, "1.234321e+25" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
1890 { 1.234321234321234e26, "1.234321e+26" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
1891 { 1.234321234321234e27, "1.234321e+27" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
1892 { 1.234321234321234e28, "1.234321e+28" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
1893 { 1.234321234321234e29, "1.234321e+29" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
1894 { 1.234321234321234e30, "1.234321e+30" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
1895 { 1.234321234321234e31, "1.234321e+31" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
1896 { 1.234321234321234e32, "1.234321e+32" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
1897 { 1.234321234321234e33, "1.234321e+33" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
1898 { 1.234321234321234e34, "1.234321e+34" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
1899 { 1.234321234321234e35, "1.234321e+35" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
1900 { 1.234321234321234e36, "1.234321e+36" } |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
1901 }; |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
1902 size_t k; |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
1903 for (k = 0; k < SIZEOF (data); k++) |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
1904 { |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
1905 char *result; |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
1906 int retval = |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
1907 my_asprintf (&result, "%e", data[k].value); |
8839
5efc1d668039
Accomodate for implementations that produce 3 exponent digits in %e and %g.
Bruno Haible <bruno@clisp.org>
parents:
8836
diff
changeset
|
1908 const char *expected = data[k].string; |
8836
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
1909 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
|
1910 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
|
1911 /* 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
|
1912 || (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
|
1913 && 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
|
1914 && 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
|
1915 && 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
|
1916 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
|
1917 == 0)); |
8836
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
1918 ASSERT (retval == strlen (result)); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
1919 free (result); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
1920 } |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
1921 } |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
1922 |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
1923 { /* A negative number. */ |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
1924 char *result; |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
1925 int retval = |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
1926 my_asprintf (&result, "%e %d", -0.03125, 33, 44, 55); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
1927 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
|
1928 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
|
1929 || 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
|
1930 ASSERT (retval == strlen (result)); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
1931 free (result); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
1932 } |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
1933 |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
1934 { /* Positive zero. */ |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
1935 char *result; |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
1936 int retval = |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
1937 my_asprintf (&result, "%e %d", 0.0, 33, 44, 55); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
1938 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
|
1939 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
|
1940 || 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
|
1941 ASSERT (retval == strlen (result)); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
1942 free (result); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
1943 } |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
1944 |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
1945 { /* Negative zero. */ |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
1946 char *result; |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
1947 int retval = |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
1948 my_asprintf (&result, "%e %d", -0.0, 33, 44, 55); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
1949 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
|
1950 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
|
1951 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
|
1952 || 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
|
1953 ASSERT (retval == strlen (result)); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
1954 free (result); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
1955 } |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
1956 |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
1957 { /* Positive infinity. */ |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
1958 char *result; |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
1959 int retval = |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
1960 my_asprintf (&result, "%e %d", 1.0 / 0.0, 33, 44, 55); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
1961 ASSERT (result != NULL); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
1962 ASSERT (strcmp (result, "inf 33") == 0 |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
1963 || strcmp (result, "infinity 33") == 0); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
1964 ASSERT (retval == strlen (result)); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
1965 free (result); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
1966 } |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
1967 |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
1968 { /* Negative infinity. */ |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
1969 char *result; |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
1970 int retval = |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
1971 my_asprintf (&result, "%e %d", -1.0 / 0.0, 33, 44, 55); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
1972 ASSERT (result != NULL); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
1973 ASSERT (strcmp (result, "-inf 33") == 0 |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
1974 || strcmp (result, "-infinity 33") == 0); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
1975 ASSERT (retval == strlen (result)); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
1976 free (result); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
1977 } |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
1978 |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
1979 { /* NaN. */ |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
1980 char *result; |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
1981 int retval = |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
1982 my_asprintf (&result, "%e %d", NaN (), 33, 44, 55); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
1983 ASSERT (result != NULL); |
8850
d1fe16dfbfee
Avoid test failures on IRIX 6.5.
Bruno Haible <bruno@clisp.org>
parents:
8839
diff
changeset
|
1984 ASSERT (strlen (result) >= 3 + 3 |
8865
9e203d8ade65
Stricter check for printf result for NaN arguments.
Bruno Haible <bruno@clisp.org>
parents:
8857
diff
changeset
|
1985 && 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
|
1986 && 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
|
1987 ASSERT (retval == strlen (result)); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
1988 free (result); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
1989 } |
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 { /* Width. */ |
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 int retval = |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
1994 my_asprintf (&result, "%15e %d", 1.75, 33, 44, 55); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
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, " 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
|
1997 || 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
|
1998 ASSERT (retval == strlen (result)); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
1999 free (result); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2000 } |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2001 |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2002 { /* FLAG_LEFT. */ |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2003 char *result; |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2004 int retval = |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2005 my_asprintf (&result, "%-15e %d", 1.75, 33, 44, 55); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2006 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
|
2007 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
|
2008 || 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
|
2009 ASSERT (retval == strlen (result)); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2010 free (result); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2011 } |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2012 |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2013 { /* FLAG_SHOWSIGN. */ |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2014 char *result; |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2015 int retval = |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2016 my_asprintf (&result, "%+e %d", 1.75, 33, 44, 55); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2017 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
|
2018 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
|
2019 || 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
|
2020 ASSERT (retval == strlen (result)); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2021 free (result); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2022 } |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2023 |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2024 { /* FLAG_SPACE. */ |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2025 char *result; |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2026 int retval = |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2027 my_asprintf (&result, "% e %d", 1.75, 33, 44, 55); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2028 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
|
2029 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
|
2030 || 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
|
2031 ASSERT (retval == strlen (result)); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2032 free (result); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2033 } |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2034 |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2035 { /* FLAG_ALT. */ |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2036 char *result; |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2037 int retval = |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2038 my_asprintf (&result, "%#e %d", 1.75, 33, 44, 55); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2039 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
|
2040 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
|
2041 || 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
|
2042 ASSERT (retval == strlen (result)); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2043 free (result); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2044 } |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2045 |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2046 { /* FLAG_ALT. */ |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2047 char *result; |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2048 int retval = |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2049 my_asprintf (&result, "%#.e %d", 1.75, 33, 44, 55); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2050 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
|
2051 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
|
2052 || 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
|
2053 ASSERT (retval == strlen (result)); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2054 free (result); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2055 } |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2056 |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2057 { /* FLAG_ALT. */ |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2058 char *result; |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2059 int retval = |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2060 my_asprintf (&result, "%#.e %d", 9.75, 33, 44, 55); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2061 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
|
2062 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
|
2063 || 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
|
2064 ASSERT (retval == strlen (result)); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2065 free (result); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2066 } |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2067 |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2068 { /* FLAG_ZERO with finite number. */ |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2069 char *result; |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2070 int retval = |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2071 my_asprintf (&result, "%015e %d", 1234.0, 33, 44, 55); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2072 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
|
2073 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
|
2074 || 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
|
2075 ASSERT (retval == strlen (result)); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2076 free (result); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2077 } |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2078 |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2079 { /* FLAG_ZERO with infinite number. */ |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2080 char *result; |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2081 int retval = |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2082 my_asprintf (&result, "%015e %d", -1.0 / 0.0, 33, 44, 55); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2083 ASSERT (result != NULL); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2084 ASSERT (strcmp (result, " -inf 33") == 0 |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2085 || strcmp (result, " -infinity 33") == 0); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2086 ASSERT (retval == strlen (result)); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2087 free (result); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2088 } |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2089 |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2090 { /* FLAG_ZERO with NaN. */ |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2091 char *result; |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2092 int retval = |
8870
4e1f2ea486b4
Allow for a longer printed representation of NaN.
Bruno Haible <bruno@clisp.org>
parents:
8865
diff
changeset
|
2093 my_asprintf (&result, "%050e %d", NaN (), 33, 44, 55); |
8836
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2094 ASSERT (result != NULL); |
8870
4e1f2ea486b4
Allow for a longer printed representation of NaN.
Bruno Haible <bruno@clisp.org>
parents:
8865
diff
changeset
|
2095 ASSERT (strlen (result) == 50 + 3 |
8865
9e203d8ade65
Stricter check for printf result for NaN arguments.
Bruno Haible <bruno@clisp.org>
parents:
8857
diff
changeset
|
2096 && 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
|
2097 && 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
|
2098 ASSERT (retval == strlen (result)); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2099 free (result); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2100 } |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2101 |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2102 { /* Precision. */ |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2103 char *result; |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2104 int retval = |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2105 my_asprintf (&result, "%.e %d", 1234.0, 33, 44, 55); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2106 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
|
2107 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
|
2108 || strcmp (result, "1e+003 33") == 0); |
8836
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2109 ASSERT (retval == strlen (result)); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2110 free (result); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2111 } |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2112 |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2113 { /* A positive number. */ |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2114 char *result; |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2115 int retval = |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2116 my_asprintf (&result, "%Le %d", 12.75L, 33, 44, 55); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2117 ASSERT (result != NULL); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2118 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
|
2119 ASSERT (retval == strlen (result)); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2120 free (result); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2121 } |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2122 |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2123 { /* A larger positive number. */ |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2124 char *result; |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2125 int retval = |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2126 my_asprintf (&result, "%Le %d", 1234567.0L, 33, 44, 55); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2127 ASSERT (result != NULL); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2128 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
|
2129 ASSERT (retval == strlen (result)); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2130 free (result); |
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 |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2133 { /* Small and large positive numbers. */ |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2134 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
|
2135 { |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2136 { 1.234321234321234e-37L, "1.234321e-37" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2137 { 1.234321234321234e-36L, "1.234321e-36" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2138 { 1.234321234321234e-35L, "1.234321e-35" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2139 { 1.234321234321234e-34L, "1.234321e-34" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2140 { 1.234321234321234e-33L, "1.234321e-33" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2141 { 1.234321234321234e-32L, "1.234321e-32" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2142 { 1.234321234321234e-31L, "1.234321e-31" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2143 { 1.234321234321234e-30L, "1.234321e-30" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2144 { 1.234321234321234e-29L, "1.234321e-29" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2145 { 1.234321234321234e-28L, "1.234321e-28" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2146 { 1.234321234321234e-27L, "1.234321e-27" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2147 { 1.234321234321234e-26L, "1.234321e-26" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2148 { 1.234321234321234e-25L, "1.234321e-25" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2149 { 1.234321234321234e-24L, "1.234321e-24" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2150 { 1.234321234321234e-23L, "1.234321e-23" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2151 { 1.234321234321234e-22L, "1.234321e-22" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2152 { 1.234321234321234e-21L, "1.234321e-21" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2153 { 1.234321234321234e-20L, "1.234321e-20" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2154 { 1.234321234321234e-19L, "1.234321e-19" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2155 { 1.234321234321234e-18L, "1.234321e-18" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2156 { 1.234321234321234e-17L, "1.234321e-17" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2157 { 1.234321234321234e-16L, "1.234321e-16" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2158 { 1.234321234321234e-15L, "1.234321e-15" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2159 { 1.234321234321234e-14L, "1.234321e-14" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2160 { 1.234321234321234e-13L, "1.234321e-13" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2161 { 1.234321234321234e-12L, "1.234321e-12" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2162 { 1.234321234321234e-11L, "1.234321e-11" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2163 { 1.234321234321234e-10L, "1.234321e-10" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2164 { 1.234321234321234e-9L, "1.234321e-09" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2165 { 1.234321234321234e-8L, "1.234321e-08" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2166 { 1.234321234321234e-7L, "1.234321e-07" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2167 { 1.234321234321234e-6L, "1.234321e-06" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2168 { 1.234321234321234e-5L, "1.234321e-05" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2169 { 1.234321234321234e-4L, "1.234321e-04" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2170 { 1.234321234321234e-3L, "1.234321e-03" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2171 { 1.234321234321234e-2L, "1.234321e-02" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2172 { 1.234321234321234e-1L, "1.234321e-01" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2173 { 1.234321234321234L, "1.234321e+00" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2174 { 1.234321234321234e1L, "1.234321e+01" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2175 { 1.234321234321234e2L, "1.234321e+02" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2176 { 1.234321234321234e3L, "1.234321e+03" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2177 { 1.234321234321234e4L, "1.234321e+04" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2178 { 1.234321234321234e5L, "1.234321e+05" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2179 { 1.234321234321234e6L, "1.234321e+06" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2180 { 1.234321234321234e7L, "1.234321e+07" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2181 { 1.234321234321234e8L, "1.234321e+08" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2182 { 1.234321234321234e9L, "1.234321e+09" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2183 { 1.234321234321234e10L, "1.234321e+10" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2184 { 1.234321234321234e11L, "1.234321e+11" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2185 { 1.234321234321234e12L, "1.234321e+12" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2186 { 1.234321234321234e13L, "1.234321e+13" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2187 { 1.234321234321234e14L, "1.234321e+14" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2188 { 1.234321234321234e15L, "1.234321e+15" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2189 { 1.234321234321234e16L, "1.234321e+16" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2190 { 1.234321234321234e17L, "1.234321e+17" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2191 { 1.234321234321234e18L, "1.234321e+18" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2192 { 1.234321234321234e19L, "1.234321e+19" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2193 { 1.234321234321234e20L, "1.234321e+20" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2194 { 1.234321234321234e21L, "1.234321e+21" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2195 { 1.234321234321234e22L, "1.234321e+22" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2196 { 1.234321234321234e23L, "1.234321e+23" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2197 { 1.234321234321234e24L, "1.234321e+24" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2198 { 1.234321234321234e25L, "1.234321e+25" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2199 { 1.234321234321234e26L, "1.234321e+26" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2200 { 1.234321234321234e27L, "1.234321e+27" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2201 { 1.234321234321234e28L, "1.234321e+28" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2202 { 1.234321234321234e29L, "1.234321e+29" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2203 { 1.234321234321234e30L, "1.234321e+30" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2204 { 1.234321234321234e31L, "1.234321e+31" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2205 { 1.234321234321234e32L, "1.234321e+32" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2206 { 1.234321234321234e33L, "1.234321e+33" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2207 { 1.234321234321234e34L, "1.234321e+34" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2208 { 1.234321234321234e35L, "1.234321e+35" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2209 { 1.234321234321234e36L, "1.234321e+36" } |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2210 }; |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2211 size_t k; |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2212 for (k = 0; k < SIZEOF (data); k++) |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2213 { |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2214 char *result; |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2215 int retval = |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2216 my_asprintf (&result, "%Le", data[k].value); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2217 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
|
2218 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
|
2219 ASSERT (retval == strlen (result)); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2220 free (result); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2221 } |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2222 } |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2223 |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2224 { /* A negative number. */ |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2225 char *result; |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2226 int retval = |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2227 my_asprintf (&result, "%Le %d", -0.03125L, 33, 44, 55); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2228 ASSERT (result != NULL); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2229 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
|
2230 ASSERT (retval == strlen (result)); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2231 free (result); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2232 } |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2233 |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2234 { /* Positive zero. */ |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2235 char *result; |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2236 int retval = |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2237 my_asprintf (&result, "%Le %d", 0.0L, 33, 44, 55); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2238 ASSERT (result != NULL); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2239 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
|
2240 ASSERT (retval == strlen (result)); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2241 free (result); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2242 } |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2243 |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2244 { /* Negative zero. */ |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2245 char *result; |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2246 int retval = |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2247 my_asprintf (&result, "%Le %d", -0.0L, 33, 44, 55); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2248 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
|
2249 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
|
2250 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
|
2251 ASSERT (retval == strlen (result)); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2252 free (result); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2253 } |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2254 |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2255 { /* Positive infinity. */ |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2256 char *result; |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2257 int retval = |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2258 my_asprintf (&result, "%Le %d", 1.0L / 0.0L, 33, 44, 55); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2259 ASSERT (result != NULL); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2260 ASSERT (strcmp (result, "inf 33") == 0 |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2261 || strcmp (result, "infinity 33") == 0); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2262 ASSERT (retval == strlen (result)); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2263 free (result); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2264 } |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2265 |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2266 { /* Negative infinity. */ |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2267 char *result; |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2268 int retval = |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2269 my_asprintf (&result, "%Le %d", -1.0L / 0.0L, 33, 44, 55); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2270 ASSERT (result != NULL); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2271 ASSERT (strcmp (result, "-inf 33") == 0 |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2272 || strcmp (result, "-infinity 33") == 0); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2273 ASSERT (retval == strlen (result)); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2274 free (result); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2275 } |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2276 |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2277 { /* NaN. */ |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2278 static long double zero = 0.0L; |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2279 char *result; |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2280 int retval = |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2281 my_asprintf (&result, "%Le %d", zero / zero, 33, 44, 55); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2282 ASSERT (result != NULL); |
8850
d1fe16dfbfee
Avoid test failures on IRIX 6.5.
Bruno Haible <bruno@clisp.org>
parents:
8839
diff
changeset
|
2283 ASSERT (strlen (result) >= 3 + 3 |
8865
9e203d8ade65
Stricter check for printf result for NaN arguments.
Bruno Haible <bruno@clisp.org>
parents:
8857
diff
changeset
|
2284 && 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
|
2285 && 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
|
2286 ASSERT (retval == strlen (result)); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2287 free (result); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2288 } |
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
|
2289 #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
|
2290 { /* 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
|
2291 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
|
2292 { 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
|
2293 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
|
2294 int retval = |
42e2847583f9
Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
2295 my_asprintf (&result, "%Le %d", x.value, 33, 44, 55); |
42e2847583f9
Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
2296 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
|
2297 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
|
2298 && 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
|
2299 && 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
|
2300 ASSERT (retval == strlen (result)); |
42e2847583f9
Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
2301 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
|
2302 } |
42e2847583f9
Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
2303 { |
42e2847583f9
Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
2304 /* 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
|
2305 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
|
2306 { 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
|
2307 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
|
2308 int retval = |
42e2847583f9
Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
2309 my_asprintf (&result, "%Le %d", x.value, 33, 44, 55); |
42e2847583f9
Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
2310 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
|
2311 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
|
2312 && 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
|
2313 && 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
|
2314 ASSERT (retval == strlen (result)); |
42e2847583f9
Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
2315 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
|
2316 } |
42e2847583f9
Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
2317 /* 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
|
2318 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
|
2319 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
|
2320 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
|
2321 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
|
2322 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
|
2323 */ |
42e2847583f9
Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
2324 { /* 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
|
2325 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
|
2326 { 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
|
2327 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
|
2328 int retval = |
42e2847583f9
Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
2329 my_asprintf (&result, "%Le %d", x.value, 33, 44, 55); |
42e2847583f9
Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
2330 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
|
2331 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
|
2332 && 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
|
2333 && 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
|
2334 ASSERT (retval == strlen (result)); |
42e2847583f9
Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
2335 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
|
2336 } |
42e2847583f9
Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
2337 { /* 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
|
2338 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
|
2339 { 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
|
2340 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
|
2341 int retval = |
42e2847583f9
Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
2342 my_asprintf (&result, "%Le %d", x.value, 33, 44, 55); |
42e2847583f9
Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
2343 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
|
2344 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
|
2345 && 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
|
2346 && 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
|
2347 ASSERT (retval == strlen (result)); |
42e2847583f9
Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
2348 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
|
2349 } |
42e2847583f9
Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
2350 { /* 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
|
2351 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
|
2352 { 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
|
2353 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
|
2354 int retval = |
42e2847583f9
Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
2355 my_asprintf (&result, "%Le %d", x.value, 33, 44, 55); |
42e2847583f9
Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
2356 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
|
2357 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
|
2358 && 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
|
2359 && 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
|
2360 ASSERT (retval == strlen (result)); |
42e2847583f9
Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
2361 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
|
2362 } |
42e2847583f9
Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
2363 { /* 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
|
2364 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
|
2365 { 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
|
2366 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
|
2367 int retval = |
42e2847583f9
Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
2368 my_asprintf (&result, "%Le %d", x.value, 33, 44, 55); |
42e2847583f9
Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
2369 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
|
2370 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
|
2371 && 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
|
2372 && 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
|
2373 ASSERT (retval == strlen (result)); |
42e2847583f9
Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
2374 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
|
2375 } |
42e2847583f9
Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
2376 { /* 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
|
2377 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
|
2378 { 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
|
2379 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
|
2380 int retval = |
42e2847583f9
Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
2381 my_asprintf (&result, "%Le %d", x.value, 33, 44, 55); |
42e2847583f9
Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
2382 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
|
2383 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
|
2384 && 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
|
2385 && 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
|
2386 ASSERT (retval == strlen (result)); |
42e2847583f9
Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
2387 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
|
2388 } |
42e2847583f9
Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
2389 #endif |
8836
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2390 |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2391 { /* Width. */ |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2392 char *result; |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2393 int retval = |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2394 my_asprintf (&result, "%15Le %d", 1.75L, 33, 44, 55); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2395 ASSERT (result != NULL); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2396 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
|
2397 ASSERT (retval == strlen (result)); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2398 free (result); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2399 } |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2400 |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2401 { /* FLAG_LEFT. */ |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2402 char *result; |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2403 int retval = |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2404 my_asprintf (&result, "%-15Le %d", 1.75L, 33, 44, 55); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2405 ASSERT (result != NULL); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2406 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
|
2407 ASSERT (retval == strlen (result)); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2408 free (result); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2409 } |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2410 |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2411 { /* FLAG_SHOWSIGN. */ |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2412 char *result; |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2413 int retval = |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2414 my_asprintf (&result, "%+Le %d", 1.75L, 33, 44, 55); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2415 ASSERT (result != NULL); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2416 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
|
2417 ASSERT (retval == strlen (result)); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2418 free (result); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2419 } |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2420 |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2421 { /* FLAG_SPACE. */ |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2422 char *result; |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2423 int retval = |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2424 my_asprintf (&result, "% Le %d", 1.75L, 33, 44, 55); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2425 ASSERT (result != NULL); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2426 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
|
2427 ASSERT (retval == strlen (result)); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2428 free (result); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2429 } |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2430 |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2431 { /* FLAG_ALT. */ |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2432 char *result; |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2433 int retval = |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2434 my_asprintf (&result, "%#Le %d", 1.75L, 33, 44, 55); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2435 ASSERT (result != NULL); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2436 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
|
2437 ASSERT (retval == strlen (result)); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2438 free (result); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2439 } |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2440 |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2441 { /* FLAG_ALT. */ |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2442 char *result; |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2443 int retval = |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2444 my_asprintf (&result, "%#.Le %d", 1.75L, 33, 44, 55); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2445 ASSERT (result != NULL); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2446 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
|
2447 ASSERT (retval == strlen (result)); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2448 free (result); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2449 } |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2450 |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2451 { /* FLAG_ALT. */ |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2452 char *result; |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2453 int retval = |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2454 my_asprintf (&result, "%#.Le %d", 9.75L, 33, 44, 55); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2455 ASSERT (result != NULL); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2456 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
|
2457 ASSERT (retval == strlen (result)); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2458 free (result); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2459 } |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2460 |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2461 { /* FLAG_ZERO with finite number. */ |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2462 char *result; |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2463 int retval = |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2464 my_asprintf (&result, "%015Le %d", 1234.0L, 33, 44, 55); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2465 ASSERT (result != NULL); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2466 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
|
2467 ASSERT (retval == strlen (result)); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2468 free (result); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2469 } |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2470 |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2471 { /* FLAG_ZERO with infinite number. */ |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2472 char *result; |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2473 int retval = |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2474 my_asprintf (&result, "%015Le %d", -1.0L / 0.0L, 33, 44, 55); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2475 ASSERT (result != NULL); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2476 ASSERT (strcmp (result, " -inf 33") == 0 |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2477 || strcmp (result, " -infinity 33") == 0); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2478 ASSERT (retval == strlen (result)); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2479 free (result); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2480 } |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2481 |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2482 { /* FLAG_ZERO with NaN. */ |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2483 static long double zero = 0.0L; |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2484 char *result; |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2485 int retval = |
8870
4e1f2ea486b4
Allow for a longer printed representation of NaN.
Bruno Haible <bruno@clisp.org>
parents:
8865
diff
changeset
|
2486 my_asprintf (&result, "%050Le %d", zero / zero, 33, 44, 55); |
8836
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2487 ASSERT (result != NULL); |
8870
4e1f2ea486b4
Allow for a longer printed representation of NaN.
Bruno Haible <bruno@clisp.org>
parents:
8865
diff
changeset
|
2488 ASSERT (strlen (result) == 50 + 3 |
8865
9e203d8ade65
Stricter check for printf result for NaN arguments.
Bruno Haible <bruno@clisp.org>
parents:
8857
diff
changeset
|
2489 && 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
|
2490 && 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
|
2491 ASSERT (retval == strlen (result)); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2492 free (result); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2493 } |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2494 |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2495 { /* Precision. */ |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2496 char *result; |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2497 int retval = |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2498 my_asprintf (&result, "%.Le %d", 1234.0L, 33, 44, 55); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2499 ASSERT (result != NULL); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2500 ASSERT (strcmp (result, "1e+03 33") == 0); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2501 ASSERT (retval == strlen (result)); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2502 free (result); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2503 } |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2504 |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2505 /* 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
|
2506 |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2507 { /* A positive number. */ |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2508 char *result; |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2509 int retval = |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2510 my_asprintf (&result, "%g %d", 12.75, 33, 44, 55); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2511 ASSERT (result != NULL); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2512 ASSERT (strcmp (result, "12.75 33") == 0); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2513 ASSERT (retval == strlen (result)); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2514 free (result); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2515 } |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2516 |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2517 { /* A larger positive number. */ |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2518 char *result; |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2519 int retval = |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2520 my_asprintf (&result, "%g %d", 1234567.0, 33, 44, 55); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2521 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
|
2522 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
|
2523 || 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
|
2524 ASSERT (retval == 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 { /* Small and large positive numbers. */ |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2529 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
|
2530 { |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2531 { 1.234321234321234e-37, "1.23432e-37" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2532 { 1.234321234321234e-36, "1.23432e-36" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2533 { 1.234321234321234e-35, "1.23432e-35" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2534 { 1.234321234321234e-34, "1.23432e-34" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2535 { 1.234321234321234e-33, "1.23432e-33" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2536 { 1.234321234321234e-32, "1.23432e-32" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2537 { 1.234321234321234e-31, "1.23432e-31" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2538 { 1.234321234321234e-30, "1.23432e-30" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2539 { 1.234321234321234e-29, "1.23432e-29" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2540 { 1.234321234321234e-28, "1.23432e-28" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2541 { 1.234321234321234e-27, "1.23432e-27" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2542 { 1.234321234321234e-26, "1.23432e-26" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2543 { 1.234321234321234e-25, "1.23432e-25" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2544 { 1.234321234321234e-24, "1.23432e-24" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2545 { 1.234321234321234e-23, "1.23432e-23" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2546 { 1.234321234321234e-22, "1.23432e-22" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2547 { 1.234321234321234e-21, "1.23432e-21" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2548 { 1.234321234321234e-20, "1.23432e-20" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2549 { 1.234321234321234e-19, "1.23432e-19" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2550 { 1.234321234321234e-18, "1.23432e-18" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2551 { 1.234321234321234e-17, "1.23432e-17" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2552 { 1.234321234321234e-16, "1.23432e-16" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2553 { 1.234321234321234e-15, "1.23432e-15" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2554 { 1.234321234321234e-14, "1.23432e-14" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2555 { 1.234321234321234e-13, "1.23432e-13" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2556 { 1.234321234321234e-12, "1.23432e-12" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2557 { 1.234321234321234e-11, "1.23432e-11" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2558 { 1.234321234321234e-10, "1.23432e-10" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2559 { 1.234321234321234e-9, "1.23432e-09" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2560 { 1.234321234321234e-8, "1.23432e-08" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2561 { 1.234321234321234e-7, "1.23432e-07" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2562 { 1.234321234321234e-6, "1.23432e-06" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2563 { 1.234321234321234e-5, "1.23432e-05" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2564 { 1.234321234321234e-4, "0.000123432" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2565 { 1.234321234321234e-3, "0.00123432" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2566 { 1.234321234321234e-2, "0.0123432" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2567 { 1.234321234321234e-1, "0.123432" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2568 { 1.234321234321234, "1.23432" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2569 { 1.234321234321234e1, "12.3432" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2570 { 1.234321234321234e2, "123.432" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2571 { 1.234321234321234e3, "1234.32" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2572 { 1.234321234321234e4, "12343.2" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2573 { 1.234321234321234e5, "123432" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2574 { 1.234321234321234e6, "1.23432e+06" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2575 { 1.234321234321234e7, "1.23432e+07" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2576 { 1.234321234321234e8, "1.23432e+08" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2577 { 1.234321234321234e9, "1.23432e+09" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2578 { 1.234321234321234e10, "1.23432e+10" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2579 { 1.234321234321234e11, "1.23432e+11" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2580 { 1.234321234321234e12, "1.23432e+12" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2581 { 1.234321234321234e13, "1.23432e+13" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2582 { 1.234321234321234e14, "1.23432e+14" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2583 { 1.234321234321234e15, "1.23432e+15" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2584 { 1.234321234321234e16, "1.23432e+16" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2585 { 1.234321234321234e17, "1.23432e+17" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2586 { 1.234321234321234e18, "1.23432e+18" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2587 { 1.234321234321234e19, "1.23432e+19" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2588 { 1.234321234321234e20, "1.23432e+20" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2589 { 1.234321234321234e21, "1.23432e+21" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2590 { 1.234321234321234e22, "1.23432e+22" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2591 { 1.234321234321234e23, "1.23432e+23" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2592 { 1.234321234321234e24, "1.23432e+24" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2593 { 1.234321234321234e25, "1.23432e+25" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2594 { 1.234321234321234e26, "1.23432e+26" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2595 { 1.234321234321234e27, "1.23432e+27" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2596 { 1.234321234321234e28, "1.23432e+28" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2597 { 1.234321234321234e29, "1.23432e+29" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2598 { 1.234321234321234e30, "1.23432e+30" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2599 { 1.234321234321234e31, "1.23432e+31" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2600 { 1.234321234321234e32, "1.23432e+32" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2601 { 1.234321234321234e33, "1.23432e+33" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2602 { 1.234321234321234e34, "1.23432e+34" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2603 { 1.234321234321234e35, "1.23432e+35" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2604 { 1.234321234321234e36, "1.23432e+36" } |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2605 }; |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2606 size_t k; |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2607 for (k = 0; k < SIZEOF (data); k++) |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2608 { |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2609 char *result; |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2610 int retval = |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2611 my_asprintf (&result, "%g", data[k].value); |
8839
5efc1d668039
Accomodate for implementations that produce 3 exponent digits in %e and %g.
Bruno Haible <bruno@clisp.org>
parents:
8836
diff
changeset
|
2612 const char *expected = data[k].string; |
8836
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2613 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
|
2614 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
|
2615 /* 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
|
2616 || (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
|
2617 && 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
|
2618 && 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
|
2619 && 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
|
2620 && 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
|
2621 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
|
2622 == 0)); |
8836
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2623 ASSERT (retval == strlen (result)); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2624 free (result); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2625 } |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2626 } |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2627 |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2628 { /* A negative number. */ |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2629 char *result; |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2630 int retval = |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2631 my_asprintf (&result, "%g %d", -0.03125, 33, 44, 55); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2632 ASSERT (result != NULL); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2633 ASSERT (strcmp (result, "-0.03125 33") == 0); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2634 ASSERT (retval == strlen (result)); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2635 free (result); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2636 } |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2637 |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2638 { /* Positive zero. */ |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2639 char *result; |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2640 int retval = |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2641 my_asprintf (&result, "%g %d", 0.0, 33, 44, 55); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2642 ASSERT (result != NULL); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2643 ASSERT (strcmp (result, "0 33") == 0); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2644 ASSERT (retval == strlen (result)); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2645 free (result); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2646 } |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2647 |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2648 { /* Negative zero. */ |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2649 char *result; |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2650 int retval = |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2651 my_asprintf (&result, "%g %d", -0.0, 33, 44, 55); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2652 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
|
2653 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
|
2654 ASSERT (strcmp (result, "-0 33") == 0); |
8836
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2655 ASSERT (retval == strlen (result)); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2656 free (result); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2657 } |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2658 |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2659 { /* Positive infinity. */ |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2660 char *result; |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2661 int retval = |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2662 my_asprintf (&result, "%g %d", 1.0 / 0.0, 33, 44, 55); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2663 ASSERT (result != NULL); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2664 ASSERT (strcmp (result, "inf 33") == 0 |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2665 || strcmp (result, "infinity 33") == 0); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2666 ASSERT (retval == strlen (result)); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2667 free (result); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2668 } |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2669 |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2670 { /* Negative infinity. */ |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2671 char *result; |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2672 int retval = |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2673 my_asprintf (&result, "%g %d", -1.0 / 0.0, 33, 44, 55); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2674 ASSERT (result != NULL); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2675 ASSERT (strcmp (result, "-inf 33") == 0 |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2676 || strcmp (result, "-infinity 33") == 0); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2677 ASSERT (retval == strlen (result)); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2678 free (result); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2679 } |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2680 |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2681 { /* NaN. */ |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2682 char *result; |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2683 int retval = |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2684 my_asprintf (&result, "%g %d", NaN (), 33, 44, 55); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2685 ASSERT (result != NULL); |
8850
d1fe16dfbfee
Avoid test failures on IRIX 6.5.
Bruno Haible <bruno@clisp.org>
parents:
8839
diff
changeset
|
2686 ASSERT (strlen (result) >= 3 + 3 |
8865
9e203d8ade65
Stricter check for printf result for NaN arguments.
Bruno Haible <bruno@clisp.org>
parents:
8857
diff
changeset
|
2687 && 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
|
2688 && 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
|
2689 ASSERT (retval == strlen (result)); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2690 free (result); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2691 } |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2692 |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2693 { /* Width. */ |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2694 char *result; |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2695 int retval = |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2696 my_asprintf (&result, "%10g %d", 1.75, 33, 44, 55); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2697 ASSERT (result != NULL); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2698 ASSERT (strcmp (result, " 1.75 33") == 0); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2699 ASSERT (retval == strlen (result)); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2700 free (result); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2701 } |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2702 |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2703 { /* FLAG_LEFT. */ |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2704 char *result; |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2705 int retval = |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2706 my_asprintf (&result, "%-10g %d", 1.75, 33, 44, 55); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2707 ASSERT (result != NULL); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2708 ASSERT (strcmp (result, "1.75 33") == 0); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2709 ASSERT (retval == strlen (result)); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2710 free (result); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2711 } |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2712 |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2713 { /* FLAG_SHOWSIGN. */ |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2714 char *result; |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2715 int retval = |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2716 my_asprintf (&result, "%+g %d", 1.75, 33, 44, 55); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2717 ASSERT (result != NULL); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2718 ASSERT (strcmp (result, "+1.75 33") == 0); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2719 ASSERT (retval == strlen (result)); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2720 free (result); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2721 } |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2722 |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2723 { /* FLAG_SPACE. */ |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2724 char *result; |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2725 int retval = |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2726 my_asprintf (&result, "% g %d", 1.75, 33, 44, 55); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2727 ASSERT (result != NULL); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2728 ASSERT (strcmp (result, " 1.75 33") == 0); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2729 ASSERT (retval == strlen (result)); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2730 free (result); |
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 |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2733 { /* FLAG_ALT. */ |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2734 char *result; |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2735 int retval = |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2736 my_asprintf (&result, "%#g %d", 1.75, 33, 44, 55); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2737 ASSERT (result != NULL); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2738 ASSERT (strcmp (result, "1.75000 33") == 0); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2739 ASSERT (retval == strlen (result)); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2740 free (result); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2741 } |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2742 |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2743 { /* FLAG_ALT. */ |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2744 char *result; |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2745 int retval = |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2746 my_asprintf (&result, "%#.g %d", 1.75, 33, 44, 55); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2747 ASSERT (result != NULL); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2748 ASSERT (strcmp (result, "2. 33") == 0); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2749 ASSERT (retval == 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 { /* FLAG_ALT. */ |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2754 char *result; |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2755 int retval = |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2756 my_asprintf (&result, "%#.g %d", 9.75, 33, 44, 55); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2757 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
|
2758 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
|
2759 || 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
|
2760 ASSERT (retval == 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 { /* FLAG_ZERO with finite number. */ |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2765 char *result; |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2766 int retval = |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2767 my_asprintf (&result, "%010g %d", 1234.0, 33, 44, 55); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
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, "0000001234 33") == 0); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2770 ASSERT (retval == 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 { /* FLAG_ZERO with infinite number. */ |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2775 char *result; |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2776 int retval = |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2777 my_asprintf (&result, "%015g %d", -1.0 / 0.0, 33, 44, 55); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2778 ASSERT (result != NULL); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2779 ASSERT (strcmp (result, " -inf 33") == 0 |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2780 || strcmp (result, " -infinity 33") == 0); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2781 ASSERT (retval == 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 { /* FLAG_ZERO with NaN. */ |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2786 char *result; |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2787 int retval = |
8870
4e1f2ea486b4
Allow for a longer printed representation of NaN.
Bruno Haible <bruno@clisp.org>
parents:
8865
diff
changeset
|
2788 my_asprintf (&result, "%050g %d", NaN (), 33, 44, 55); |
8836
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2789 ASSERT (result != NULL); |
8870
4e1f2ea486b4
Allow for a longer printed representation of NaN.
Bruno Haible <bruno@clisp.org>
parents:
8865
diff
changeset
|
2790 ASSERT (strlen (result) == 50 + 3 |
8865
9e203d8ade65
Stricter check for printf result for NaN arguments.
Bruno Haible <bruno@clisp.org>
parents:
8857
diff
changeset
|
2791 && 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
|
2792 && 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
|
2793 ASSERT (retval == strlen (result)); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2794 free (result); |
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 |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2797 { /* Precision. */ |
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 int retval = |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2800 my_asprintf (&result, "%.g %d", 1234.0, 33, 44, 55); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2801 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
|
2802 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
|
2803 || strcmp (result, "1e+003 33") == 0); |
8836
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2804 ASSERT (retval == strlen (result)); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2805 free (result); |
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 |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2808 { /* A positive number. */ |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2809 char *result; |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2810 int retval = |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2811 my_asprintf (&result, "%Lg %d", 12.75L, 33, 44, 55); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2812 ASSERT (result != NULL); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2813 ASSERT (strcmp (result, "12.75 33") == 0); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2814 ASSERT (retval == strlen (result)); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2815 free (result); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2816 } |
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 { /* A larger positive number. */ |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2819 char *result; |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2820 int retval = |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2821 my_asprintf (&result, "%Lg %d", 1234567.0L, 33, 44, 55); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2822 ASSERT (result != NULL); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2823 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
|
2824 ASSERT (retval == strlen (result)); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2825 free (result); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2826 } |
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 { /* Small and large positive numbers. */ |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2829 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
|
2830 { |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2831 { 1.234321234321234e-37L, "1.23432e-37" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2832 { 1.234321234321234e-36L, "1.23432e-36" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2833 { 1.234321234321234e-35L, "1.23432e-35" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2834 { 1.234321234321234e-34L, "1.23432e-34" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2835 { 1.234321234321234e-33L, "1.23432e-33" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2836 { 1.234321234321234e-32L, "1.23432e-32" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2837 { 1.234321234321234e-31L, "1.23432e-31" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2838 { 1.234321234321234e-30L, "1.23432e-30" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2839 { 1.234321234321234e-29L, "1.23432e-29" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2840 { 1.234321234321234e-28L, "1.23432e-28" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2841 { 1.234321234321234e-27L, "1.23432e-27" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2842 { 1.234321234321234e-26L, "1.23432e-26" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2843 { 1.234321234321234e-25L, "1.23432e-25" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2844 { 1.234321234321234e-24L, "1.23432e-24" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2845 { 1.234321234321234e-23L, "1.23432e-23" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2846 { 1.234321234321234e-22L, "1.23432e-22" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2847 { 1.234321234321234e-21L, "1.23432e-21" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2848 { 1.234321234321234e-20L, "1.23432e-20" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2849 { 1.234321234321234e-19L, "1.23432e-19" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2850 { 1.234321234321234e-18L, "1.23432e-18" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2851 { 1.234321234321234e-17L, "1.23432e-17" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2852 { 1.234321234321234e-16L, "1.23432e-16" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2853 { 1.234321234321234e-15L, "1.23432e-15" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2854 { 1.234321234321234e-14L, "1.23432e-14" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2855 { 1.234321234321234e-13L, "1.23432e-13" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2856 { 1.234321234321234e-12L, "1.23432e-12" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2857 { 1.234321234321234e-11L, "1.23432e-11" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2858 { 1.234321234321234e-10L, "1.23432e-10" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2859 { 1.234321234321234e-9L, "1.23432e-09" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2860 { 1.234321234321234e-8L, "1.23432e-08" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2861 { 1.234321234321234e-7L, "1.23432e-07" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2862 { 1.234321234321234e-6L, "1.23432e-06" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2863 { 1.234321234321234e-5L, "1.23432e-05" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2864 { 1.234321234321234e-4L, "0.000123432" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2865 { 1.234321234321234e-3L, "0.00123432" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2866 { 1.234321234321234e-2L, "0.0123432" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2867 { 1.234321234321234e-1L, "0.123432" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2868 { 1.234321234321234L, "1.23432" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2869 { 1.234321234321234e1L, "12.3432" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2870 { 1.234321234321234e2L, "123.432" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2871 { 1.234321234321234e3L, "1234.32" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2872 { 1.234321234321234e4L, "12343.2" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2873 { 1.234321234321234e5L, "123432" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2874 { 1.234321234321234e6L, "1.23432e+06" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2875 { 1.234321234321234e7L, "1.23432e+07" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2876 { 1.234321234321234e8L, "1.23432e+08" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2877 { 1.234321234321234e9L, "1.23432e+09" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2878 { 1.234321234321234e10L, "1.23432e+10" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2879 { 1.234321234321234e11L, "1.23432e+11" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2880 { 1.234321234321234e12L, "1.23432e+12" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2881 { 1.234321234321234e13L, "1.23432e+13" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2882 { 1.234321234321234e14L, "1.23432e+14" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2883 { 1.234321234321234e15L, "1.23432e+15" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2884 { 1.234321234321234e16L, "1.23432e+16" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2885 { 1.234321234321234e17L, "1.23432e+17" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2886 { 1.234321234321234e18L, "1.23432e+18" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2887 { 1.234321234321234e19L, "1.23432e+19" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2888 { 1.234321234321234e20L, "1.23432e+20" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2889 { 1.234321234321234e21L, "1.23432e+21" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2890 { 1.234321234321234e22L, "1.23432e+22" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2891 { 1.234321234321234e23L, "1.23432e+23" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2892 { 1.234321234321234e24L, "1.23432e+24" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2893 { 1.234321234321234e25L, "1.23432e+25" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2894 { 1.234321234321234e26L, "1.23432e+26" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2895 { 1.234321234321234e27L, "1.23432e+27" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2896 { 1.234321234321234e28L, "1.23432e+28" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2897 { 1.234321234321234e29L, "1.23432e+29" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2898 { 1.234321234321234e30L, "1.23432e+30" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2899 { 1.234321234321234e31L, "1.23432e+31" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2900 { 1.234321234321234e32L, "1.23432e+32" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2901 { 1.234321234321234e33L, "1.23432e+33" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2902 { 1.234321234321234e34L, "1.23432e+34" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2903 { 1.234321234321234e35L, "1.23432e+35" }, |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2904 { 1.234321234321234e36L, "1.23432e+36" } |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2905 }; |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2906 size_t k; |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2907 for (k = 0; k < SIZEOF (data); k++) |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2908 { |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2909 char *result; |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2910 int retval = |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2911 my_asprintf (&result, "%Lg", data[k].value); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2912 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
|
2913 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
|
2914 ASSERT (retval == strlen (result)); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2915 free (result); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2916 } |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2917 } |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2918 |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2919 { /* A negative number. */ |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2920 char *result; |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2921 int retval = |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2922 my_asprintf (&result, "%Lg %d", -0.03125L, 33, 44, 55); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2923 ASSERT (result != NULL); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2924 ASSERT (strcmp (result, "-0.03125 33") == 0); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2925 ASSERT (retval == strlen (result)); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2926 free (result); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2927 } |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2928 |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2929 { /* Positive zero. */ |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2930 char *result; |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2931 int retval = |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2932 my_asprintf (&result, "%Lg %d", 0.0L, 33, 44, 55); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2933 ASSERT (result != NULL); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2934 ASSERT (strcmp (result, "0 33") == 0); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2935 ASSERT (retval == strlen (result)); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2936 free (result); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2937 } |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2938 |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2939 { /* Negative zero. */ |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2940 char *result; |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2941 int retval = |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2942 my_asprintf (&result, "%Lg %d", -0.0L, 33, 44, 55); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2943 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
|
2944 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
|
2945 ASSERT (strcmp (result, "-0 33") == 0); |
8836
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2946 ASSERT (retval == strlen (result)); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2947 free (result); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2948 } |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2949 |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2950 { /* Positive infinity. */ |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2951 char *result; |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2952 int retval = |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2953 my_asprintf (&result, "%Lg %d", 1.0L / 0.0L, 33, 44, 55); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2954 ASSERT (result != NULL); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2955 ASSERT (strcmp (result, "inf 33") == 0 |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2956 || strcmp (result, "infinity 33") == 0); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2957 ASSERT (retval == strlen (result)); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2958 free (result); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2959 } |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2960 |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2961 { /* Negative infinity. */ |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2962 char *result; |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2963 int retval = |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2964 my_asprintf (&result, "%Lg %d", -1.0L / 0.0L, 33, 44, 55); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2965 ASSERT (result != NULL); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2966 ASSERT (strcmp (result, "-inf 33") == 0 |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2967 || strcmp (result, "-infinity 33") == 0); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2968 ASSERT (retval == strlen (result)); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2969 free (result); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2970 } |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2971 |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2972 { /* NaN. */ |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2973 static long double zero = 0.0L; |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2974 char *result; |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2975 int retval = |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2976 my_asprintf (&result, "%Lg %d", zero / zero, 33, 44, 55); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2977 ASSERT (result != NULL); |
8850
d1fe16dfbfee
Avoid test failures on IRIX 6.5.
Bruno Haible <bruno@clisp.org>
parents:
8839
diff
changeset
|
2978 ASSERT (strlen (result) >= 3 + 3 |
8865
9e203d8ade65
Stricter check for printf result for NaN arguments.
Bruno Haible <bruno@clisp.org>
parents:
8857
diff
changeset
|
2979 && 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
|
2980 && 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
|
2981 ASSERT (retval == strlen (result)); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2982 free (result); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
2983 } |
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
|
2984 #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
|
2985 { /* 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
|
2986 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
|
2987 { 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
|
2988 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
|
2989 int retval = |
42e2847583f9
Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
2990 my_asprintf (&result, "%Lg %d", x.value, 33, 44, 55); |
42e2847583f9
Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
2991 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
|
2992 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
|
2993 && 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
|
2994 && 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
|
2995 ASSERT (retval == strlen (result)); |
42e2847583f9
Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
2996 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
|
2997 } |
42e2847583f9
Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
2998 { |
42e2847583f9
Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
2999 /* 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
|
3000 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
|
3001 { 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
|
3002 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
|
3003 int retval = |
42e2847583f9
Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
3004 my_asprintf (&result, "%Lg %d", x.value, 33, 44, 55); |
42e2847583f9
Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
3005 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
|
3006 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
|
3007 && 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
|
3008 && 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
|
3009 ASSERT (retval == strlen (result)); |
42e2847583f9
Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
3010 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
|
3011 } |
42e2847583f9
Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
3012 /* 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
|
3013 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
|
3014 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
|
3015 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
|
3016 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
|
3017 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
|
3018 */ |
42e2847583f9
Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
3019 { /* 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
|
3020 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
|
3021 { 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
|
3022 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
|
3023 int retval = |
42e2847583f9
Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
3024 my_asprintf (&result, "%Lg %d", x.value, 33, 44, 55); |
42e2847583f9
Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
3025 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
|
3026 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
|
3027 && 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
|
3028 && 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
|
3029 ASSERT (retval == strlen (result)); |
42e2847583f9
Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
3030 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
|
3031 } |
42e2847583f9
Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
3032 { /* 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
|
3033 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
|
3034 { 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
|
3035 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
|
3036 int retval = |
42e2847583f9
Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
3037 my_asprintf (&result, "%Lg %d", x.value, 33, 44, 55); |
42e2847583f9
Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
3038 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
|
3039 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
|
3040 && 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
|
3041 && 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
|
3042 ASSERT (retval == strlen (result)); |
42e2847583f9
Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
3043 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
|
3044 } |
42e2847583f9
Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
3045 { /* 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
|
3046 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
|
3047 { 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
|
3048 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
|
3049 int retval = |
42e2847583f9
Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
3050 my_asprintf (&result, "%Lg %d", x.value, 33, 44, 55); |
42e2847583f9
Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
3051 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
|
3052 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
|
3053 && 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
|
3054 && 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
|
3055 ASSERT (retval == strlen (result)); |
42e2847583f9
Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
3056 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
|
3057 } |
42e2847583f9
Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
3058 { /* 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
|
3059 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
|
3060 { 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
|
3061 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
|
3062 int retval = |
42e2847583f9
Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
3063 my_asprintf (&result, "%Lg %d", x.value, 33, 44, 55); |
42e2847583f9
Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
3064 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
|
3065 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
|
3066 && 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
|
3067 && 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
|
3068 ASSERT (retval == strlen (result)); |
42e2847583f9
Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
3069 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
|
3070 } |
42e2847583f9
Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
3071 { /* 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
|
3072 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
|
3073 { 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
|
3074 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
|
3075 int retval = |
42e2847583f9
Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
3076 my_asprintf (&result, "%Lg %d", x.value, 33, 44, 55); |
42e2847583f9
Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
3077 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
|
3078 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
|
3079 && 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
|
3080 && 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
|
3081 ASSERT (retval == strlen (result)); |
42e2847583f9
Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
3082 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
|
3083 } |
42e2847583f9
Fix *printf so that it recognizes non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
3084 #endif |
8836
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
3085 |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
3086 { /* Width. */ |
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 int retval = |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
3089 my_asprintf (&result, "%10Lg %d", 1.75L, 33, 44, 55); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
3090 ASSERT (result != NULL); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
3091 ASSERT (strcmp (result, " 1.75 33") == 0); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
3092 ASSERT (retval == 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 { /* FLAG_LEFT. */ |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
3097 char *result; |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
3098 int retval = |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
3099 my_asprintf (&result, "%-10Lg %d", 1.75L, 33, 44, 55); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
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, "1.75 33") == 0); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
3102 ASSERT (retval == strlen (result)); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
3103 free (result); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
3104 } |
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 { /* FLAG_SHOWSIGN. */ |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
3107 char *result; |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
3108 int retval = |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
3109 my_asprintf (&result, "%+Lg %d", 1.75L, 33, 44, 55); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
3110 ASSERT (result != NULL); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
3111 ASSERT (strcmp (result, "+1.75 33") == 0); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
3112 ASSERT (retval == strlen (result)); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
3113 free (result); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
3114 } |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
3115 |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
3116 { /* FLAG_SPACE. */ |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
3117 char *result; |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
3118 int retval = |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
3119 my_asprintf (&result, "% Lg %d", 1.75L, 33, 44, 55); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
3120 ASSERT (result != NULL); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
3121 ASSERT (strcmp (result, " 1.75 33") == 0); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
3122 ASSERT (retval == strlen (result)); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
3123 free (result); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
3124 } |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
3125 |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
3126 { /* FLAG_ALT. */ |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
3127 char *result; |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
3128 int retval = |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
3129 my_asprintf (&result, "%#Lg %d", 1.75L, 33, 44, 55); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
3130 ASSERT (result != NULL); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
3131 ASSERT (strcmp (result, "1.75000 33") == 0); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
3132 ASSERT (retval == strlen (result)); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
3133 free (result); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
3134 } |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
3135 |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
3136 { /* FLAG_ALT. */ |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
3137 char *result; |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
3138 int retval = |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
3139 my_asprintf (&result, "%#.Lg %d", 1.75L, 33, 44, 55); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
3140 ASSERT (result != NULL); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
3141 ASSERT (strcmp (result, "2. 33") == 0); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
3142 ASSERT (retval == strlen (result)); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
3143 free (result); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
3144 } |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
3145 |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
3146 { /* FLAG_ALT. */ |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
3147 char *result; |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
3148 int retval = |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
3149 my_asprintf (&result, "%#.Lg %d", 9.75L, 33, 44, 55); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
3150 ASSERT (result != NULL); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
3151 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
|
3152 ASSERT (retval == strlen (result)); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
3153 free (result); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
3154 } |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
3155 |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
3156 { /* FLAG_ZERO with finite number. */ |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
3157 char *result; |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
3158 int retval = |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
3159 my_asprintf (&result, "%010Lg %d", 1234.0L, 33, 44, 55); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
3160 ASSERT (result != NULL); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
3161 ASSERT (strcmp (result, "0000001234 33") == 0); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
3162 ASSERT (retval == strlen (result)); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
3163 free (result); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
3164 } |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
3165 |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
3166 { /* FLAG_ZERO with infinite number. */ |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
3167 char *result; |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
3168 int retval = |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
3169 my_asprintf (&result, "%015Lg %d", -1.0L / 0.0L, 33, 44, 55); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
3170 ASSERT (result != NULL); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
3171 ASSERT (strcmp (result, " -inf 33") == 0 |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
3172 || strcmp (result, " -infinity 33") == 0); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
3173 ASSERT (retval == strlen (result)); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
3174 free (result); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
3175 } |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
3176 |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
3177 { /* FLAG_ZERO with NaN. */ |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
3178 static long double zero = 0.0L; |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
3179 char *result; |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
3180 int retval = |
8870
4e1f2ea486b4
Allow for a longer printed representation of NaN.
Bruno Haible <bruno@clisp.org>
parents:
8865
diff
changeset
|
3181 my_asprintf (&result, "%050Lg %d", zero / zero, 33, 44, 55); |
8836
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
3182 ASSERT (result != NULL); |
8870
4e1f2ea486b4
Allow for a longer printed representation of NaN.
Bruno Haible <bruno@clisp.org>
parents:
8865
diff
changeset
|
3183 ASSERT (strlen (result) == 50 + 3 |
8865
9e203d8ade65
Stricter check for printf result for NaN arguments.
Bruno Haible <bruno@clisp.org>
parents:
8857
diff
changeset
|
3184 && 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
|
3185 && 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
|
3186 ASSERT (retval == strlen (result)); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
3187 free (result); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
3188 } |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
3189 |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
3190 { /* Precision. */ |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
3191 char *result; |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
3192 int retval = |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
3193 my_asprintf (&result, "%.Lg %d", 1234.0L, 33, 44, 55); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
3194 ASSERT (result != NULL); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
3195 ASSERT (strcmp (result, "1e+03 33") == 0); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
3196 ASSERT (retval == strlen (result)); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
3197 free (result); |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
3198 } |
07084ab003b8
Add tests for %e and %g directives.
Bruno Haible <bruno@clisp.org>
parents:
8834
diff
changeset
|
3199 |
8342
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
3200 /* Test the support of the %n format directive. */ |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
3201 |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
3202 { |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
3203 int count = -1; |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
3204 char *result; |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
3205 int retval = |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
3206 my_asprintf (&result, "%d %n", 123, &count, 33, 44, 55); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
3207 ASSERT (result != NULL); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
3208 ASSERT (strcmp (result, "123 ") == 0); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
3209 ASSERT (retval == strlen (result)); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
3210 ASSERT (count == 4); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
3211 free (result); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
3212 } |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
3213 |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
3214 /* Test the support of the POSIX/XSI format strings with positions. */ |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
3215 |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
3216 { |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
3217 char *result; |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
3218 int retval = |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
3219 my_asprintf (&result, "%2$d %1$d", 33, 55); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
3220 ASSERT (result != NULL); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
3221 ASSERT (strcmp (result, "55 33") == 0); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
3222 ASSERT (retval == strlen (result)); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
3223 free (result); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
3224 } |
8803
6c1d98929550
Work around lack of support of grouping flag.
Bruno Haible <bruno@clisp.org>
parents:
8754
diff
changeset
|
3225 |
6c1d98929550
Work around lack of support of grouping flag.
Bruno Haible <bruno@clisp.org>
parents:
8754
diff
changeset
|
3226 /* 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
|
3227 |
6c1d98929550
Work around lack of support of grouping flag.
Bruno Haible <bruno@clisp.org>
parents:
8754
diff
changeset
|
3228 { |
6c1d98929550
Work around lack of support of grouping flag.
Bruno Haible <bruno@clisp.org>
parents:
8754
diff
changeset
|
3229 char *result; |
6c1d98929550
Work around lack of support of grouping flag.
Bruno Haible <bruno@clisp.org>
parents:
8754
diff
changeset
|
3230 int retval = |
6c1d98929550
Work around lack of support of grouping flag.
Bruno Haible <bruno@clisp.org>
parents:
8754
diff
changeset
|
3231 my_asprintf (&result, "%'d %d", 1234567, 99); |
6c1d98929550
Work around lack of support of grouping flag.
Bruno Haible <bruno@clisp.org>
parents:
8754
diff
changeset
|
3232 ASSERT (result != NULL); |
6c1d98929550
Work around lack of support of grouping flag.
Bruno Haible <bruno@clisp.org>
parents:
8754
diff
changeset
|
3233 ASSERT (result[strlen (result) - 1] == '9'); |
6c1d98929550
Work around lack of support of grouping flag.
Bruno Haible <bruno@clisp.org>
parents:
8754
diff
changeset
|
3234 ASSERT (retval == strlen (result)); |
6c1d98929550
Work around lack of support of grouping flag.
Bruno Haible <bruno@clisp.org>
parents:
8754
diff
changeset
|
3235 free (result); |
6c1d98929550
Work around lack of support of grouping flag.
Bruno Haible <bruno@clisp.org>
parents:
8754
diff
changeset
|
3236 } |
8342
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
3237 } |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
3238 |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
3239 static int |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
3240 my_asprintf (char **result, const char *format, ...) |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
3241 { |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
3242 va_list args; |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
3243 int ret; |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
3244 |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
3245 va_start (args, format); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
3246 ret = vasprintf (result, format, args); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
3247 va_end (args); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
3248 return ret; |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
3249 } |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
3250 |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
3251 static void |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
3252 test_vasprintf () |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
3253 { |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
3254 test_function (my_asprintf); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
3255 } |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
3256 |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
3257 static void |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
3258 test_asprintf () |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
3259 { |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
3260 test_function (asprintf); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
3261 } |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
3262 |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
3263 int |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
3264 main (int argc, char *argv[]) |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
3265 { |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
3266 test_vasprintf (); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
3267 test_asprintf (); |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
3268 return 0; |
504f056f113a
Tests for module 'vasprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
3269 } |