Update contrib.texi
[glibc.git] / stdlib / bug-strtod.c
blob89d0bcc6e6b15738a1d57a9122349abb952d8972
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-2014 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, see
18 <http://www.gnu.org/licenses/>. */
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <string.h>
25 int
26 main (void)
28 char buf[300];
29 int cnt;
30 int result = 0;
32 for (cnt = 0; cnt < 200; ++cnt)
34 ssize_t n;
35 float f;
37 n = sprintf (buf, "%d", cnt);
38 memset (buf + n, '0', cnt);
39 sprintf (buf + n + cnt, ".000e-%d", cnt);
40 f = strtof (buf, NULL);
42 if (f != (float) cnt)
44 printf ("strtof(\"%s\") failed for cnt == %d (%g instead of %g)\n",
45 buf, cnt, f, (float) cnt);
46 result = 1;
48 else
49 printf ("strtof() fine for cnt == %d\n", cnt);
52 for (cnt = 0; cnt < 200; ++cnt)
54 ssize_t n;
55 double f;
57 n = sprintf (buf, "%d", cnt);
58 memset (buf + n, '0', cnt);
59 sprintf (buf + n + cnt, ".000e-%d", cnt);
60 f = strtod (buf, NULL);
62 if (f != (double) cnt)
64 printf ("strtod(\"%s\") failed for cnt == %d (%g instead of %g)\n",
65 buf, cnt, f, (double) cnt);
66 result = 1;
68 else
69 printf ("strtod() fine for cnt == %d\n", cnt);
72 for (cnt = 0; cnt < 200; ++cnt)
74 ssize_t n;
75 long double f;
77 n = sprintf (buf, "%d", cnt);
78 memset (buf + n, '0', cnt);
79 sprintf (buf + n + cnt, ".000e-%d", cnt);
80 f = strtold (buf, NULL);
82 if (f != (long double) cnt)
84 printf ("strtold(\"%s\") failed for cnt == %d (%Lg instead of %Lg)\n",
85 buf, cnt, f, (long double) cnt);
86 result = 1;
88 else
89 printf ("strtold() fine for cnt == %d\n", cnt);
92 return result;