1 /* Copyright (C) 1991, 1996, 1997, 1998 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public License as
6 published by the Free Software Foundation; either version 2 of the
7 License, or (at your option) any later version.
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
14 You should have received a copy of the GNU Library General Public
15 License along with the GNU C Library; see the file COPYING.LIB. If not,
16 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 Boston, MA 02111-1307, USA. */
27 const char *str
; /* Convert this. */
28 double expect
; /* To get this. */
29 char left
; /* With this left over. */
30 int err
; /* And this in errno. */
32 static const struct ltest tests
[] =
34 { "12.345", 12.345, '\0', 0 },
35 { "12.345e19", 12.345e19
, '\0', 0 },
36 { "-.1e+9", -.1e+9, '\0', 0 },
37 { ".125", .125, '\0', 0 },
38 { "1e20", 1e20
, '\0', 0 },
39 { "0e-19", 0, '\0', 0 },
40 { "4\00012", 4.0, '\0', 0 },
41 { "5.9e-76", 5.9e-76, '\0', 0 },
45 static void expand (char *dst
, int c
);
46 static int long_dbl (void);
49 main (int argc
, char ** argv
)
52 register const struct ltest
*lt
;
57 for (lt
= tests
; lt
->str
!= NULL
; ++lt
)
62 d
= strtod(lt
->str
, &ep
);
64 printf ("strtod (\"%s\") test %u",
65 lt
->str
, (unsigned int) (lt
- tests
));
66 if (d
== lt
->expect
&& *ep
== lt
->left
&& save_errno
== lt
->err
)
72 printf (" returns %.60g, expected %.60g\n", d
, lt
->expect
);
75 char exp1
[5], exp2
[5];
77 expand (exp2
, lt
->left
);
78 printf (" leaves '%s', expected '%s'\n", exp1
, exp2
);
80 if (save_errno
!= lt
->err
)
81 printf (" errno %d (%s) instead of %d (%s)\n",
82 save_errno
, strerror (save_errno
),
83 lt
->err
, strerror (lt
->err
));
88 sprintf (buf
, "%f", strtod ("-0.0", NULL
));
89 if (strcmp (buf
, "-0.000000") != 0)
91 printf (" strtod (\"-0.0\', NULL) returns \"%s\"\n", buf
);
95 status
|= long_dbl ();
97 exit (status
? EXIT_FAILURE
: EXIT_SUCCESS
);
111 (void) sprintf (dst
, "%#.3o", (unsigned int) c
);
117 /* Regenerate this string using
119 echo '(2^53-1)*2^(1024-53)' | bc | sed 's/\([^\]*\)\\*$/ "\1"/'
122 static const char longestdbl
[] =
123 "17976931348623157081452742373170435679807056752584499659891747680315"
124 "72607800285387605895586327668781715404589535143824642343213268894641"
125 "82768467546703537516986049910576551282076245490090389328944075868508"
126 "45513394230458323690322294816580855933212334827479782620414472316873"
127 "8177180919299881250404026184124858368";
128 double d
= strtod (longestdbl
, NULL
);
130 printf ("strtod (\"%s\", NULL) = %g\n", longestdbl
, d
);
132 if (d
!= 179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368.000000)