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_EXP2],
9 AC_REQUIRE([gl_MATH_H_DEFAULTS])
11 dnl Persuade glibc <math.h> to declare exp2().
12 AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
15 AC_CACHE_CHECK([whether exp2() can be used without linking with libm],
16 [gl_cv_func_exp2_no_libm],
20 [[#ifndef __NO_MATH_INLINES
21 # define __NO_MATH_INLINES 1 /* for glibc */
29 double (* volatile funcptr) (double) = exp2;
31 [[return funcptr (x) > 1.5
32 || exp2 (x) > 1.5;]])],
33 [gl_cv_func_exp2_no_libm=yes],
34 [gl_cv_func_exp2_no_libm=no])
36 if test $gl_cv_func_exp2_no_libm = no; then
37 AC_CACHE_CHECK([whether exp2() can be used with libm],
38 [gl_cv_func_exp2_in_libm],
44 [[#ifndef __NO_MATH_INLINES
45 # define __NO_MATH_INLINES 1 /* for glibc */
53 double (* volatile funcptr) (double) = exp2;
55 [[return funcptr (x) > 1.5
56 || exp2 (x) > 1.5;]])],
57 [gl_cv_func_exp2_in_libm=yes],
58 [gl_cv_func_exp2_in_libm=no])
61 if test $gl_cv_func_exp2_in_libm = yes; then
65 if test $gl_cv_func_exp2_no_libm = yes \
66 || test $gl_cv_func_exp2_in_libm = yes; then
68 dnl Also check whether it's declared.
69 dnl IRIX 6.5 has exp2() in libm but doesn't declare it in <math.h>.
70 AC_CHECK_DECL([exp2], , [HAVE_DECL_EXP2=0], [[#include <math.h>]])
72 LIBS="$LIBS $EXP2_LIBM"
75 case "$gl_cv_func_exp2_works" in
83 if test $HAVE_EXP2 = 0 || test $REPLACE_EXP2 = 1; then
84 dnl Find libraries needed to link lib/exp2.c.
85 AC_REQUIRE([gl_FUNC_ISNAND])
86 AC_REQUIRE([gl_FUNC_ROUND])
87 AC_REQUIRE([gl_FUNC_LDEXP])
89 dnl Append $ISNAND_LIBM to EXP2_LIBM, avoiding gratuitous duplicates.
90 case " $EXP2_LIBM " in
91 *" $ISNAND_LIBM "*) ;;
92 *) EXP2_LIBM="$EXP2_LIBM $ISNAND_LIBM" ;;
94 dnl Append $ROUND_LIBM to EXP2_LIBM, avoiding gratuitous duplicates.
95 case " $EXP2_LIBM " in
97 *) EXP2_LIBM="$EXP2_LIBM $ROUND_LIBM" ;;
99 dnl Append $LDEXP_LIBM to EXP2_LIBM, avoiding gratuitous duplicates.
100 case " $EXP2_LIBM " in
101 *" $LDEXP_LIBM "*) ;;
102 *) EXP2_LIBM="$EXP2_LIBM $LDEXP_LIBM" ;;
105 AC_SUBST([EXP2_LIBM])
108 dnl Test whether exp2() works.
109 dnl On OpenBSD 4.9, for the argument 0.6, it returns 1.517358639986284397,
110 dnl which has a relative error of 0.1%.
111 AC_DEFUN([gl_FUNC_EXP2_WORKS],
113 AC_REQUIRE([AC_PROG_CC])
114 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
115 AC_CACHE_CHECK([whether exp2 works], [gl_cv_func_exp2_works],
124 double exp2 (double);
136 [gl_cv_func_exp2_works=yes],
137 [gl_cv_func_exp2_works=no],
139 openbsd*) gl_cv_func_exp2_works="guessing no" ;;
140 # Guess yes on native Windows.
141 mingw*) gl_cv_func_exp2_works="guessing yes" ;;
142 *) gl_cv_func_exp2_works="guessing yes" ;;