1 | /* Test to strtod etc for numbers like x000...0000.000e-nn.
|
---|
2 | This file is part of the GNU C Library.
|
---|
3 | Copyright (C) 2001 Free Software Foundation, Inc.
|
---|
4 | Contributed by Ulrich Drepper <drepper@redhat.com>, 2001.
|
---|
5 |
|
---|
6 | The GNU C Library is free software; you can redistribute it and/or
|
---|
7 | modify it under the terms of the GNU Lesser General Public
|
---|
8 | License as published by the Free Software Foundation; either
|
---|
9 | version 2.1 of the License, or (at your option) any later version.
|
---|
10 |
|
---|
11 | The GNU C Library is distributed in the hope that it will be useful,
|
---|
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
14 | Lesser General Public License for more details.
|
---|
15 |
|
---|
16 | You should have received a copy of the GNU Lesser General Public
|
---|
17 | License along with the GNU C Library; if not, write to the Free
|
---|
18 | Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
---|
19 | 02111-1307 USA. */
|
---|
20 |
|
---|
21 | #include <stdio.h>
|
---|
22 | #include <stdlib.h>
|
---|
23 | #include <string.h>
|
---|
24 | #ifdef __EMX__ /* one of the above seems to be declaring ssize_t... glibc feat I guess. */
|
---|
25 | #include <sys/types.h>
|
---|
26 | #endif
|
---|
27 |
|
---|
28 |
|
---|
29 | int
|
---|
30 | main (void)
|
---|
31 | {
|
---|
32 | char buf[300];
|
---|
33 | int cnt;
|
---|
34 | int result = 0;
|
---|
35 |
|
---|
36 | for (cnt = 0; cnt < 200; ++cnt)
|
---|
37 | {
|
---|
38 | ssize_t n;
|
---|
39 | float f;
|
---|
40 |
|
---|
41 | n = sprintf (buf, "%d", cnt);
|
---|
42 | memset (buf + n, '0', cnt);
|
---|
43 | sprintf (buf + n + cnt, ".000e-%d", cnt);
|
---|
44 | f = strtof (buf, NULL);
|
---|
45 |
|
---|
46 | if (f != (float) cnt)
|
---|
47 | {
|
---|
48 | printf ("strtof(\"%s\") failed for cnt == %d (%g instead of %g)\n",
|
---|
49 | buf, cnt, f, (float) cnt);
|
---|
50 | result = 1;
|
---|
51 | }
|
---|
52 | else
|
---|
53 | printf ("strtof() fine for cnt == %d\n", cnt);
|
---|
54 | }
|
---|
55 |
|
---|
56 | for (cnt = 0; cnt < 200; ++cnt)
|
---|
57 | {
|
---|
58 | ssize_t n;
|
---|
59 | double f;
|
---|
60 |
|
---|
61 | n = sprintf (buf, "%d", cnt);
|
---|
62 | memset (buf + n, '0', cnt);
|
---|
63 | sprintf (buf + n + cnt, ".000e-%d", cnt);
|
---|
64 | f = strtod (buf, NULL);
|
---|
65 |
|
---|
66 | if (f != (double) cnt)
|
---|
67 | {
|
---|
68 | printf ("strtod(\"%s\") failed for cnt == %d (%g instead of %g)\n",
|
---|
69 | buf, cnt, f, (double) cnt);
|
---|
70 | result = 1;
|
---|
71 | }
|
---|
72 | else
|
---|
73 | printf ("strtod() fine for cnt == %d\n", cnt);
|
---|
74 | }
|
---|
75 |
|
---|
76 | for (cnt = 0; cnt < 200; ++cnt)
|
---|
77 | {
|
---|
78 | ssize_t n;
|
---|
79 | long double f;
|
---|
80 |
|
---|
81 | n = sprintf (buf, "%d", cnt);
|
---|
82 | memset (buf + n, '0', cnt);
|
---|
83 | sprintf (buf + n + cnt, ".000e-%d", cnt);
|
---|
84 | f = strtold (buf, NULL);
|
---|
85 |
|
---|
86 | if (f != (long double) cnt)
|
---|
87 | {
|
---|
88 | printf ("strtold(\"%s\") failed for cnt == %d (%Lg instead of %Lg)\n",
|
---|
89 | buf, cnt, f, (long double) cnt);
|
---|
90 | result = 1;
|
---|
91 | }
|
---|
92 | else
|
---|
93 | printf ("strtold() fine for cnt == %d\n", cnt);
|
---|
94 | }
|
---|
95 |
|
---|
96 | return result;
|
---|
97 | }
|
---|