(root)/
glibc-2.38/
stdlib/
bug-strtod.c
       1  /* Test to strtod etc for numbers like x000...0000.000e-nn.
       2     This file is part of the GNU C Library.
       3     Copyright (C) 2001-2023 Free Software Foundation, Inc.
       4  
       5     The GNU C Library is free software; you can redistribute it and/or
       6     modify it under the terms of the GNU Lesser General Public
       7     License as published by the Free Software Foundation; either
       8     version 2.1 of the License, or (at your option) any later version.
       9  
      10     The GNU C Library is distributed in the hope that it will be useful,
      11     but WITHOUT ANY WARRANTY; without even the implied warranty of
      12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      13     Lesser General Public License for more details.
      14  
      15     You should have received a copy of the GNU Lesser General Public
      16     License along with the GNU C Library; if not, see
      17     <https://www.gnu.org/licenses/>.  */
      18  
      19  #include <stdio.h>
      20  #include <stdlib.h>
      21  #include <string.h>
      22  
      23  #include "tst-strtod.h"
      24  
      25  #define TEST_STRTOD(FSUF, FTYPE, FTOSTR, LSUF, CSUF)			\
      26  static int								\
      27  test_strto ## FSUF (void)						\
      28  {									\
      29    char buf[300];							\
      30    int cnt;								\
      31    int result = 0;							\
      32  									\
      33    for (cnt = 0; cnt < 200; ++cnt)					\
      34      {									\
      35        ssize_t n;							\
      36        FTYPE f;								\
      37  									\
      38        n = sprintf (buf, "%d", cnt);					\
      39        memset (buf + n, '0', cnt);					\
      40        sprintf (buf + n + cnt, ".000e-%d", cnt);				\
      41        f = strto ## FSUF (buf, NULL);					\
      42  									\
      43        if (f != (FTYPE) cnt)						\
      44  	{								\
      45  	  char fstr[FSTRLENMAX];					\
      46  	  char fcntstr[FSTRLENMAX];					\
      47  	  FTOSTR (fstr, sizeof (fstr), "%g", f);			\
      48  	  FTOSTR (fcntstr, sizeof (fstr), "%g", (FTYPE) cnt); 		\
      49  	  printf ("strto" #FSUF "(\"%s\") "				\
      50  		  "failed for cnt == %d (%s instead of %s)\n",		\
      51  		  buf, cnt, fstr, fcntstr);				\
      52  	  result = 1;							\
      53  	}								\
      54        else								\
      55  	printf ( "strto" #FSUF "() fine for cnt == %d\n", cnt);		\
      56      }									\
      57    return result;							\
      58  }
      59  
      60  GEN_TEST_STRTOD_FOREACH (TEST_STRTOD)
      61  
      62  int
      63  main (void)
      64  {
      65    return STRTOD_TEST_FOREACH (test_strto);
      66  }