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