blob: a1f037cdc8d611b1dabf74cbfad7b36649f0ccce [file] [log] [blame]
lh9ed821d2023-04-07 01:36:19 -07001#include <locale.h>
2#include <math.h>
3#include <stdio.h>
4#include <stdlib.h>
5
6static const char *tests[] =
7 {
8 "inf", "Inf", "iNf", "inF", "INf", "iNF", "INF", "InF",
9 "infinity", "Infinity", "InfInity", "INFINITY"
10 };
11#define ntests (sizeof (tests) / sizeof (tests[0]))
12
13static int
14do_test (void)
15{
16 /* The Turkish locale is notorious because tolower() maps 'I' to the
17 dotless lowercase 'i' and toupper() maps 'i' to an 'I' with a dot
18 above. */
19 if (setlocale (LC_ALL, "tr_TR.UTF-8") == NULL)
20 {
21 puts ("cannot set locale");
22 return 0;
23 }
24
25 int res = 0;
26 for (int i = 0; i < ntests; ++i)
27 {
28 char *endp;
29 double d = strtod (tests[i], &endp);
30 if (*endp != '\0')
31 {
32 printf ("did not consume all of '%s'\n", tests[i]);
33 res = 1;
34 }
35 if (!isinf (d))
36 {
37 printf ("'%s' does not pass isinf\n", tests[i]);
38 res = 1;
39 }
40 }
41
42 return res;
43}
44
45#define TEST_FUNCTION do_test ()
46#include "../test-skeleton.c"