(root)/
glibc-2.38/
stdlib/
tst-atof2.c
       1  #include <stdio.h>
       2  #include <stdlib.h>
       3  #include <string.h>
       4  
       5  
       6  static const struct
       7  {
       8    const char *str;
       9    const char *expected;
      10  } tests[] =
      11    {
      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" },
      30    };
      31  #define NTESTS (sizeof (tests) / sizeof (tests[0]))
      32  
      33  
      34  static int
      35  do_test (void)
      36  {
      37    int status = 0;
      38  
      39    for (int i = 0; i < NTESTS; ++i)
      40      {
      41        char buf[100];
      42        snprintf (buf, sizeof (buf), "%g", atof (tests[i].str));
      43        if (strcmp (buf, tests[i].expected) != 0)
      44  	{
      45  	  printf ("%d: got \"%s\", expected \"%s\"\n",
      46  		  i, buf, tests[i].expected);
      47  	  status = 1;
      48  	}
      49      }
      50  
      51    return status;
      52  }
      53  
      54  #define TEST_FUNCTION do_test ()
      55  #include "../test-skeleton.c"