Back to index

glibc  2.9
tst-atof2.c
Go to the documentation of this file.
00001 #include <stdio.h>
00002 #include <stdlib.h>
00003 #include <string.h>
00004 
00005 
00006 static const struct
00007 {
00008   const char *str;
00009   const char *expected;
00010 } tests[] =
00011   {
00012     { "1e308", "1e+308" },
00013     { "100000000e300", "1e+308" },
00014     { "0x1p1023", "8.98847e+307" },
00015     { "0x1000p1011", "8.98847e+307" },
00016     { "0x1p1020", "1.12356e+307" },
00017     { "0x0.00001p1040", "1.12356e+307" },
00018     { "1e-307", "1e-307" },
00019     { "0.000001e-301", "1e-307" },
00020     { "0.0000001e-300", "1e-307" },
00021     { "0.00000001e-299", "1e-307" },
00022     { "1000000e-313", "1e-307" },
00023     { "10000000e-314", "1e-307" },
00024     { "100000000e-315", "1e-307" },
00025     { "0x1p-1021", "4.45015e-308" },
00026     { "0x1000p-1033", "4.45015e-308" },
00027     { "0x10000p-1037", "4.45015e-308" },
00028     { "0x0.001p-1009", "4.45015e-308" },
00029     { "0x0.0001p-1005", "4.45015e-308" },
00030   };
00031 #define NTESTS (sizeof (tests) / sizeof (tests[0]))
00032 
00033 
00034 static int
00035 do_test (void)
00036 {
00037   int status = 0;
00038 
00039   for (int i = 0; i < NTESTS; ++i)
00040     {
00041       char buf[100];
00042       snprintf (buf, sizeof (buf), "%g", atof (tests[i].str));
00043       if (strcmp (buf, tests[i].expected) != 0)
00044        {
00045          printf ("%d: got \"%s\", expected \"%s\"\n",
00046                 i, buf, tests[i].expected);
00047          status = 1;
00048        }
00049     }
00050 
00051   return status;
00052 }
00053 
00054 #define TEST_FUNCTION do_test ()
00055 #include "../test-skeleton.c"