Back to index

glibc  2.9
bug-strtod2.c
Go to the documentation of this file.
00001 #include <locale.h>
00002 #include <math.h>
00003 #include <stdio.h>
00004 #include <stdlib.h>
00005 
00006 static const char *tests[] =
00007   {
00008     "inf", "Inf", "iNf", "inF", "INf", "iNF", "INF", "InF",
00009     "infinity", "Infinity", "InfInity", "INFINITY"
00010   };
00011 #define ntests (sizeof (tests) / sizeof (tests[0]))
00012 
00013 static int
00014 do_test (void)
00015 {
00016   /* The Turkish locale is notorious because tolower() maps 'I' to the
00017      dotless lowercase 'i' and toupper() maps 'i' to an 'I' with a dot
00018      above.  */
00019   if (setlocale (LC_ALL, "tr_TR.UTF-8") == NULL)
00020     {
00021       puts ("cannot set locale");
00022       return 0;
00023     }
00024 
00025   int res = 0;
00026   for (int i = 0; i < ntests; ++i)
00027     {
00028       char *endp;
00029       double d = strtod (tests[i], &endp);
00030       if (*endp != '\0')
00031        {
00032          printf ("did not consume all of '%s'\n", tests[i]);
00033          res = 1;
00034        }
00035       if (!isinf (d))
00036        {
00037          printf ("'%s' does not pass isinf\n", tests[i]);
00038          res = 1;
00039        }
00040     }
00041 
00042   return res;
00043 }
00044 
00045 #define TEST_FUNCTION do_test ()
00046 #include "../test-skeleton.c"