source: vendor/glibc-tests/glibc/stdlib/bug-strtod.c

Last change on this file was 2036, checked in by bird, 20 years ago

Initial revision

  • Property cvs2svn:cvs-rev set to 1.1
  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 2.4 KB
Line 
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
25
26int
27main (void)
28{
29 char buf[300];
30 int cnt;
31 int result = 0;
32
33 for (cnt = 0; cnt < 200; ++cnt)
34 {
35 ssize_t n;
36 float f;
37
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);
42
43 if (f != (float) cnt)
44 {
45 printf ("strtof(\"%s\") failed for cnt == %d (%g instead of %g)\n",
46 buf, cnt, f, (float) cnt);
47 result = 1;
48 }
49 else
50 printf ("strtof() fine for cnt == %d\n", cnt);
51 }
52
53 for (cnt = 0; cnt < 200; ++cnt)
54 {
55 ssize_t n;
56 double f;
57
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);
62
63 if (f != (double) cnt)
64 {
65 printf ("strtod(\"%s\") failed for cnt == %d (%g instead of %g)\n",
66 buf, cnt, f, (double) cnt);
67 result = 1;
68 }
69 else
70 printf ("strtod() fine for cnt == %d\n", cnt);
71 }
72
73 for (cnt = 0; cnt < 200; ++cnt)
74 {
75 ssize_t n;
76 long double f;
77
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);
82
83 if (f != (long double) cnt)
84 {
85 printf ("strtold(\"%s\") failed for cnt == %d (%Lg instead of %Lg)\n",
86 buf, cnt, f, (long double) cnt);
87 result = 1;
88 }
89 else
90 printf ("strtold() fine for cnt == %d\n", cnt);
91 }
92
93 return result;
94}
Note: See TracBrowser for help on using the repository browser.