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