spawn: Use special invocation for <spawn.h> on OS/2 kLIBC.
[gnulib.git] / m4 / strtold.m4
blob8379877d4d7d9e444287289da4aad3550d3602d5
1 # strtold.m4 serial 7
2 dnl Copyright (C) 2002-2003, 2006-2021 Free Software Foundation, Inc.
3 dnl This file is free software; the Free Software Foundation
4 dnl gives unlimited permission to copy and/or distribute it,
5 dnl with or without modifications, as long as this notice is preserved.
7 AC_DEFUN([gl_FUNC_STRTOLD],
9   AC_REQUIRE([gl_STDLIB_H_DEFAULTS])
10   AC_REQUIRE([gl_LONG_DOUBLE_VS_DOUBLE])
11   AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
12   AC_CHECK_FUNCS_ONCE([strtold])
13   if test $ac_cv_func_strtold != yes; then
14     HAVE_STRTOLD=0
15   else
16     AC_CACHE_CHECK([whether strtold obeys POSIX], [gl_cv_func_strtold_works],
17       [AC_RUN_IFELSE([AC_LANG_PROGRAM([[
18 #include <stdlib.h>
19 #include <math.h>
20 #include <errno.h>
21 /* Compare two numbers with ==.
22    This is a separate function because IRIX 6.5 "cc -O" miscompiles an
23    'x == x' test.  */
24 static int
25 numeric_equal (long double x, long double y)
27   return x == y;
29 ]], [[
30   int result = 0;
31   {
32     /* Under Solaris 2.4, strtod returns the wrong value for the
33        terminating character under some conditions.  */
34     const char *string = "NaN";
35     char *term;
36     strtold (string, &term);
37     if (term != string && *(term - 1) == 0)
38       result |= 1;
39   }
40   {
41     /* Older glibc and Cygwin mis-parse "-0x".  */
42     const char *string = "-0x";
43     char *term;
44     long double value = strtold (string, &term);
45     long double zero = 0.0L;
46     if (1.0L / value != -1.0L / zero || term != (string + 2))
47       result |= 2;
48   }
49   {
50     /* IRIX 6.5, mingw do not parse hex floats.  */
51     const char *string = "0XaP+1";
52     char *term;
53     long double value = strtold (string, &term);
54     if (value != 20.0L || term != (string + 6))
55       result |= 4;
56   }
57   {
58     /* IRIX 6.5 does not parse infinities.  HP-UX 11.31/ia64 parses inf,
59        but mistakenly sets errno.  */
60     const char *string = "inf";
61     char *term;
62     long double value;
63     errno = 0;
64     value = strtold (string, &term);
65     if (value != HUGE_VAL || term != (string + 3) || errno)
66       result |= 8;
67   }
68   {
69     /* glibc-2.3.2, IRIX 6.5, mingw, Haiku misparse "nan()".  */
70     const char *string = "nan()";
71     char *term;
72     long double value = strtold (string, &term);
73     if (numeric_equal (value, value) || term != (string + 5))
74       result |= 16;
75   }
76   {
77     /* Mac OS X 10.5, IRIX 6.5 misparse "nan(".  */
78     const char *string = "nan(";
79     char *term;
80     long double value = strtold (string, &term);
81     if (numeric_equal (value, value) || term != (string + 3))
82       result |= 32;
83   }
84   {
85     /* In Cygwin 2.9, strtold does not set errno upon underflow.  */
86     const char *string = "1E-100000";
87     char *term;
88     long double value;
89     errno = 0;
90     value = strtold (string, &term);
91     if (term != (string + 9) || (value == 0.0L && errno != ERANGE))
92       result |= 64;
93   }
94   return result;
95 ]])],
96         [gl_cv_func_strtold_works=yes],
97         [if expr $? '>=' 64 >/dev/null; then
98            gl_cv_func_strtold_works="no (underflow problem)"
99          else
100            gl_cv_func_strtold_works=no
101          fi
102         ],
103         [dnl The last known bugs in glibc strtold(), as of this writing,
104          dnl were fixed in version 2.8
105          AC_EGREP_CPP([Lucky user],
106            [
107 #include <features.h>
108 #ifdef __GNU_LIBRARY__
109  #if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 8) || (__GLIBC__ > 2)) \
110      && !defined __UCLIBC__
111   Lucky user
112  #endif
113 #endif
114            ],
115            [gl_cv_func_strtold_works="guessing yes"],
116            [case "$host_os" in
117                        # Guess yes on musl systems.
118               *-musl*) gl_cv_func_strtold_works="guessing yes" ;;
119                        # Guess 'no (underflow problem)' on Cygwin.
120               cygwin*) gl_cv_func_strtold_works="guessing no (underflow problem)" ;;
121               *)       gl_cv_func_strtold_works="$gl_cross_guess_normal" ;;
122             esac
123            ])
124         ])
125       ])
126     case "$gl_cv_func_strtold_works" in
127       *yes) ;;
128       *)
129         REPLACE_STRTOLD=1
130         case "$gl_cv_func_strtold_works" in
131           *"no (underflow problem)")
132             AC_DEFINE([STRTOLD_HAS_UNDERFLOW_BUG], [1],
133               [Define to 1 if strtold does not set errno upon underflow.])
134             ;;
135         esac
136         ;;
137     esac
138   fi
141 # Prerequisites of lib/strtold.c.
142 AC_DEFUN([gl_PREREQ_STRTOLD], [
143   AC_REQUIRE([gl_CHECK_LDEXPL_NO_LIBM])
144   if test $gl_cv_func_ldexpl_no_libm = yes; then
145     AC_DEFINE([HAVE_LDEXPL_IN_LIBC], [1],
146       [Define if the ldexpl function is available in libc.])
147   fi
148   AC_CHECK_FUNCS([nl_langinfo])