file klio_listio.c was initially added on branch fedora-branch.
[glibc/history.git] / stdlib / bug-strtod.c
blob502dfa0f7b60ba2236039d82942b8a2ce7b06f33
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.
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.
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.
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. */
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <string.h>
26 int
27 main (void)
29 char buf[300];
30 int cnt;
31 int result = 0;
33 for (cnt = 0; cnt < 200; ++cnt)
35 ssize_t n;
36 float f;
38 n = sprintf (buf, "%d", cnt);
39 memset (buf + n, '0', cnt);
40 sprintf (buf + n + cnt, ".000e-%d", cnt);
41 f = strtof (buf, NULL);
43 if (f != (float) cnt)
45 printf ("strtof(\"%s\") failed for cnt == %d (%g instead of %g)\n",
46 buf, cnt, f, (float) cnt);
47 result = 1;
49 else
50 printf ("strtof() fine for cnt == %d\n", cnt);
53 for (cnt = 0; cnt < 200; ++cnt)
55 ssize_t n;
56 double f;
58 n = sprintf (buf, "%d", cnt);
59 memset (buf + n, '0', cnt);
60 sprintf (buf + n + cnt, ".000e-%d", cnt);
61 f = strtod (buf, NULL);
63 if (f != (double) cnt)
65 printf ("strtod(\"%s\") failed for cnt == %d (%g instead of %g)\n",
66 buf, cnt, f, (double) cnt);
67 result = 1;
69 else
70 printf ("strtod() fine for cnt == %d\n", cnt);
73 for (cnt = 0; cnt < 200; ++cnt)
75 ssize_t n;
76 long double f;
78 n = sprintf (buf, "%d", cnt);
79 memset (buf + n, '0', cnt);
80 sprintf (buf + n + cnt, ".000e-%d", cnt);
81 f = strtold (buf, NULL);
83 if (f != (long double) cnt)
85 printf ("strtold(\"%s\") failed for cnt == %d (%Lg instead of %Lg)\n",
86 buf, cnt, f, (long double) cnt);
87 result = 1;
89 else
90 printf ("strtold() fine for cnt == %d\n", cnt);
93 return result;