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])
16 AC_CACHE_CHECK([whether expm1l() can be used without linking with libm],
17 [gl_cv_func_expm1l_no_libm],
21 [[#ifndef __NO_MATH_INLINES
22 # define __NO_MATH_INLINES 1 /* for glibc */
29 long double expm1l (long double);
30 long double (* volatile funcptr) (long double) = expm1l;
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])
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],
45 [[#ifndef __NO_MATH_INLINES
46 # define __NO_MATH_INLINES 1 /* for glibc */
53 long double expm1l (long double);
54 long double (* volatile funcptr) (long double) = expm1l;
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])
62 if test $gl_cv_func_expm1l_in_libm = yes; then
66 if test $gl_cv_func_expm1l_no_libm = yes \
67 || test $gl_cv_func_expm1l_in_libm = yes; then
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],
78 LIBS="$LIBS $EXPM1L_LIBM"
81 #ifndef __NO_MATH_INLINES
82 # define __NO_MATH_INLINES 1 /* for glibc */
86 /* Override the values of <float.h>, like done in float.in.h. */
87 #if defined __i386__ && (defined __BEOS__ || defined __OpenBSD__)
89 # define LDBL_MANT_DIG 64
91 # define LDBL_MIN_EXP (-16381)
93 # define LDBL_MAX_EXP 16384
95 #if defined __i386__ && (defined __FreeBSD__ || defined __DragonFly__)
97 # define LDBL_MANT_DIG 64
99 # define LDBL_MIN_EXP (-16381)
101 # define LDBL_MAX_EXP 16384
103 #if (defined _ARCH_PPC || defined _POWER) && defined _AIX && (LDBL_MANT_DIG == 106) && defined __GNUC__
105 # define LDBL_MIN_EXP DBL_MIN_EXP
107 #if defined __sgi && (LDBL_MANT_DIG >= 106)
108 # undef LDBL_MANT_DIG
109 # define LDBL_MANT_DIG 106
110 # if defined __GNUC__
112 # define LDBL_MIN_EXP DBL_MIN_EXP
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;
126 /* This test fails on Mac OS X 10.5, NetBSD 8.0. */
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 long double err = (y + (1.0L + y) * z) * TWO_LDBL_MANT_DIG;
138 if (!(err >= -100.0L && err <= 100.0L))
144 [gl_cv_func_expm1l_works=yes],
145 [gl_cv_func_expm1l_works=no],
147 # Guess yes on glibc systems.
148 *-gnu* | gnu*) gl_cv_func_expm1l_works="guessing yes" ;;
149 # Guess yes on musl systems.
150 *-musl*) gl_cv_func_expm1l_works="guessing yes" ;;
151 # Guess yes on native Windows.
152 mingw*) gl_cv_func_expm1l_works="guessing yes" ;;
153 # If we don't know, obey --enable-cross-guesses.
154 *) gl_cv_func_expm1l_works="$gl_cross_guess_normal" ;;
159 case "$gl_cv_func_expm1l_works" in
161 *) REPLACE_EXPM1L=1 ;;
168 if test $HAVE_EXPM1L = 0 || test $REPLACE_EXPM1L = 1; then
169 dnl Find libraries needed to link lib/expm1l.c.
170 if test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 1; then
171 AC_REQUIRE([gl_FUNC_EXPM1])
172 EXPM1L_LIBM="$EXPM1_LIBM"
174 AC_REQUIRE([gl_FUNC_ISNANL])
175 AC_REQUIRE([gl_FUNC_EXPL])
176 AC_REQUIRE([gl_FUNC_ROUNDL])
177 AC_REQUIRE([gl_FUNC_LDEXPL])
179 dnl Append $ISNANL_LIBM to EXPM1L_LIBM, avoiding gratuitous duplicates.
180 case " $EXPM1L_LIBM " in
181 *" $ISNANL_LIBM "*) ;;
182 *) EXPM1L_LIBM="$EXPM1L_LIBM $ISNANL_LIBM" ;;
184 dnl Append $EXPL_LIBM to EXPM1L_LIBM, avoiding gratuitous duplicates.
185 case " $EXPM1L_LIBM " in
187 *) EXPM1L_LIBM="$EXPM1L_LIBM $EXPL_LIBM" ;;
189 dnl Append $ROUNDL_LIBM to EXPM1L_LIBM, avoiding gratuitous duplicates.
190 case " $EXPM1L_LIBM " in
191 *" $ROUNDL_LIBM "*) ;;
192 *) EXPM1L_LIBM="$EXPM1L_LIBM $ROUNDL_LIBM" ;;
194 dnl Append $LDEXPL_LIBM to EXPM1L_LIBM, avoiding gratuitous duplicates.
195 case " $EXPM1L_LIBM " in
196 *" $LDEXPL_LIBM "*) ;;
197 *) EXPM1L_LIBM="$EXPM1L_LIBM $LDEXPL_LIBM" ;;
201 AC_SUBST([EXPM1L_LIBM])