(root)/
glibc-2.38/
stdio-common/
bug16.c
       1  #include <array_length.h>
       2  #include <stdio.h>
       3  #include <string.h>
       4  
       5  struct
       6  {
       7    long double val;
       8    const char str[4][7];
       9  } tests[] =
      10  {
      11    { 0x0.FFFFp+0L, { "0X1P+0", "0X2P-1", "0X4P-2", "0X8P-3" } },
      12    { 0x0.FFFFp+1L, { "0X1P+1", "0X2P+0", "0X4P-1", "0X8P-2" } },
      13    { 0x0.FFFFp+2L, { "0X1P+2", "0X2P+1", "0X4P+0", "0X8P-1" } },
      14    { 0x0.FFFFp+3L, { "0X1P+3", "0X2P+2", "0X4P+1", "0X8P+0" } }
      15  };
      16  
      17  static int
      18  do_test (void)
      19  {
      20    char buf[100];
      21    int ret = 0;
      22  
      23    for (size_t i = 0; i < array_length (tests); ++i)
      24      {
      25        snprintf (buf, sizeof (buf), "%.0LA", tests[i].val);
      26  
      27        size_t j;
      28        for (j = 0; j < 4; ++j)
      29  	if (strcmp (buf, tests[i].str[j]) == 0)
      30  	  break;
      31  
      32        if (j == 4)
      33  	{
      34  	  printf ("%zd: got \"%s\", expected \"%s\" or equivalent\n",
      35  		  i, buf, tests[i].str[0]);
      36  	  ret = 1;
      37  	}
      38      }
      39  
      40    return ret;
      41  }
      42  
      43  #define TEST_FUNCTION do_test ()
      44  #include "../test-skeleton.c"