2 dnl Copyright (C) 2010-2018 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_EXPL],
9 AC_REQUIRE([gl_MATH_H_DEFAULTS])
10 AC_REQUIRE([gl_LONG_DOUBLE_VS_DOUBLE])
11 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
13 dnl Persuade glibc <math.h> to declare expl().
14 AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
17 AC_CACHE_CHECK([whether expl() can be used without linking with libm],
18 [gl_cv_func_expl_no_libm],
22 [[#ifndef __NO_MATH_INLINES
23 # define __NO_MATH_INLINES 1 /* for glibc */
26 long double (*funcptr) (long double) = expl;
28 [[return funcptr (x) > 1.5
29 || expl (x) > 1.5;]])],
30 [gl_cv_func_expl_no_libm=yes],
31 [gl_cv_func_expl_no_libm=no])
33 if test $gl_cv_func_expl_no_libm = no; then
34 AC_CACHE_CHECK([whether expl() can be used with libm],
35 [gl_cv_func_expl_in_libm],
41 [[#ifndef __NO_MATH_INLINES
42 # define __NO_MATH_INLINES 1 /* for glibc */
45 long double (*funcptr) (long double) = expl;
47 [[return funcptr (x) > 1.5
48 || expl (x) > 1.5;]])],
49 [gl_cv_func_expl_in_libm=yes],
50 [gl_cv_func_expl_in_libm=no])
53 if test $gl_cv_func_expl_in_libm = yes; then
57 dnl On Haiku 2017 the system's native expl() is just a stub: it returns 0.0
58 dnl and prints "__expl not implemented" for all arguments.
59 dnl On OpenBSD 5.4 the system's native expl() is buggy:
60 dnl it returns 'nan' for small values. Test for this anomaly.
61 if test $gl_cv_func_expl_no_libm = yes \
62 || test $gl_cv_func_expl_in_libm = yes; then
63 AC_CACHE_CHECK([whether expl() breaks with small values],
64 [gl_cv_func_expl_buggy],
69 [[#include <math.h>]],
70 [[volatile long double x1 = -1.0;
71 volatile long double x2 = -0.8;
72 volatile long double x3 = -0.4;
73 return expl(x1) == 0.0 || isnan(expl(x1))
74 || isnan(expl(x2)) || isnan(expl(x3));
77 [gl_cv_func_expl_buggy=no], [gl_cv_func_expl_buggy=yes],
80 gl_cv_func_expl_buggy="guessing yes" ;;
81 # Guess no on native Windows.
82 mingw*) gl_cv_func_expl_buggy="guessing no" ;;
83 *) gl_cv_func_expl_buggy="guessing no" ;;
88 case "$gl_cv_func_expl_buggy" in
90 gl_cv_func_expl_in_libm=no
91 gl_cv_func_expl_no_libm=no ;;
94 if test $gl_cv_func_expl_no_libm = yes \
95 || test $gl_cv_func_expl_in_libm = yes; then
96 dnl Also check whether it's declared.
97 dnl Mac OS X 10.3 has expl() in libc but doesn't declare it in <math.h>.
98 AC_CHECK_DECL([expl], , [HAVE_DECL_EXPL=0], [[#include <math.h>]])
102 dnl Find libraries needed to link lib/expl.c.
103 if test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 1; then
104 AC_REQUIRE([gl_FUNC_EXP])
105 EXPL_LIBM="$EXP_LIBM"
107 AC_REQUIRE([gl_FUNC_ISNANL])
108 AC_REQUIRE([gl_FUNC_ROUNDL])
109 AC_REQUIRE([gl_FUNC_LDEXPL])
111 dnl Append $ISNANL_LIBM to EXPL_LIBM, avoiding gratuitous duplicates.
112 case " $EXPL_LIBM " in
113 *" $ISNANL_LIBM "*) ;;
114 *) EXPL_LIBM="$EXPL_LIBM $ISNANL_LIBM" ;;
116 dnl Append $ROUNDL_LIBM to EXPL_LIBM, avoiding gratuitous duplicates.
117 case " $EXPL_LIBM " in
118 *" $ROUNDL_LIBM "*) ;;
119 *) EXPL_LIBM="$EXPL_LIBM $ROUNDL_LIBM" ;;
121 dnl Append $LDEXPL_LIBM to EXPL_LIBM, avoiding gratuitous duplicates.
122 case " $EXPL_LIBM " in
123 *" $LDEXPL_LIBM "*) ;;
124 *) EXPL_LIBM="$EXPL_LIBM $LDEXPL_LIBM" ;;
128 AC_SUBST([EXPL_LIBM])