expm1l: Fix configure test result with GCC 10 on powerpc64le.
[gnulib.git] / m4 / expm1l.m4
blob8fe31b574bd94f6efb03c3e6ab5a8470dbf6036c
1 # expm1l.m4 serial 8
2 dnl Copyright (C) 2010-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_EXPM1L],
9   AC_REQUIRE([gl_MATH_H_DEFAULTS])
10   AC_REQUIRE([gl_LONG_DOUBLE_VS_DOUBLE])
12   dnl Persuade glibc <math.h> to declare expm1l().
13   AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
15   EXPM1L_LIBM=
16   AC_CACHE_CHECK([whether expm1l() can be used without linking with libm],
17     [gl_cv_func_expm1l_no_libm],
18     [
19       AC_LINK_IFELSE(
20         [AC_LANG_PROGRAM(
21            [[#ifndef __NO_MATH_INLINES
22              # define __NO_MATH_INLINES 1 /* for glibc */
23              #endif
24              #include <math.h>
25              extern
26              #ifdef __cplusplus
27              "C"
28              #endif
29              long double expm1l (long double);
30              long double (* volatile funcptr) (long double) = expm1l;
31              long double x;]],
32            [[return funcptr (x) > 0.5
33                     || expm1l (x) > 0.5;]])],
34         [gl_cv_func_expm1l_no_libm=yes],
35         [gl_cv_func_expm1l_no_libm=no])
36     ])
37   if test $gl_cv_func_expm1l_no_libm = no; then
38     AC_CACHE_CHECK([whether expm1l() can be used with libm],
39       [gl_cv_func_expm1l_in_libm],
40       [
41         save_LIBS="$LIBS"
42         LIBS="$LIBS -lm"
43         AC_LINK_IFELSE(
44           [AC_LANG_PROGRAM(
45              [[#ifndef __NO_MATH_INLINES
46                # define __NO_MATH_INLINES 1 /* for glibc */
47                #endif
48                #include <math.h>
49                extern
50                #ifdef __cplusplus
51                "C"
52                #endif
53                long double expm1l (long double);
54                long double (* volatile funcptr) (long double) = expm1l;
55                long double x;]],
56              [[return funcptr (x) > 0.5
57                       || expm1l (x) > 0.5;]])],
58           [gl_cv_func_expm1l_in_libm=yes],
59           [gl_cv_func_expm1l_in_libm=no])
60         LIBS="$save_LIBS"
61       ])
62     if test $gl_cv_func_expm1l_in_libm = yes; then
63       EXPM1L_LIBM=-lm
64     fi
65   fi
66   if test $gl_cv_func_expm1l_no_libm = yes \
67      || test $gl_cv_func_expm1l_in_libm = yes; then
68     HAVE_EXPM1L=1
69     dnl Also check whether it's declared.
70     dnl IRIX 6.5 has expm1l() in libm but doesn't declare it in <math.h>.
71     AC_CHECK_DECL([expm1l], , [HAVE_DECL_EXPM1L=0], [[#include <math.h>]])
72     if test $REPLACE_EXPM1L = 0; then
73       AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
74       AC_CACHE_CHECK([whether expm1l works],
75         [gl_cv_func_expm1l_works],
76         [
77           save_LIBS="$LIBS"
78           LIBS="$LIBS $EXPM1L_LIBM"
79           AC_RUN_IFELSE(
80             [AC_LANG_SOURCE([[
81 #ifndef __NO_MATH_INLINES
82 # define __NO_MATH_INLINES 1 /* for glibc */
83 #endif
84 #include <float.h>
85 #include <math.h>
86 /* Override the values of <float.h>, like done in float.in.h.  */
87 #if defined __i386__ && (defined __BEOS__ || defined __OpenBSD__)
88 # undef LDBL_MANT_DIG
89 # define LDBL_MANT_DIG   64
90 # undef LDBL_MIN_EXP
91 # define LDBL_MIN_EXP    (-16381)
92 # undef LDBL_MAX_EXP
93 # define LDBL_MAX_EXP    16384
94 #endif
95 #if defined __i386__ && (defined __FreeBSD__ || defined __DragonFly__)
96 # undef LDBL_MANT_DIG
97 # define LDBL_MANT_DIG   64
98 # undef LDBL_MIN_EXP
99 # define LDBL_MIN_EXP    (-16381)
100 # undef LDBL_MAX_EXP
101 # define LDBL_MAX_EXP    16384
102 #endif
103 #if (defined _ARCH_PPC || defined _POWER) && defined _AIX && (LDBL_MANT_DIG == 106) && defined __GNUC__
104 # undef LDBL_MIN_EXP
105 # define LDBL_MIN_EXP DBL_MIN_EXP
106 #endif
107 #if defined __sgi && (LDBL_MANT_DIG >= 106)
108 # undef LDBL_MANT_DIG
109 # define LDBL_MANT_DIG 106
110 # if defined __GNUC__
111 #  undef LDBL_MIN_EXP
112 #  define LDBL_MIN_EXP DBL_MIN_EXP
113 # endif
114 #endif
115 #undef expm1l
116 extern
117 #ifdef __cplusplus
119 #endif
120 long double expm1l (long double);
121 static long double dummy (long double x) { return 0; }
122 int main (int argc, char *argv[])
124   long double (* volatile my_expm1l) (long double) = argc ? expm1l : dummy;
125   int result = 0;
126   /* This test fails on Mac OS X 10.5, NetBSD 8.0.  */
127   {
128     const long double TWO_LDBL_MANT_DIG = /* 2^LDBL_MANT_DIG */
129       (long double) (1U << ((LDBL_MANT_DIG - 1) / 5))
130       * (long double) (1U << ((LDBL_MANT_DIG - 1 + 1) / 5))
131       * (long double) (1U << ((LDBL_MANT_DIG - 1 + 2) / 5))
132       * (long double) (1U << ((LDBL_MANT_DIG - 1 + 3) / 5))
133       * (long double) (1U << ((LDBL_MANT_DIG - 1 + 4) / 5));
134     long double x = 11.358L;
135     long double y = my_expm1l (x);
136     long double z = my_expm1l (- x);
137     volatile long double t = (1.0L + y) * z;
138     long double err = (y + t) * TWO_LDBL_MANT_DIG;
139     if (!(err >= -100.0L && err <= 100.0L))
140       result |= 1;
141   }
142   return result;
144             ]])],
145             [gl_cv_func_expm1l_works=yes],
146             [gl_cv_func_expm1l_works=no],
147             [case "$host_os" in
148                               # Guess yes on glibc systems.
149                *-gnu* | gnu*) gl_cv_func_expm1l_works="guessing yes" ;;
150                               # Guess yes on musl systems.
151                *-musl*)       gl_cv_func_expm1l_works="guessing yes" ;;
152                               # Guess yes on native Windows.
153                mingw*)        gl_cv_func_expm1l_works="guessing yes" ;;
154                               # If we don't know, obey --enable-cross-guesses.
155                *)             gl_cv_func_expm1l_works="$gl_cross_guess_normal" ;;
156              esac
157             ])
158           LIBS="$save_LIBS"
159         ])
160       case "$gl_cv_func_expm1l_works" in
161         *yes) ;;
162         *) REPLACE_EXPM1L=1 ;;
163       esac
164     fi
165   else
166     HAVE_EXPM1L=0
167     HAVE_DECL_EXPM1L=0
168   fi
169   if test $HAVE_EXPM1L = 0 || test $REPLACE_EXPM1L = 1; then
170     dnl Find libraries needed to link lib/expm1l.c.
171     if test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 1; then
172       AC_REQUIRE([gl_FUNC_EXPM1])
173       EXPM1L_LIBM="$EXPM1_LIBM"
174     else
175       AC_REQUIRE([gl_FUNC_ISNANL])
176       AC_REQUIRE([gl_FUNC_EXPL])
177       AC_REQUIRE([gl_FUNC_ROUNDL])
178       AC_REQUIRE([gl_FUNC_LDEXPL])
179       EXPM1L_LIBM=
180       dnl Append $ISNANL_LIBM to EXPM1L_LIBM, avoiding gratuitous duplicates.
181       case " $EXPM1L_LIBM " in
182         *" $ISNANL_LIBM "*) ;;
183         *) EXPM1L_LIBM="$EXPM1L_LIBM $ISNANL_LIBM" ;;
184       esac
185       dnl Append $EXPL_LIBM to EXPM1L_LIBM, avoiding gratuitous duplicates.
186       case " $EXPM1L_LIBM " in
187         *" $EXPL_LIBM "*) ;;
188         *) EXPM1L_LIBM="$EXPM1L_LIBM $EXPL_LIBM" ;;
189       esac
190       dnl Append $ROUNDL_LIBM to EXPM1L_LIBM, avoiding gratuitous duplicates.
191       case " $EXPM1L_LIBM " in
192         *" $ROUNDL_LIBM "*) ;;
193         *) EXPM1L_LIBM="$EXPM1L_LIBM $ROUNDL_LIBM" ;;
194       esac
195       dnl Append $LDEXPL_LIBM to EXPM1L_LIBM, avoiding gratuitous duplicates.
196       case " $EXPM1L_LIBM " in
197         *" $LDEXPL_LIBM "*) ;;
198         *) EXPM1L_LIBM="$EXPM1L_LIBM $LDEXPL_LIBM" ;;
199       esac
200     fi
201   fi
202   AC_SUBST([EXPM1L_LIBM])