annotate tests/test-strtod.c @ 9848:3dbacd929304

Convert from C99 syntax to C89 syntax.
author Bruno Haible <bruno@clisp.org>
date Tue, 01 Apr 2008 00:26:18 +0200
parents bb111aa32127
children ab48b8591214
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
9821
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
1 /*
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
2 * Copyright (C) 2008 Free Software Foundation
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
3 * Written by Eric Blake
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
4 *
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
5 * This program is free software: you can redistribute it and/or modify
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
6 * it under the terms of the GNU General Public License as published by
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
7 * the Free Software Foundation; either version 3 of the License, or
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
8 * (at your option) any later version.
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
9 *
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
10 * This program is distributed in the hope that it will be useful,
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
13 * GNU General Public License for more details.
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
14 *
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
16 * along with this program. If not, see <http://www.gnu.org/licenses/>. */
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
17
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
18 #include <config.h>
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
19
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
20 #include <stdlib.h>
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
21
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
22 #include <errno.h>
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
23 #include <float.h>
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
24 #include <math.h>
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
25 #include <stdio.h>
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
26 #include <string.h>
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
27
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
28 #define ASSERT(expr) \
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
29 do \
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
30 { \
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
31 if (!(expr)) \
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
32 { \
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
33 fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
34 /* FIXME abort ();*/status = 1; \
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
35 } \
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
36 } \
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
37 while (0)
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
38
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
39 int
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
40 main ()
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
41 {
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
42 int status = 0;
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
43 /* Subject sequence empty or invalid. */
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
44 {
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
45 const char input[] = "";
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
46 char *ptr;
9848
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
47 double result;
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
48 errno = 0;
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
49 result = strtod (input, &ptr);
9821
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
50 ASSERT (result == 0.0);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
51 ASSERT (!signbit (result));
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
52 ASSERT (ptr == input);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
53 ASSERT (errno == 0 || errno == EINVAL);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
54 }
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
55 {
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
56 const char input[] = " ";
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
57 char *ptr;
9848
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
58 double result;
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
59 errno = 0;
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
60 result = strtod (input, &ptr);
9821
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
61 ASSERT (result == 0.0);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
62 ASSERT (!signbit (result));
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
63 ASSERT (ptr == input);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
64 ASSERT (errno == 0 || errno == EINVAL);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
65 }
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
66 {
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
67 const char input[] = " +";
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
68 char *ptr;
9848
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
69 double result;
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
70 errno = 0;
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
71 result = strtod (input, &ptr);
9821
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
72 ASSERT (result == 0.0);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
73 ASSERT (!signbit (result));
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
74 ASSERT (ptr == input);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
75 ASSERT (errno == 0 || errno == EINVAL);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
76 }
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
77 {
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
78 const char input[] = " .";
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
79 char *ptr;
9848
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
80 double result;
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
81 errno = 0;
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
82 result = strtod (input, &ptr);
9821
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
83 ASSERT (result == 0.0);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
84 ASSERT (!signbit (result));
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
85 ASSERT (ptr == input);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
86 ASSERT (errno == 0 || errno == EINVAL);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
87 }
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
88 {
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
89 const char input[] = " .e0";
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
90 char *ptr;
9848
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
91 double result;
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
92 errno = 0;
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
93 result = strtod (input, &ptr);
9821
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
94 ASSERT (result == 0.0);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
95 ASSERT (!signbit (result));
9841
a95dd6984607 Add info about many more platforms.
Bruno Haible <bruno@clisp.org>
parents: 9839
diff changeset
96 ASSERT (ptr == input); /* IRIX 6.5, OSF/1 5.1 */
9821
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
97 ASSERT (errno == 0 || errno == EINVAL);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
98 }
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
99 {
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
100 const char input[] = " +.e-0";
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
101 char *ptr;
9848
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
102 double result;
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
103 errno = 0;
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
104 result = strtod (input, &ptr);
9821
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
105 ASSERT (result == 0.0);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
106 ASSERT (!signbit (result));
9841
a95dd6984607 Add info about many more platforms.
Bruno Haible <bruno@clisp.org>
parents: 9839
diff changeset
107 ASSERT (ptr == input); /* IRIX 6.5, OSF/1 5.1 */
9821
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
108 ASSERT (errno == 0 || errno == EINVAL);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
109 }
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
110 {
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
111 const char input[] = " in";
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
112 char *ptr;
9848
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
113 double result;
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
114 errno = 0;
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
115 result = strtod (input, &ptr);
9821
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
116 ASSERT (result == 0.0);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
117 ASSERT (!signbit (result));
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
118 ASSERT (ptr == input);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
119 ASSERT (errno == 0 || errno == EINVAL);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
120 }
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
121 {
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
122 const char input[] = " na";
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
123 char *ptr;
9848
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
124 double result;
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
125 errno = 0;
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
126 result = strtod (input, &ptr);
9821
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
127 ASSERT (result == 0.0);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
128 ASSERT (!signbit (result));
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
129 ASSERT (ptr == input);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
130 ASSERT (errno == 0 || errno == EINVAL);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
131 }
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
132
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
133 /* Simple floating point values. */
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
134 {
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
135 const char input[] = "1";
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
136 char *ptr;
9848
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
137 double result;
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
138 errno = 0;
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
139 result = strtod (input, &ptr);
9821
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
140 ASSERT (result == 1.0);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
141 ASSERT (ptr == input + 1);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
142 ASSERT (errno == 0);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
143 }
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
144 {
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
145 const char input[] = "1.";
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
146 char *ptr;
9848
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
147 double result;
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
148 errno = 0;
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
149 result = strtod (input, &ptr);
9821
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
150 ASSERT (result == 1.0);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
151 ASSERT (ptr == input + 2);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
152 ASSERT (errno == 0);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
153 }
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
154 {
9837
8c80e0046993 More strtod touchups.
Eric Blake <ebb9@byu.net>
parents: 9822
diff changeset
155 const char input[] = ".5";
9821
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
156 char *ptr;
9848
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
157 double result;
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
158 errno = 0;
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
159 result = strtod (input, &ptr);
9837
8c80e0046993 More strtod touchups.
Eric Blake <ebb9@byu.net>
parents: 9822
diff changeset
160 ASSERT (result == 0.5);
9821
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
161 ASSERT (ptr == input + 2);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
162 ASSERT (errno == 0);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
163 }
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
164 {
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
165 const char input[] = " 1";
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
166 char *ptr;
9848
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
167 double result;
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
168 errno = 0;
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
169 result = strtod (input, &ptr);
9821
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
170 ASSERT (result == 1.0);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
171 ASSERT (ptr == input + 2);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
172 ASSERT (errno == 0);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
173 }
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
174 {
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
175 const char input[] = "+1";
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
176 char *ptr;
9848
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
177 double result;
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
178 errno = 0;
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
179 result = strtod (input, &ptr);
9821
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
180 ASSERT (result == 1.0);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
181 ASSERT (ptr == input + 2);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
182 ASSERT (errno == 0);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
183 }
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
184 {
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
185 const char input[] = "-1";
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
186 char *ptr;
9848
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
187 double result;
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
188 errno = 0;
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
189 result = strtod (input, &ptr);
9821
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
190 ASSERT (result == -1.0);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
191 ASSERT (ptr == input + 2);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
192 ASSERT (errno == 0);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
193 }
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
194 {
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
195 const char input[] = "1e0";
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
196 char *ptr;
9848
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
197 double result;
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
198 errno = 0;
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
199 result = strtod (input, &ptr);
9821
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
200 ASSERT (result == 1.0);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
201 ASSERT (ptr == input + 3);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
202 ASSERT (errno == 0);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
203 }
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
204 {
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
205 const char input[] = "1e+0";
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
206 char *ptr;
9848
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
207 double result;
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
208 errno = 0;
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
209 result = strtod (input, &ptr);
9821
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
210 ASSERT (result == 1.0);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
211 ASSERT (ptr == input + 4);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
212 ASSERT (errno == 0);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
213 }
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
214 {
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
215 const char input[] = "1e-0";
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
216 char *ptr;
9848
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
217 double result;
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
218 errno = 0;
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
219 result = strtod (input, &ptr);
9821
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
220 ASSERT (result == 1.0);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
221 ASSERT (ptr == input + 4);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
222 ASSERT (errno == 0);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
223 }
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
224 {
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
225 const char input[] = "1e1";
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
226 char *ptr;
9848
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
227 double result;
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
228 errno = 0;
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
229 result = strtod (input, &ptr);
9821
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
230 ASSERT (result == 10.0);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
231 ASSERT (ptr == input + 3);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
232 ASSERT (errno == 0);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
233 }
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
234 {
9837
8c80e0046993 More strtod touchups.
Eric Blake <ebb9@byu.net>
parents: 9822
diff changeset
235 const char input[] = "5e-1";
9821
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
236 char *ptr;
9848
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
237 double result;
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
238 errno = 0;
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
239 result = strtod (input, &ptr);
9837
8c80e0046993 More strtod touchups.
Eric Blake <ebb9@byu.net>
parents: 9822
diff changeset
240 ASSERT (result == 0.5);
9821
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
241 ASSERT (ptr == input + 4);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
242 ASSERT (errno == 0);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
243 }
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
244
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
245 /* Zero. */
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
246 {
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
247 const char input[] = "0";
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
248 char *ptr;
9848
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
249 double result;
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
250 errno = 0;
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
251 result = strtod (input, &ptr);
9821
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
252 ASSERT (result == 0.0);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
253 ASSERT (!signbit (result));
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
254 ASSERT (ptr == input + 1);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
255 ASSERT (errno == 0);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
256 }
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
257 {
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
258 const char input[] = ".0";
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
259 char *ptr;
9848
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
260 double result;
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
261 errno = 0;
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
262 result = strtod (input, &ptr);
9821
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
263 ASSERT (result == 0.0);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
264 ASSERT (!signbit (result));
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
265 ASSERT (ptr == input + 2);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
266 ASSERT (errno == 0);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
267 }
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
268 {
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
269 const char input[] = "0e0";
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
270 char *ptr;
9848
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
271 double result;
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
272 errno = 0;
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
273 result = strtod (input, &ptr);
9821
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
274 ASSERT (result == 0.0);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
275 ASSERT (!signbit (result));
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
276 ASSERT (ptr == input + 3);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
277 ASSERT (errno == 0);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
278 }
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
279 {
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
280 const char input[] = "0e+9999999";
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
281 char *ptr;
9848
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
282 double result;
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
283 errno = 0;
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
284 result = strtod (input, &ptr);
9821
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
285 ASSERT (result == 0.0);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
286 ASSERT (!signbit (result));
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
287 ASSERT (ptr == input + 10);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
288 ASSERT (errno == 0);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
289 }
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
290 {
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
291 const char input[] = "0e-9999999";
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
292 char *ptr;
9848
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
293 double result;
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
294 errno = 0;
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
295 result = strtod (input, &ptr);
9821
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
296 ASSERT (result == 0.0);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
297 ASSERT (!signbit (result));
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
298 ASSERT (ptr == input + 10);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
299 ASSERT (errno == 0);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
300 }
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
301 {
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
302 const char input[] = "-0";
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
303 char *ptr;
9848
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
304 double result;
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
305 errno = 0;
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
306 result = strtod (input, &ptr);
9821
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
307 ASSERT (result == 0.0);
9846
25b01b718f02 Don't compare actual signbit return values.
Jim Meyering <meyering@redhat.com>
parents: 9841
diff changeset
308 ASSERT (!!signbit (result) == !!signbit (-0.0)); /* IRIX 6.5 */
9821
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
309 ASSERT (ptr == input + 2);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
310 ASSERT (errno == 0);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
311 }
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
312
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
313 /* Suffixes. */
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
314 {
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
315 const char input[] = "1f";
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
316 char *ptr;
9848
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
317 double result;
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
318 errno = 0;
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
319 result = strtod (input, &ptr);
9821
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
320 ASSERT (result == 1.0);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
321 ASSERT (ptr == input + 1);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
322 ASSERT (errno == 0);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
323 }
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
324 {
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
325 const char input[] = "1.f";
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
326 char *ptr;
9848
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
327 double result;
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
328 errno = 0;
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
329 result = strtod (input, &ptr);
9821
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
330 ASSERT (result == 1.0);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
331 ASSERT (ptr == input + 2);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
332 ASSERT (errno == 0);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
333 }
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
334 {
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
335 const char input[] = "1e";
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
336 char *ptr;
9848
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
337 double result;
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
338 errno = 0;
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
339 result = strtod (input, &ptr);
9821
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
340 ASSERT (result == 1.0);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
341 ASSERT (ptr == input + 1);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
342 ASSERT (errno == 0);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
343 }
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
344 {
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
345 const char input[] = "1e+";
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
346 char *ptr;
9848
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
347 double result;
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
348 errno = 0;
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
349 result = strtod (input, &ptr);
9821
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
350 ASSERT (result == 1.0);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
351 ASSERT (ptr == input + 1);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
352 ASSERT (errno == 0);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
353 }
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
354 {
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
355 const char input[] = "1e-";
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
356 char *ptr;
9848
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
357 double result;
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
358 errno = 0;
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
359 result = strtod (input, &ptr);
9821
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
360 ASSERT (result == 1.0);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
361 ASSERT (ptr == input + 1);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
362 ASSERT (errno == 0);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
363 }
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
364 {
9822
fb687649f177 Add hex float support.
Eric Blake <ebb9@byu.net>
parents: 9821
diff changeset
365 const char input[] = "1E 2";
fb687649f177 Add hex float support.
Eric Blake <ebb9@byu.net>
parents: 9821
diff changeset
366 char *ptr;
9848
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
367 double result;
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
368 errno = 0;
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
369 result = strtod (input, &ptr);
9841
a95dd6984607 Add info about many more platforms.
Bruno Haible <bruno@clisp.org>
parents: 9839
diff changeset
370 ASSERT (result == 1.0); /* HP-UX 11.11, IRIX 6.5, OSF/1 4.0 */
a95dd6984607 Add info about many more platforms.
Bruno Haible <bruno@clisp.org>
parents: 9839
diff changeset
371 ASSERT (ptr == input + 1); /* HP-UX 11.11, IRIX 6.5 */
9822
fb687649f177 Add hex float support.
Eric Blake <ebb9@byu.net>
parents: 9821
diff changeset
372 ASSERT (errno == 0);
fb687649f177 Add hex float support.
Eric Blake <ebb9@byu.net>
parents: 9821
diff changeset
373 }
fb687649f177 Add hex float support.
Eric Blake <ebb9@byu.net>
parents: 9821
diff changeset
374 {
9821
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
375 const char input[] = "0x";
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
376 char *ptr;
9848
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
377 double result;
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
378 errno = 0;
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
379 result = strtod (input, &ptr);
9821
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
380 ASSERT (result == 0.0);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
381 ASSERT (!signbit (result));
9841
a95dd6984607 Add info about many more platforms.
Bruno Haible <bruno@clisp.org>
parents: 9839
diff changeset
382 ASSERT (ptr == input + 1); /* glibc-2.3.6, MacOS X 10.3, FreeBSD 6.2 */
9821
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
383 ASSERT (errno == 0);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
384 }
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
385 {
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
386 const char input[] = "00x1";
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
387 char *ptr;
9848
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
388 double result;
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
389 errno = 0;
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
390 result = strtod (input, &ptr);
9821
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
391 ASSERT (result == 0.0);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
392 ASSERT (!signbit (result));
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
393 ASSERT (ptr == input + 2);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
394 ASSERT (errno == 0);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
395 }
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
396 {
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
397 const char input[] = "-0x";
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
398 char *ptr;
9848
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
399 double result;
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
400 errno = 0;
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
401 result = strtod (input, &ptr);
9821
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
402 ASSERT (result == 0.0);
9846
25b01b718f02 Don't compare actual signbit return values.
Jim Meyering <meyering@redhat.com>
parents: 9841
diff changeset
403 ASSERT (!!signbit (result) == !!signbit (-0.0)); /* MacOS X 10.3, FreeBSD 6.2, IRIX 6.5 */
9841
a95dd6984607 Add info about many more platforms.
Bruno Haible <bruno@clisp.org>
parents: 9839
diff changeset
404 ASSERT (ptr == input + 2); /* glibc-2.3.6, MacOS X 10.3, FreeBSD 6.2 */
9821
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
405 ASSERT (errno == 0);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
406 }
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
407 {
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
408 const char input[] = "0xg";
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
409 char *ptr;
9848
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
410 double result;
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
411 errno = 0;
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
412 result = strtod (input, &ptr);
9821
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
413 ASSERT (result == 0.0);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
414 ASSERT (!signbit (result));
9841
a95dd6984607 Add info about many more platforms.
Bruno Haible <bruno@clisp.org>
parents: 9839
diff changeset
415 ASSERT (ptr == input + 1); /* glibc-2.3.6, MacOS X 10.3, FreeBSD 6.2 */
9821
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
416 ASSERT (errno == 0);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
417 }
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
418 {
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
419 const char input[] = "0xp";
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
420 char *ptr;
9848
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
421 double result;
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
422 errno = 0;
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
423 result = strtod (input, &ptr);
9821
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
424 ASSERT (result == 0.0);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
425 ASSERT (!signbit (result));
9841
a95dd6984607 Add info about many more platforms.
Bruno Haible <bruno@clisp.org>
parents: 9839
diff changeset
426 ASSERT (ptr == input + 1); /* glibc-2.3.6, MacOS X 10.3, FreeBSD 6.2 */
9821
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
427 ASSERT (errno == 0);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
428 }
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
429 {
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
430 const char input[] = "0x.";
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
431 char *ptr;
9848
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
432 double result;
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
433 errno = 0;
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
434 result = strtod (input, &ptr);
9821
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
435 ASSERT (result == 0.0);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
436 ASSERT (!signbit (result));
9841
a95dd6984607 Add info about many more platforms.
Bruno Haible <bruno@clisp.org>
parents: 9839
diff changeset
437 ASSERT (ptr == input + 1); /* glibc-2.3.6, MacOS X 10.3, FreeBSD 6.2 */
9821
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
438 ASSERT (errno == 0);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
439 }
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
440 {
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
441 const char input[] = "0xp+";
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
442 char *ptr;
9848
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
443 double result;
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
444 errno = 0;
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
445 result = strtod (input, &ptr);
9821
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
446 ASSERT (result == 0.0);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
447 ASSERT (!signbit (result));
9841
a95dd6984607 Add info about many more platforms.
Bruno Haible <bruno@clisp.org>
parents: 9839
diff changeset
448 ASSERT (ptr == input + 1); /* glibc-2.3.6, MacOS X 10.3, FreeBSD 6.2 */
9821
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
449 ASSERT (errno == 0);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
450 }
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
451 {
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
452 const char input[] = "0xp+1";
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
453 char *ptr;
9848
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
454 double result;
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
455 errno = 0;
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
456 result = strtod (input, &ptr);
9821
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
457 ASSERT (result == 0.0);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
458 ASSERT (!signbit (result));
9841
a95dd6984607 Add info about many more platforms.
Bruno Haible <bruno@clisp.org>
parents: 9839
diff changeset
459 ASSERT (ptr == input + 1); /* glibc-2.3.6, MacOS X 10.3, FreeBSD 6.2 */
9821
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
460 ASSERT (errno == 0);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
461 }
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
462 {
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
463 const char input[] = "0x.p+1";
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
464 char *ptr;
9848
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
465 double result;
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
466 errno = 0;
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
467 result = strtod (input, &ptr);
9821
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
468 ASSERT (result == 0.0);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
469 ASSERT (!signbit (result));
9841
a95dd6984607 Add info about many more platforms.
Bruno Haible <bruno@clisp.org>
parents: 9839
diff changeset
470 ASSERT (ptr == input + 1); /* glibc-2.3.6, MacOS X 10.3, FreeBSD 6.2 */
9821
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
471 ASSERT (errno == 0);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
472 }
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
473 {
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
474 const char input[] = "1p+1";
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
475 char *ptr;
9848
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
476 double result;
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
477 errno = 0;
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
478 result = strtod (input, &ptr);
9821
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
479 ASSERT (result == 1.0);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
480 ASSERT (ptr == input + 1);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
481 ASSERT (errno == 0);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
482 }
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
483
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
484 /* Overflow/underflow. */
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
485 {
9837
8c80e0046993 More strtod touchups.
Eric Blake <ebb9@byu.net>
parents: 9822
diff changeset
486 const char input[] = "1E1000000";
9821
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
487 char *ptr;
9848
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
488 double result;
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
489 errno = 0;
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
490 result = strtod (input, &ptr);
9821
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
491 ASSERT (result == HUGE_VAL);
9839
3dc6b2551b2e Fix typo in last patch.
Eric Blake <ebb9@byu.net>
parents: 9837
diff changeset
492 ASSERT (ptr == input + 9);
9821
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
493 ASSERT (errno == ERANGE);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
494 }
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
495 {
9837
8c80e0046993 More strtod touchups.
Eric Blake <ebb9@byu.net>
parents: 9822
diff changeset
496 const char input[] = "-1E1000000";
9821
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
497 char *ptr;
9848
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
498 double result;
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
499 errno = 0;
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
500 result = strtod (input, &ptr);
9821
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
501 ASSERT (result == -HUGE_VAL);
9839
3dc6b2551b2e Fix typo in last patch.
Eric Blake <ebb9@byu.net>
parents: 9837
diff changeset
502 ASSERT (ptr == input + 10);
9821
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
503 ASSERT (errno == ERANGE);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
504 }
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
505 {
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
506 const char input[] = "1E-100000";
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
507 char *ptr;
9848
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
508 double result;
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
509 errno = 0;
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
510 result = strtod (input, &ptr);
9821
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
511 ASSERT (0.0 <= result && result <= FLT_MIN);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
512 ASSERT (!signbit (result));
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
513 ASSERT (ptr == input + 9);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
514 ASSERT (errno == ERANGE);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
515 }
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
516 {
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
517 const char input[] = "-1E-100000";
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
518 char *ptr;
9848
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
519 double result;
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
520 errno = 0;
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
521 result = strtod (input, &ptr);
9821
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
522 ASSERT (-FLT_MIN <= result && result <= 0.0);
9837
8c80e0046993 More strtod touchups.
Eric Blake <ebb9@byu.net>
parents: 9822
diff changeset
523 #if 0
8c80e0046993 More strtod touchups.
Eric Blake <ebb9@byu.net>
parents: 9822
diff changeset
524 /* FIXME - this is glibc bug 5995; POSIX allows returning positive
8c80e0046993 More strtod touchups.
Eric Blake <ebb9@byu.net>
parents: 9822
diff changeset
525 0 on negative underflow, even though quality of implementation
8c80e0046993 More strtod touchups.
Eric Blake <ebb9@byu.net>
parents: 9822
diff changeset
526 demands preserving the sign. Disable this test until fixed
8c80e0046993 More strtod touchups.
Eric Blake <ebb9@byu.net>
parents: 9822
diff changeset
527 glibc is more prevalent. */
9846
25b01b718f02 Don't compare actual signbit return values.
Jim Meyering <meyering@redhat.com>
parents: 9841
diff changeset
528 ASSERT (!!signbit (result) == !!signbit (-0.0)); /* glibc-2.3.6, mingw */
9837
8c80e0046993 More strtod touchups.
Eric Blake <ebb9@byu.net>
parents: 9822
diff changeset
529 #endif
9821
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
530 ASSERT (ptr == input + 10);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
531 ASSERT (errno == ERANGE);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
532 }
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
533
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
534 /* Infinity. */
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
535 {
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
536 const char input[] = "iNf";
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
537 char *ptr;
9848
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
538 double result;
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
539 errno = 0;
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
540 result = strtod (input, &ptr);
9841
a95dd6984607 Add info about many more platforms.
Bruno Haible <bruno@clisp.org>
parents: 9839
diff changeset
541 ASSERT (result == HUGE_VAL); /* OpenBSD 4.0, IRIX 6.5, OSF/1 5.1, mingw */
a95dd6984607 Add info about many more platforms.
Bruno Haible <bruno@clisp.org>
parents: 9839
diff changeset
542 ASSERT (ptr == input + 3); /* OpenBSD 4.0, HP-UX 11.00, IRIX 6.5, OSF/1 5.1, Solaris 9, mingw */
a95dd6984607 Add info about many more platforms.
Bruno Haible <bruno@clisp.org>
parents: 9839
diff changeset
543 ASSERT (errno == 0); /* HP-UX 11.11, OSF/1 4.0 */
9821
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
544 }
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
545 {
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
546 const char input[] = "-InF";
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
547 char *ptr;
9848
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
548 double result;
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
549 errno = 0;
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
550 result = strtod (input, &ptr);
9841
a95dd6984607 Add info about many more platforms.
Bruno Haible <bruno@clisp.org>
parents: 9839
diff changeset
551 ASSERT (result == -HUGE_VAL); /* OpenBSD 4.0, IRIX 6.5, OSF/1 5.1, mingw */
a95dd6984607 Add info about many more platforms.
Bruno Haible <bruno@clisp.org>
parents: 9839
diff changeset
552 ASSERT (ptr == input + 4); /* OpenBSD 4.0, HP-UX 11.00, IRIX 6.5, OSF/1 4.0, Solaris 9, mingw */
a95dd6984607 Add info about many more platforms.
Bruno Haible <bruno@clisp.org>
parents: 9839
diff changeset
553 ASSERT (errno == 0); /* HP-UX 11.11, OSF/1 4.0 */
9821
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
554 }
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
555 {
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
556 const char input[] = "infinite";
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
557 char *ptr;
9848
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
558 double result;
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
559 errno = 0;
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
560 result = strtod (input, &ptr);
9841
a95dd6984607 Add info about many more platforms.
Bruno Haible <bruno@clisp.org>
parents: 9839
diff changeset
561 ASSERT (result == HUGE_VAL); /* OpenBSD 4.0, HP-UX 11.11, IRIX 6.5, OSF/1 5.1, mingw */
a95dd6984607 Add info about many more platforms.
Bruno Haible <bruno@clisp.org>
parents: 9839
diff changeset
562 ASSERT (ptr == input + 3); /* OpenBSD 4.0, HP-UX 11.11, IRIX 6.5, OSF/1 5.1, mingw */
a95dd6984607 Add info about many more platforms.
Bruno Haible <bruno@clisp.org>
parents: 9839
diff changeset
563 ASSERT (errno == 0); /* OSF/1 4.0 */
9821
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
564 }
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
565 {
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
566 const char input[] = "infinitY";
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
567 char *ptr;
9848
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
568 double result;
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
569 errno = 0;
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
570 result = strtod (input, &ptr);
9841
a95dd6984607 Add info about many more platforms.
Bruno Haible <bruno@clisp.org>
parents: 9839
diff changeset
571 ASSERT (result == HUGE_VAL); /* OpenBSD 4.0, IRIX 6.5, OSF/1 5.1, mingw */
a95dd6984607 Add info about many more platforms.
Bruno Haible <bruno@clisp.org>
parents: 9839
diff changeset
572 ASSERT (ptr == input + 8); /* OpenBSD 4.0, HP-UX 11.00, IRIX 6.5, OSF/1 5.1, Solaris 9, mingw */
a95dd6984607 Add info about many more platforms.
Bruno Haible <bruno@clisp.org>
parents: 9839
diff changeset
573 ASSERT (errno == 0); /* HP-UX 11.11, OSF/1 4.0 */
9821
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
574 }
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
575 {
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
576 const char input[] = "infinitY.";
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
577 char *ptr;
9848
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
578 double result;
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
579 errno = 0;
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
580 result = strtod (input, &ptr);
9841
a95dd6984607 Add info about many more platforms.
Bruno Haible <bruno@clisp.org>
parents: 9839
diff changeset
581 ASSERT (result == HUGE_VAL); /* OpenBSD 4.0, HP-UX 11.11, IRIX 6.5, OSF/1 5.1, mingw */
a95dd6984607 Add info about many more platforms.
Bruno Haible <bruno@clisp.org>
parents: 9839
diff changeset
582 ASSERT (ptr == input + 8); /* OpenBSD 4.0, HP-UX 11.11, IRIX 6.5, OSF/1 5.1, mingw */
a95dd6984607 Add info about many more platforms.
Bruno Haible <bruno@clisp.org>
parents: 9839
diff changeset
583 ASSERT (errno == 0); /* OSF/1 4.0 */
9821
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
584 }
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
585
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
586 /* NaN. Some processors set the sign bit of the default NaN, so all
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
587 we check is that using a sign changes the result. */
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
588 {
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
589 const char input[] = "-nan";
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
590 char *ptr1;
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
591 char *ptr2;
9848
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
592 double result1;
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
593 double result2;
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
594 errno = 0;
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
595 result1 = strtod (input, &ptr1);
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
596 result2 = strtod (input + 1, &ptr2);
9847
bb111aa32127 Assume NaNs exist; don't test the NAN macro.
Bruno Haible <bruno@clisp.org>
parents: 9846
diff changeset
597 #if 1 /* All known CPUs support NaNs. */
9841
a95dd6984607 Add info about many more platforms.
Bruno Haible <bruno@clisp.org>
parents: 9839
diff changeset
598 ASSERT (isnan (result1)); /* OpenBSD 4.0, IRIX 6.5, OSF/1 5.1, mingw */
a95dd6984607 Add info about many more platforms.
Bruno Haible <bruno@clisp.org>
parents: 9839
diff changeset
599 ASSERT (isnan (result2)); /* OpenBSD 4.0, IRIX 6.5, OSF/1 5.1, mingw */
9837
8c80e0046993 More strtod touchups.
Eric Blake <ebb9@byu.net>
parents: 9822
diff changeset
600 # if 0
8c80e0046993 More strtod touchups.
Eric Blake <ebb9@byu.net>
parents: 9822
diff changeset
601 /* Sign bits of NaN is a portability sticking point, not worth
8c80e0046993 More strtod touchups.
Eric Blake <ebb9@byu.net>
parents: 9822
diff changeset
602 worrying about. */
9846
25b01b718f02 Don't compare actual signbit return values.
Jim Meyering <meyering@redhat.com>
parents: 9841
diff changeset
603 ASSERT (!!signbit (result1) != !!signbit (result2)); /* glibc-2.3.6, IRIX 6.5, OSF/1 5.1, mingw */
9837
8c80e0046993 More strtod touchups.
Eric Blake <ebb9@byu.net>
parents: 9822
diff changeset
604 # endif
9841
a95dd6984607 Add info about many more platforms.
Bruno Haible <bruno@clisp.org>
parents: 9839
diff changeset
605 ASSERT (ptr1 == input + 4); /* OpenBSD 4.0, IRIX 6.5, OSF/1 5.1, Solaris 2.5.1, mingw */
a95dd6984607 Add info about many more platforms.
Bruno Haible <bruno@clisp.org>
parents: 9839
diff changeset
606 ASSERT (ptr2 == input + 4); /* OpenBSD 4.0, IRIX 6.5, OSF/1 5.1, Solaris 2.5.1, mingw */
a95dd6984607 Add info about many more platforms.
Bruno Haible <bruno@clisp.org>
parents: 9839
diff changeset
607 ASSERT (errno == 0); /* HP-UX 11.11 */
9821
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
608 #else
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
609 ASSERT (result1 == 0.0);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
610 ASSERT (result2 == 0.0);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
611 ASSERT (!signbit (result1));
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
612 ASSERT (!signbit (result2));
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
613 ASSERT (ptr1 == input);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
614 ASSERT (ptr2 == input + 1);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
615 ASSERT (errno == 0 || errno == EINVAL);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
616 #endif
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
617 }
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
618 {
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
619 const char input[] = "+nan(";
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
620 char *ptr1;
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
621 char *ptr2;
9848
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
622 double result1;
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
623 double result2;
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
624 errno = 0;
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
625 result1 = strtod (input, &ptr1);
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
626 result2 = strtod (input + 1, &ptr2);
9847
bb111aa32127 Assume NaNs exist; don't test the NAN macro.
Bruno Haible <bruno@clisp.org>
parents: 9846
diff changeset
627 #if 1 /* All known CPUs support NaNs. */
9841
a95dd6984607 Add info about many more platforms.
Bruno Haible <bruno@clisp.org>
parents: 9839
diff changeset
628 ASSERT (isnan (result1)); /* OpenBSD 4.0, HP-UX 11.11, IRIX 6.5, OSF/1 5.1, mingw */
a95dd6984607 Add info about many more platforms.
Bruno Haible <bruno@clisp.org>
parents: 9839
diff changeset
629 ASSERT (isnan (result2)); /* OpenBSD 4.0, HP-UX 11.11, IRIX 6.5, OSF/1 5.1, mingw */
9846
25b01b718f02 Don't compare actual signbit return values.
Jim Meyering <meyering@redhat.com>
parents: 9841
diff changeset
630 ASSERT (!!signbit (result1) == !!signbit (result2));
9841
a95dd6984607 Add info about many more platforms.
Bruno Haible <bruno@clisp.org>
parents: 9839
diff changeset
631 ASSERT (ptr1 == input + 4); /* OpenBSD 4.0, HP-UX 11.11, IRIX 6.5, OSF/1 5.1, Solaris 2.5.1, mingw */
a95dd6984607 Add info about many more platforms.
Bruno Haible <bruno@clisp.org>
parents: 9839
diff changeset
632 ASSERT (ptr2 == input + 4); /* OpenBSD 4.0, HP-UX 11.11, IRIX 6.5, OSF/1 5.1, Solaris 2.5.1, mingw */
9821
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
633 ASSERT (errno == 0);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
634 #else
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
635 ASSERT (result1 == 0.0);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
636 ASSERT (result2 == 0.0);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
637 ASSERT (!signbit (result1));
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
638 ASSERT (!signbit (result2));
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
639 ASSERT (ptr1 == input);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
640 ASSERT (ptr2 == input + 1);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
641 ASSERT (errno == 0 || errno == EINVAL);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
642 #endif
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
643 }
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
644 {
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
645 const char input[] = "-nan()";
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
646 char *ptr1;
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
647 char *ptr2;
9848
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
648 double result1;
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
649 double result2;
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
650 errno = 0;
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
651 result1 = strtod (input, &ptr1);
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
652 result2 = strtod (input + 1, &ptr2);
9847
bb111aa32127 Assume NaNs exist; don't test the NAN macro.
Bruno Haible <bruno@clisp.org>
parents: 9846
diff changeset
653 #if 1 /* All known CPUs support NaNs. */
9841
a95dd6984607 Add info about many more platforms.
Bruno Haible <bruno@clisp.org>
parents: 9839
diff changeset
654 ASSERT (isnan (result1)); /* OpenBSD 4.0, HP-UX 11.11, IRIX 6.5, OSF/1 5.1, mingw */
a95dd6984607 Add info about many more platforms.
Bruno Haible <bruno@clisp.org>
parents: 9839
diff changeset
655 ASSERT (isnan (result2)); /* OpenBSD 4.0, HP-UX 11.11, IRIX 6.5, OSF/1 5.1, mingw */
9837
8c80e0046993 More strtod touchups.
Eric Blake <ebb9@byu.net>
parents: 9822
diff changeset
656 # if 0
8c80e0046993 More strtod touchups.
Eric Blake <ebb9@byu.net>
parents: 9822
diff changeset
657 /* Sign bits of NaN is a portability sticking point, not worth
8c80e0046993 More strtod touchups.
Eric Blake <ebb9@byu.net>
parents: 9822
diff changeset
658 worrying about. */
9846
25b01b718f02 Don't compare actual signbit return values.
Jim Meyering <meyering@redhat.com>
parents: 9841
diff changeset
659 ASSERT (!!signbit (result1) != !!signbit (result2)); /* glibc-2.3.6, IRIX 6.5, OSF/1 5.1, mingw */
9837
8c80e0046993 More strtod touchups.
Eric Blake <ebb9@byu.net>
parents: 9822
diff changeset
660 # endif
9841
a95dd6984607 Add info about many more platforms.
Bruno Haible <bruno@clisp.org>
parents: 9839
diff changeset
661 ASSERT (ptr1 == input + 6); /* glibc-2.3.6, MacOS X 10.3, FreeBSD 6.2, OpenBSD 4.0, AIX 5.1, HP-UX 11.11, IRIX 6.5, OSF/1 5.1, mingw */
a95dd6984607 Add info about many more platforms.
Bruno Haible <bruno@clisp.org>
parents: 9839
diff changeset
662 ASSERT (ptr2 == input + 6); /* glibc-2.3.6, MacOS X 10.3, FreeBSD 6.2, OpenBSD 4.0, AIX 5.1, HP-UX 11.11, IRIX 6.5, OSF/1 5.1, mingw */
9821
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
663 ASSERT (errno == 0);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
664 #else
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
665 ASSERT (result1 == 0.0);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
666 ASSERT (result2 == 0.0);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
667 ASSERT (!signbit (result1));
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
668 ASSERT (!signbit (result2));
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
669 ASSERT (ptr1 == input);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
670 ASSERT (ptr2 == input + 1);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
671 ASSERT (errno == 0 || errno == EINVAL);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
672 #endif
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
673 }
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
674 {
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
675 const char input[] = " nan().";
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
676 char *ptr;
9848
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
677 double result;
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
678 errno = 0;
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
679 result = strtod (input, &ptr);
9847
bb111aa32127 Assume NaNs exist; don't test the NAN macro.
Bruno Haible <bruno@clisp.org>
parents: 9846
diff changeset
680 #if 1 /* All known CPUs support NaNs. */
9841
a95dd6984607 Add info about many more platforms.
Bruno Haible <bruno@clisp.org>
parents: 9839
diff changeset
681 ASSERT (isnan (result)); /* OpenBSD 4.0, HP-UX 11.11, IRIX 6.5, OSF/1 5.1, mingw */
a95dd6984607 Add info about many more platforms.
Bruno Haible <bruno@clisp.org>
parents: 9839
diff changeset
682 ASSERT (ptr == input + 6); /* glibc-2.3.6, MacOS X 10.3, FreeBSD 6.2, OpenBSD 4.0, AIX 5.1, HP-UX 11.11, IRIX 6.5, OSF/1 5.1, mingw */
9821
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
683 ASSERT (errno == 0);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
684 #else
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
685 ASSERT (result == 0.0);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
686 ASSERT (!signbit (result));
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
687 ASSERT (ptr == input);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
688 ASSERT (errno == 0 || errno == EINVAL);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
689 #endif
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
690 }
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
691 {
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
692 /* The behavior of nan(0) is implementation-defined, but all
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
693 implementations we know of which handle optional
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
694 n-char-sequences handle nan(0) the same as nan(). */
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
695 const char input[] = "-nan(0).";
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
696 char *ptr1;
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
697 char *ptr2;
9848
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
698 double result1;
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
699 double result2;
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
700 errno = 0;
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
701 result1 = strtod (input, &ptr1);
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
702 result2 = strtod (input + 1, &ptr2);
9847
bb111aa32127 Assume NaNs exist; don't test the NAN macro.
Bruno Haible <bruno@clisp.org>
parents: 9846
diff changeset
703 #if 1 /* All known CPUs support NaNs. */
9841
a95dd6984607 Add info about many more platforms.
Bruno Haible <bruno@clisp.org>
parents: 9839
diff changeset
704 ASSERT (isnan (result1)); /* OpenBSD 4.0, HP-UX 11.11, IRIX 6.5, OSF/1 5.1, mingw */
a95dd6984607 Add info about many more platforms.
Bruno Haible <bruno@clisp.org>
parents: 9839
diff changeset
705 ASSERT (isnan (result2)); /* OpenBSD 4.0, HP-UX 11.11, IRIX 6.5, OSF/1 5.1, mingw */
9837
8c80e0046993 More strtod touchups.
Eric Blake <ebb9@byu.net>
parents: 9822
diff changeset
706 # if 0
8c80e0046993 More strtod touchups.
Eric Blake <ebb9@byu.net>
parents: 9822
diff changeset
707 /* Sign bits of NaN is a portability sticking point, not worth
8c80e0046993 More strtod touchups.
Eric Blake <ebb9@byu.net>
parents: 9822
diff changeset
708 worrying about. */
9846
25b01b718f02 Don't compare actual signbit return values.
Jim Meyering <meyering@redhat.com>
parents: 9841
diff changeset
709 ASSERT (!!signbit (result1) != !!signbit (result2)); /* glibc-2.3.6, IRIX 6.5, OSF/1 5.1, mingw */
9837
8c80e0046993 More strtod touchups.
Eric Blake <ebb9@byu.net>
parents: 9822
diff changeset
710 # endif
9841
a95dd6984607 Add info about many more platforms.
Bruno Haible <bruno@clisp.org>
parents: 9839
diff changeset
711 ASSERT (ptr1 == input + 7); /* glibc-2.3.6, OpenBSD 4.0, AIX 5.1, HP-UX 11.11, IRIX 6.5, OSF/1 5.1, mingw */
a95dd6984607 Add info about many more platforms.
Bruno Haible <bruno@clisp.org>
parents: 9839
diff changeset
712 ASSERT (ptr2 == input + 7); /* glibc-2.3.6, OpenBSD 4.0, AIX 5.1, HP-UX 11.11, IRIX 6.5, OSF/1 5.1, mingw */
9821
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
713 ASSERT (errno == 0);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
714 #else
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
715 ASSERT (result1 == 0.0);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
716 ASSERT (result2 == 0.0);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
717 ASSERT (!signbit (result1));
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
718 ASSERT (!signbit (result2));
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
719 ASSERT (ptr1 == input);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
720 ASSERT (ptr2 == input + 1);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
721 ASSERT (errno == 0 || errno == EINVAL);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
722 #endif
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
723 }
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
724
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
725 /* Hex. */
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
726 {
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
727 const char input[] = "0xa";
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
728 char *ptr;
9848
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
729 double result;
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
730 errno = 0;
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
731 result = strtod (input, &ptr);
9841
a95dd6984607 Add info about many more platforms.
Bruno Haible <bruno@clisp.org>
parents: 9839
diff changeset
732 ASSERT (result == 10.0); /* NetBSD 3.0, OpenBSD 4.0, AIX 5.1, HP-UX 11.11, IRIX 6.5, OSF/1 5.1, Solaris 10, mingw */
a95dd6984607 Add info about many more platforms.
Bruno Haible <bruno@clisp.org>
parents: 9839
diff changeset
733 ASSERT (ptr == input + 3); /* NetBSD 3.0, OpenBSD 4.0, AIX 5.1, HP-UX 11.11, IRIX 6.5, OSF/1 5.1, Solaris 10, mingw */
9821
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
734 ASSERT (errno == 0);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
735 }
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
736 {
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
737 const char input[] = "0XA";
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
738 char *ptr;
9848
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
739 double result;
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
740 errno = 0;
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
741 result = strtod (input, &ptr);
9841
a95dd6984607 Add info about many more platforms.
Bruno Haible <bruno@clisp.org>
parents: 9839
diff changeset
742 ASSERT (result == 10.0); /* NetBSD 3.0, OpenBSD 4.0, AIX 5.1, HP-UX 11.11, IRIX 6.5, OSF/1 5.1, Solaris 10, mingw */
a95dd6984607 Add info about many more platforms.
Bruno Haible <bruno@clisp.org>
parents: 9839
diff changeset
743 ASSERT (ptr == input + 3); /* NetBSD 3.0, OpenBSD 4.0, AIX 5.1, HP-UX 11.11, IRIX 6.5, OSF/1 5.1, Solaris 10, mingw */
9821
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
744 ASSERT (errno == 0);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
745 }
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
746 {
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
747 const char input[] = "0x1p";
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
748 char *ptr;
9848
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
749 double result;
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
750 errno = 0;
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
751 result = strtod (input, &ptr);
9841
a95dd6984607 Add info about many more platforms.
Bruno Haible <bruno@clisp.org>
parents: 9839
diff changeset
752 ASSERT (result == 1.0); /* NetBSD 3.0, OpenBSD 4.0, AIX 5.1, HP-UX 11.11, IRIX 6.5, OSF/1 5.1, Solaris 10, mingw */
a95dd6984607 Add info about many more platforms.
Bruno Haible <bruno@clisp.org>
parents: 9839
diff changeset
753 ASSERT (ptr == input + 3); /* NetBSD 3.0, OpenBSD 4.0, AIX 5.1, HP-UX 11.11, IRIX 6.5, OSF/1 5.1, Solaris 10, mingw */
9821
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
754 ASSERT (errno == 0);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
755 }
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
756 {
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
757 const char input[] = "0x1p+";
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
758 char *ptr;
9848
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
759 double result;
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
760 errno = 0;
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
761 result = strtod (input, &ptr);
9841
a95dd6984607 Add info about many more platforms.
Bruno Haible <bruno@clisp.org>
parents: 9839
diff changeset
762 ASSERT (result == 1.0); /* NetBSD 3.0, OpenBSD 4.0, AIX 5.1, HP-UX 11.11, IRIX 6.5, OSF/1 5.1, Solaris 10, mingw */
a95dd6984607 Add info about many more platforms.
Bruno Haible <bruno@clisp.org>
parents: 9839
diff changeset
763 ASSERT (ptr == input + 3); /* NetBSD 3.0, OpenBSD 4.0, AIX 5.1, HP-UX 11.11, IRIX 6.5, OSF/1 5.1, Solaris 10, mingw */
9821
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
764 ASSERT (errno == 0);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
765 }
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
766 {
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
767 const char input[] = "0x1p+1";
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
768 char *ptr;
9848
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
769 double result;
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
770 errno = 0;
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
771 result = strtod (input, &ptr);
9841
a95dd6984607 Add info about many more platforms.
Bruno Haible <bruno@clisp.org>
parents: 9839
diff changeset
772 ASSERT (result == 2.0); /* NetBSD 3.0, OpenBSD 4.0, AIX 5.1, HP-UX 11.11, IRIX 6.5, OSF/1 5.1, Solaris 10, mingw */
a95dd6984607 Add info about many more platforms.
Bruno Haible <bruno@clisp.org>
parents: 9839
diff changeset
773 ASSERT (ptr == input + 6); /* NetBSD 3.0, OpenBSD 4.0, AIX 5.1, HP-UX 11.11, IRIX 6.5, OSF/1 5.1, Solaris 10, mingw */
9821
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
774 ASSERT (errno == 0);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
775 }
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
776 {
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
777 const char input[] = "0x1p+1a";
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
778 char *ptr;
9848
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
779 double result;
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
780 errno = 0;
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
781 result = strtod (input, &ptr);
9841
a95dd6984607 Add info about many more platforms.
Bruno Haible <bruno@clisp.org>
parents: 9839
diff changeset
782 ASSERT (result == 2.0); /* NetBSD 3.0, OpenBSD 4.0, AIX 5.1, HP-UX 11.11, IRIX 6.5, OSF/1 5.1, Solaris 10, mingw */
a95dd6984607 Add info about many more platforms.
Bruno Haible <bruno@clisp.org>
parents: 9839
diff changeset
783 ASSERT (ptr == input + 6); /* NetBSD 3.0, OpenBSD 4.0, AIX 5.1, HP-UX 11.11, IRIX 6.5, OSF/1 5.1, Solaris 10, mingw */
9821
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
784 ASSERT (errno == 0);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
785 }
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
786
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
787 /* Large buffers. */
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
788 {
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
789 size_t m = 1000000;
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
790 char *input = malloc (m + 1);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
791 if (input)
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
792 {
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
793 char *ptr;
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
794 double result;
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
795 memset (input, '\t', m - 1);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
796 input[m - 1] = '1';
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
797 input[m] = '\0';
9848
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
798 errno = 0;
9821
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
799 result = strtod (input, &ptr);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
800 ASSERT (result == 1.0);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
801 ASSERT (ptr == input + m);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
802 ASSERT (errno == 0);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
803 }
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
804 free (input);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
805 }
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
806 {
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
807 size_t m = 1000000;
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
808 char *input = malloc (m + 1);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
809 if (input)
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
810 {
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
811 char *ptr;
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
812 double result;
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
813 memset (input, '0', m - 1);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
814 input[m - 1] = '1';
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
815 input[m] = '\0';
9848
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
816 errno = 0;
9821
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
817 result = strtod (input, &ptr);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
818 ASSERT (result == 1.0);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
819 ASSERT (ptr == input + m);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
820 ASSERT (errno == 0);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
821 }
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
822 free (input);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
823 }
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
824 #if 0
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
825 /* Newlib has an artificial limit of 20000 for the exponent. TODO -
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
826 gnulib should fix this. */
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
827 {
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
828 size_t m = 1000000;
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
829 char *input = malloc (m + 1);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
830 if (input)
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
831 {
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
832 char *ptr;
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
833 double result;
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
834 input[0] = '.';
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
835 memset (input + 1, '0', m - 10);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
836 input[m - 9] = '1';
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
837 input[m - 8] = 'e';
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
838 input[m - 7] = '+';
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
839 input[m - 6] = '9';
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
840 input[m - 5] = '9';
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
841 input[m - 4] = '9';
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
842 input[m - 3] = '9';
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
843 input[m - 2] = '9';
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
844 input[m - 1] = '1';
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
845 input[m] = '\0';
9848
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
846 errno = 0;
9821
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
847 result = strtod (input, &ptr);
9841
a95dd6984607 Add info about many more platforms.
Bruno Haible <bruno@clisp.org>
parents: 9839
diff changeset
848 ASSERT (result == 1.0); /* MacOS X 10.3, FreeBSD 6.2, NetBSD 3.0, OpenBSD 4.0, IRIX 6.5, OSF/1 5.1, mingw */
a95dd6984607 Add info about many more platforms.
Bruno Haible <bruno@clisp.org>
parents: 9839
diff changeset
849 ASSERT (ptr == input + m); /* OSF/1 5.1 */
a95dd6984607 Add info about many more platforms.
Bruno Haible <bruno@clisp.org>
parents: 9839
diff changeset
850 ASSERT (errno == 0); /* MacOS X 10.3, FreeBSD 6.2, NetBSD 3.0, OpenBSD 4.0, IRIX 6.5, OSF/1 5.1, mingw */
9821
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
851 }
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
852 free (input);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
853 }
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
854 {
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
855 size_t m = 1000000;
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
856 char *input = malloc (m + 1);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
857 if (input)
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
858 {
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
859 char *ptr;
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
860 double result;
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
861 input[0] = '1';
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
862 memset (input + 1, '0', m - 9);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
863 input[m - 8] = 'e';
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
864 input[m - 7] = '-';
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
865 input[m - 6] = '9';
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
866 input[m - 5] = '9';
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
867 input[m - 4] = '9';
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
868 input[m - 3] = '9';
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
869 input[m - 2] = '9';
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
870 input[m - 1] = '1';
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
871 input[m] = '\0';
9848
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
872 errno = 0;
9821
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
873 result = strtod (input, &ptr);
9841
a95dd6984607 Add info about many more platforms.
Bruno Haible <bruno@clisp.org>
parents: 9839
diff changeset
874 ASSERT (result == 1.0); /* MacOS X 10.3, FreeBSD 6.2, NetBSD 3.0, OpenBSD 4.0, IRIX 6.5, OSF/1 5.1, mingw */
9821
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
875 ASSERT (ptr == input + m);
9841
a95dd6984607 Add info about many more platforms.
Bruno Haible <bruno@clisp.org>
parents: 9839
diff changeset
876 ASSERT (errno == 0); /* MacOS X 10.3, FreeBSD 6.2, NetBSD 3.0, OpenBSD 4.0, IRIX 6.5, OSF/1 5.1, mingw */
9821
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
877 }
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
878 free (input);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
879 }
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
880 #endif
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
881 {
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
882 size_t m = 1000000;
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
883 char *input = malloc (m + 1);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
884 if (input)
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
885 {
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
886 char *ptr;
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
887 double result;
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
888 input[0] = '-';
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
889 input[1] = '0';
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
890 input[2] = 'e';
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
891 input[3] = '1';
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
892 memset (input + 4, '0', m - 3);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
893 input[m] = '\0';
9848
3dbacd929304 Convert from C99 syntax to C89 syntax.
Bruno Haible <bruno@clisp.org>
parents: 9847
diff changeset
894 errno = 0;
9821
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
895 result = strtod (input, &ptr);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
896 ASSERT (result == 0.0);
9846
25b01b718f02 Don't compare actual signbit return values.
Jim Meyering <meyering@redhat.com>
parents: 9841
diff changeset
897 ASSERT (!!signbit (result) == !!signbit (-0.0)); /* IRIX 6.5 */
9821
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
898 ASSERT (ptr == input + m);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
899 ASSERT (errno == 0);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
900 }
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
901 free (input);
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
902 }
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
903
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
904 /* Rounding. */
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
905 /* TODO - is it worth some tests of rounding for typical IEEE corner
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
906 cases, such as .5 ULP rounding up to the smallest denormal and
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
907 not causing underflow, or FLT_MIN - .5 ULP not causing an
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
908 infinite loop? */
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
909
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
910 return status;
18bab9955c43 Document various strtod bugs, with some fixes.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
911 }