2 dnl Copyright (C) 2010-2020 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_EXPM1],
9 m4_divert_text([DEFAULTS], [gl_expm1_required=plain])
10 AC_REQUIRE([gl_MATH_H_DEFAULTS])
12 dnl Persuade glibc <math.h> to declare expm1().
13 AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
16 AC_CACHE_CHECK([whether expm1() can be used without linking with libm],
17 [gl_cv_func_expm1_no_libm],
21 [[#ifndef __NO_MATH_INLINES
22 # define __NO_MATH_INLINES 1 /* for glibc */
25 double (* volatile funcptr) (double) = expm1;
27 [[return funcptr (x) > 0.5
28 || expm1 (x) > 0.5;]])],
29 [gl_cv_func_expm1_no_libm=yes],
30 [gl_cv_func_expm1_no_libm=no])
32 if test $gl_cv_func_expm1_no_libm = no; then
33 AC_CACHE_CHECK([whether expm1() can be used with libm],
34 [gl_cv_func_expm1_in_libm],
40 [[#ifndef __NO_MATH_INLINES
41 # define __NO_MATH_INLINES 1 /* for glibc */
44 double (* volatile funcptr) (double) = expm1;
46 [[return funcptr (x) > 0.5
47 || expm1 (x) > 0.5;]])],
48 [gl_cv_func_expm1_in_libm=yes],
49 [gl_cv_func_expm1_in_libm=no])
52 if test $gl_cv_func_expm1_in_libm = yes; then
56 if test $gl_cv_func_expm1_no_libm = yes \
57 || test $gl_cv_func_expm1_in_libm = yes; then
59 m4_ifdef([gl_FUNC_EXPM1_IEEE], [
60 if test $gl_expm1_required = ieee && test $REPLACE_EXPM1 = 0; then
61 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
62 AC_CACHE_CHECK([whether expm1 works according to ISO C 99 with IEC 60559],
63 [gl_cv_func_expm1_ieee],
66 LIBS="$LIBS $EXPM1_LIBM"
69 #ifndef __NO_MATH_INLINES
70 # define __NO_MATH_INLINES 1 /* for glibc */
73 ]gl_DOUBLE_MINUS_ZERO_CODE[
74 ]gl_DOUBLE_SIGNBIT_CODE[
75 static double dummy (double x) { return 0; }
76 int main (int argc, char *argv[])
78 double (* volatile my_expm1) (double) = argc ? expm1 : dummy;
79 double y = my_expm1 (minus_zerod);
80 if (!(y == 0.0) || (signbitd (minus_zerod) && !signbitd (y)))
85 [gl_cv_func_expm1_ieee=yes],
86 [gl_cv_func_expm1_ieee=no],
88 # Guess yes on glibc systems.
89 *-gnu* | gnu*) gl_cv_func_expm1_ieee="guessing yes" ;;
90 # Guess yes on musl systems.
91 *-musl*) gl_cv_func_expm1_ieee="guessing yes" ;;
92 # Guess yes on native Windows.
93 mingw*) gl_cv_func_expm1_ieee="guessing yes" ;;
94 # If we don't know, obey --enable-cross-guesses.
95 *) gl_cv_func_expm1_ieee="$gl_cross_guess_normal" ;;
100 case "$gl_cv_func_expm1_ieee" in
102 *) REPLACE_EXPM1=1 ;;
109 if test $HAVE_EXPM1 = 0 || test $REPLACE_EXPM1 = 1; then
110 dnl Find libraries needed to link lib/expm1.c.
111 AC_REQUIRE([gl_FUNC_ISNAND])
112 AC_REQUIRE([gl_FUNC_EXP])
113 AC_REQUIRE([gl_FUNC_ROUND])
114 AC_REQUIRE([gl_FUNC_LDEXP])
116 dnl Append $ISNAND_LIBM to EXPM1_LIBM, avoiding gratuitous duplicates.
117 case " $EXPM1_LIBM " in
118 *" $ISNAND_LIBM "*) ;;
119 *) EXPM1_LIBM="$EXPM1_LIBM $ISNAND_LIBM" ;;
121 dnl Append $EXP_LIBM to EXPM1_LIBM, avoiding gratuitous duplicates.
122 case " $EXPM1_LIBM " in
124 *) EXPM1_LIBM="$EXPM1_LIBM $EXP_LIBM" ;;
126 dnl Append $ROUND_LIBM to EXPM1_LIBM, avoiding gratuitous duplicates.
127 case " $EXPM1_LIBM " in
128 *" $ROUND_LIBM "*) ;;
129 *) EXPM1_LIBM="$EXPM1_LIBM $ROUND_LIBM" ;;
131 dnl Append $LDEXP_LIBM to EXPM1_LIBM, avoiding gratuitous duplicates.
132 case " $EXPM1_LIBM " in
133 *" $LDEXP_LIBM "*) ;;
134 *) EXPM1_LIBM="$EXPM1_LIBM $LDEXP_LIBM" ;;
137 AC_SUBST([EXPM1_LIBM])