Back to index

glibc  2.9
tst-strtod2.c
Go to the documentation of this file.
00001 #include <stdio.h>
00002 #include <stdlib.h>
00003 
00004 struct test
00005 {
00006   const char *str;
00007   double result;
00008   size_t offset;
00009 } tests[] =
00010 {
00011   { "0xy", 0.0, 1 },
00012   { "0x.y", 0.0, 1 },
00013   { "0x0.y", 0.0, 4 },
00014   { "0x.0y", 0.0, 4 },
00015   { ".y", 0.0, 0 },
00016   { "0.y", 0.0, 2 },
00017   { ".0y", 0.0, 2 }
00018 };
00019 
00020 static int
00021 do_test (void)
00022 {
00023   int status = 0;
00024   for (size_t i = 0; i < sizeof (tests) / sizeof (tests[0]); ++i)
00025     {
00026       char *ep;
00027       double r = strtod (tests[i].str, &ep);
00028       if (r != tests[i].result)
00029        {
00030          printf ("test %zu r = %g, expect %g\n", i, r, tests[i].result);
00031          status = 1;
00032        }
00033       if (ep != tests[i].str + tests[i].offset)
00034        {
00035          printf ("test %zu strtod parsed %tu characters, expected %zu\n",
00036                 i, ep - tests[i].str, tests[i].offset);
00037          status = 1;
00038        }
00039     }
00040   return status;
00041 }
00042 
00043 #define TEST_FUNCTION do_test ()
00044 #include "../test-skeleton.c"