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 # gl_MATHFUNC(FUNC, RETTYPE, PARAMTYPES [, INCLUDES] [, EXTRA-CODE])
9 # ------------------------------------------------------------------
10 # tests whether the function FUNC is available in libc or libm.
11 # RETTYPE is the return type. PARAMTYPES is a parameter list, with parentheses.
12 # It sets FUNC_LIBM to empty or "-lm" accordingly.
14 AC_DEFUN([gl_MATHFUNC],
16 dnl We need the RETTYPE and PARAMTYPES in order to force linking with the
18 dnl 1) With gcc >= 4.3 on glibc/x86_64, calls to the 'fabs' function
19 dnl are inlined by the compiler, therefore linking of these calls does
20 dnl not require -lm, but taking the function pointer of 'fabs' does.
21 dnl 2) On MSVC 9, many math functions exist only as macros with arguments,
22 dnl whereas the function pointer is undefined.
23 dnl On the other hand, taking just the function pointer is not enough.
24 dnl 1) On AIX 7.1, when 'long double' is 128 bit large ("xlc -qldbl128" or
25 dnl "xlc -qlongdouble" or "gcc -mlong-double-128") many math functions
26 dnl exist as macros with arguments, that may reference libm or even
27 dnl completely undefined functions such as __rint128.
28 dnl 2) In AIX 7.1 with gcc 4.2, when optimization is turned on, calls to
29 dnl rint() with simple arguments are turned into rintf() calls by the
30 dnl compiler. But while rint() is resides in libc, rintf() is in libm.
31 m4_pushdef([func], [$1])
32 m4_pushdef([FUNC], [m4_translit([$1],[abcdefghijklmnopqrstuvwxyz],
33 [ABCDEFGHIJKLMNOPQRSTUVWXYZ])])
34 m4_pushdef([ARGS], [m4_bpatsubst(
48 [fenv_t\( const\)? \*], [&fenv_ret])],
49 [fexcept_t\( const\)? \*], [&fx_ret])],
52 [float\( const\)? \*], [&f_ret])],
53 [double\( const\)? \*], [&d_ret])],
54 [long double\( const\)? \*], [&l_ret])],
58 [float], [1.618034f])],
59 [long double], [1.618033988749894848L])],
60 [double], [1.6180339887])],
63 AC_CACHE_CHECK([whether func() can be used without linking with libm],
64 [gl_cv_func_]func[_no_libm],
68 [[#ifndef __NO_MATH_INLINES
69 # define __NO_MATH_INLINES 1 /* for glibc */
73 $2 (* volatile funcptr) $3 = ]func[;
78 [[$2 y = funcptr ]ARGS[ + ]func[ ]ARGS[;
80 return y < 0.3 || y > 1.7;
82 [gl_cv_func_]func[_no_libm=yes],
83 [gl_cv_func_]func[_no_libm=no])
85 if test $gl_cv_func_[]func[]_no_libm = no; then
86 AC_CACHE_CHECK([whether func() can be used with libm],
87 [gl_cv_func_]func[_in_libm],
93 [[#ifndef __NO_MATH_INLINES
94 # define __NO_MATH_INLINES 1 /* for glibc */
98 $2 (* volatile funcptr) $3 = ]func[;
102 long double l_ret;]],
103 [[$2 y = funcptr ]ARGS[ + ]func[ ]ARGS[;
105 return y < 0.3 || y > 1.7;
107 [gl_cv_func_]func[_in_libm=yes],
108 [gl_cv_func_]func[_in_libm=no])
111 if test $gl_cv_func_[]func[]_in_libm = yes; then
115 AC_SUBST(FUNC[_LIBM])
121 # gl_COMMON_DOUBLE_MATHFUNC(FUNC)
122 # -------------------------------
123 # tests whether the function FUNC is available in libc or libm.
124 # It sets FUNC_LIBM to empty or "-lm" accordingly.
125 # FUNC must be one of the following functions, that are present on all systems
126 # and provided by libm on all systems except Mac OS X, BeOS, Haiku:
127 # acos asin atan atan2 cbrt cos cosh erf erfc exp fmod hypot j0 j1 jn lgamma
128 # log log10 log1p pow remainder sin sinh sqrt tan tanh y0 y1 yn
130 AC_DEFUN([gl_COMMON_DOUBLE_MATHFUNC],
132 AC_REQUIRE([gl_COMMON_DOUBLE_MATHFUNC_TEST])
133 m4_pushdef([FUNC], [m4_translit([$1],[abcdefghijklmnopqrstuvwxyz],
134 [ABCDEFGHIJKLMNOPQRSTUVWXYZ])])
135 FUNC[]_LIBM="$POW_LIBM"
136 AC_SUBST(FUNC[_LIBM])
140 AC_DEFUN([gl_COMMON_DOUBLE_MATHFUNC_TEST],
142 dnl We could use any of the following:
143 dnl gl_MATHFUNC([acos], [double], [(double)])
144 dnl gl_MATHFUNC([asin], [double], [(double)])
145 dnl gl_MATHFUNC([atan], [double], [(double)])
146 dnl gl_MATHFUNC([atan2], [double], [(double, double)])
147 dnl gl_MATHFUNC([cbrt], [double], [(double)])
148 dnl gl_MATHFUNC([cos], [double], [(double)])
149 dnl gl_MATHFUNC([cosh], [double], [(double)])
150 dnl gl_MATHFUNC([erf], [double], [(double)])
151 dnl gl_MATHFUNC([erfc], [double], [(double)])
152 dnl gl_MATHFUNC([exp], [double], [(double)])
153 dnl gl_MATHFUNC([fmod], [double], [(double, double)])
154 dnl gl_MATHFUNC([hypot], [double], [(double, double)])
155 dnl gl_MATHFUNC([j0], [double], [(double)])
156 dnl gl_MATHFUNC([j1], [double], [(double)])
157 dnl gl_MATHFUNC([jn], [double], [(int, double)])
158 dnl gl_MATHFUNC([lgamma], [double], [(double)])
159 dnl gl_MATHFUNC([log], [double], [(double)])
160 dnl gl_MATHFUNC([log10], [double], [(double)])
161 dnl gl_MATHFUNC([log1p], [double], [(double)])
162 dnl gl_MATHFUNC([pow], [double], [(double, double)])
163 dnl gl_MATHFUNC([remainder], [double], [(double, double)])
164 dnl gl_MATHFUNC([sin], [double], [(double)])
165 dnl gl_MATHFUNC([sinh], [double], [(double)])
166 dnl gl_MATHFUNC([sqrt], [double], [(double)])
167 dnl gl_MATHFUNC([tan], [double], [(double)])
168 dnl gl_MATHFUNC([tanh], [double], [(double)])
169 dnl gl_MATHFUNC([y0], [double], [(double)])
170 dnl gl_MATHFUNC([y1], [double], [(double)])
171 dnl gl_MATHFUNC([yn], [double], [(int, double)])
172 gl_MATHFUNC([pow], [double], [(double, double)])