Merge branch 'master' of ssh://sourceware.org/git/glibc
[glibc.git] / stdlib / tst-atof2.c
blob74dac87b0de2d49a893feb986acf240b2bca5c4f
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
6 static const struct
8 const char *str;
9 const char *expected;
10 } tests[] =
12 { "1e308", "1e+308" },
13 { "100000000e300", "1e+308" },
14 { "0x1p1023", "8.98847e+307" },
15 { "0x1000p1011", "8.98847e+307" },
16 { "0x1p1020", "1.12356e+307" },
17 { "0x0.00001p1040", "1.12356e+307" },
18 { "1e-307", "1e-307" },
19 { "0.000001e-301", "1e-307" },
20 { "0.0000001e-300", "1e-307" },
21 { "0.00000001e-299", "1e-307" },
22 { "1000000e-313", "1e-307" },
23 { "10000000e-314", "1e-307" },
24 { "100000000e-315", "1e-307" },
25 { "0x1p-1021", "4.45015e-308" },
26 { "0x1000p-1033", "4.45015e-308" },
27 { "0x10000p-1037", "4.45015e-308" },
28 { "0x0.001p-1009", "4.45015e-308" },
29 { "0x0.0001p-1005", "4.45015e-308" },
31 #define NTESTS (sizeof (tests) / sizeof (tests[0]))
34 static int
35 do_test (void)
37 int status = 0;
39 for (int i = 0; i < NTESTS; ++i)
41 char buf[100];
42 snprintf (buf, sizeof (buf), "%g", atof (tests[i].str));
43 if (strcmp (buf, tests[i].expected) != 0)
45 printf ("%d: got \"%s\", expected \"%s\"\n",
46 i, buf, tests[i].expected);
47 status = 1;
51 return status;
54 #define TEST_FUNCTION do_test ()
55 #include "../test-skeleton.c"