3 dnl Copyright (C) 2010-2024 Free Software Foundation, Inc.
4 dnl This file is free software; the Free Software Foundation
5 dnl gives unlimited permission to copy and/or distribute it,
6 dnl with or without modifications, as long as this notice is preserved.
8 AC_DEFUN([gl_FUNC_EXPM1L],
10 AC_REQUIRE([gl_MATH_H_DEFAULTS])
11 AC_REQUIRE([gl_LONG_DOUBLE_VS_DOUBLE])
13 dnl Persuade glibc <math.h> to declare expm1l().
14 AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
17 AC_CACHE_CHECK([whether expm1l() can be used without linking with libm],
18 [gl_cv_func_expm1l_no_libm],
22 [[#ifndef __NO_MATH_INLINES
23 # define __NO_MATH_INLINES 1 /* for glibc */
30 long double expm1l (long double);
31 long double (* volatile funcptr) (long double) = expm1l;
33 [[return funcptr (x) > 0.5
34 || expm1l (x) > 0.5;]])],
35 [gl_cv_func_expm1l_no_libm=yes],
36 [gl_cv_func_expm1l_no_libm=no])
38 if test $gl_cv_func_expm1l_no_libm = no; then
39 AC_CACHE_CHECK([whether expm1l() can be used with libm],
40 [gl_cv_func_expm1l_in_libm],
46 [[#ifndef __NO_MATH_INLINES
47 # define __NO_MATH_INLINES 1 /* for glibc */
54 long double expm1l (long double);
55 long double (* volatile funcptr) (long double) = expm1l;
57 [[return funcptr (x) > 0.5
58 || expm1l (x) > 0.5;]])],
59 [gl_cv_func_expm1l_in_libm=yes],
60 [gl_cv_func_expm1l_in_libm=no])
63 if test $gl_cv_func_expm1l_in_libm = yes; then
67 if test $gl_cv_func_expm1l_no_libm = yes \
68 || test $gl_cv_func_expm1l_in_libm = yes; then
70 dnl Also check whether it's declared.
71 dnl IRIX 6.5 has expm1l() in libm but doesn't declare it in <math.h>.
72 AC_CHECK_DECL([expm1l], , [HAVE_DECL_EXPM1L=0], [[#include <math.h>]])
73 if test $REPLACE_EXPM1L = 0; then
74 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
75 AC_CACHE_CHECK([whether expm1l works],
76 [gl_cv_func_expm1l_works],
79 LIBS="$LIBS $EXPM1L_LIBM"
82 #ifndef __NO_MATH_INLINES
83 # define __NO_MATH_INLINES 1 /* for glibc */
87 /* Override the values of <float.h>, like done in float.in.h. */
88 #if defined __i386__ && (defined __BEOS__ || defined __OpenBSD__)
90 # define LDBL_MANT_DIG 64
92 # define LDBL_MIN_EXP (-16381)
94 # define LDBL_MAX_EXP 16384
96 #if defined __i386__ && (defined __FreeBSD__ || defined __DragonFly__)
98 # define LDBL_MANT_DIG 64
100 # define LDBL_MIN_EXP (-16381)
102 # define LDBL_MAX_EXP 16384
104 #if (defined _ARCH_PPC || defined _POWER) && defined _AIX && (LDBL_MANT_DIG == 106) && defined __GNUC__
106 # define LDBL_MIN_EXP DBL_MIN_EXP
108 #if defined __sgi && (LDBL_MANT_DIG >= 106)
109 # undef LDBL_MANT_DIG
110 # define LDBL_MANT_DIG 106
111 # if defined __GNUC__
113 # define LDBL_MIN_EXP DBL_MIN_EXP
121 long double expm1l (long double);
122 static long double dummy (long double x) { return 0; }
123 int main (int argc, char *argv[])
125 long double (* volatile my_expm1l) (long double) = argc ? expm1l : dummy;
127 /* This test fails on musl 1.2.2/arm64, musl 1.2.2/s390x, Mac OS X 10.5,
128 NetBSD 10.0/x86_64. */
130 const long double TWO_LDBL_MANT_DIG = /* 2^LDBL_MANT_DIG */
131 (long double) (1U << ((LDBL_MANT_DIG - 1) / 5))
132 * (long double) (1U << ((LDBL_MANT_DIG - 1 + 1) / 5))
133 * (long double) (1U << ((LDBL_MANT_DIG - 1 + 2) / 5))
134 * (long double) (1U << ((LDBL_MANT_DIG - 1 + 3) / 5))
135 * (long double) (1U << ((LDBL_MANT_DIG - 1 + 4) / 5));
136 long double x = 11.358L;
137 long double y = my_expm1l (x);
138 long double z = my_expm1l (- x);
139 volatile long double t = (1.0L + y) * z;
140 long double err = (y + t) * TWO_LDBL_MANT_DIG;
141 if (!(err >= -100.0L && err <= 100.0L))
144 /* This test fails on NetBSD 10.0/i386. */
148 volatile long double y;
149 for (i = -1, x = 0.5L; i > LDBL_MIN_EXP; i--, x *= 0.5L)
151 /* Here i = LDBL_MIN_EXP, x = 2^LDBL_MIN_EXP. */
159 [gl_cv_func_expm1l_works=yes],
160 [gl_cv_func_expm1l_works=no],
162 # Guess yes on glibc systems.
163 *-gnu* | gnu*) gl_cv_func_expm1l_works="guessing yes" ;;
164 # Guess no on musl systems.
165 *-musl* | midipix*) gl_cv_func_expm1l_works="guessing no" ;;
166 # Guess no on NetBSD.
167 netbsd*) gl_cv_func_expm1l_works="guessing no" ;;
168 # Guess yes on native Windows.
169 mingw* | windows*) gl_cv_func_expm1l_works="guessing yes" ;;
170 # If we don't know, obey --enable-cross-guesses.
171 *) gl_cv_func_expm1l_works="$gl_cross_guess_normal" ;;
176 case "$gl_cv_func_expm1l_works" in
178 *) REPLACE_EXPM1L=1 ;;
185 if test $HAVE_EXPM1L = 0 || test $REPLACE_EXPM1L = 1; then
186 dnl Find libraries needed to link lib/expm1l.c.
187 if test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 1; then
188 AC_REQUIRE([gl_FUNC_EXPM1])
189 EXPM1L_LIBM="$EXPM1_LIBM"
191 AC_REQUIRE([gl_FUNC_ISNANL])
192 AC_REQUIRE([gl_FUNC_EXPL])
193 AC_REQUIRE([gl_FUNC_ROUNDL])
194 AC_REQUIRE([gl_FUNC_LDEXPL])
196 dnl Append $ISNANL_LIBM to EXPM1L_LIBM, avoiding gratuitous duplicates.
197 case " $EXPM1L_LIBM " in
198 *" $ISNANL_LIBM "*) ;;
199 *) EXPM1L_LIBM="$EXPM1L_LIBM $ISNANL_LIBM" ;;
201 dnl Append $EXPL_LIBM to EXPM1L_LIBM, avoiding gratuitous duplicates.
202 case " $EXPM1L_LIBM " in
204 *) EXPM1L_LIBM="$EXPM1L_LIBM $EXPL_LIBM" ;;
206 dnl Append $ROUNDL_LIBM to EXPM1L_LIBM, avoiding gratuitous duplicates.
207 case " $EXPM1L_LIBM " in
208 *" $ROUNDL_LIBM "*) ;;
209 *) EXPM1L_LIBM="$EXPM1L_LIBM $ROUNDL_LIBM" ;;
211 dnl Append $LDEXPL_LIBM to EXPM1L_LIBM, avoiding gratuitous duplicates.
212 case " $EXPM1L_LIBM " in
213 *" $LDEXPL_LIBM "*) ;;
214 *) EXPM1L_LIBM="$EXPM1L_LIBM $LDEXPL_LIBM" ;;
218 AC_SUBST([EXPM1L_LIBM])