X-Git-Url: https://erislabs.net/gitweb/?a=blobdiff_plain;ds=sidebyside;f=m4%2Fmathfunc.m4;h=67b601fe424c7f64bfd5991812c1a777187314b5;hb=53a617f5e118ec5642daa3da45fcef0bf5593b12;hp=d09aacaa328c45f61e1ce797ae3a68e599ae8723;hpb=a5b5500500ba4d6aaa9a1b3bb214f6917dc1ac3c;p=gnulib.git diff --git a/m4/mathfunc.m4 b/m4/mathfunc.m4 index d09aacaa3..67b601fe4 100644 --- a/m4/mathfunc.m4 +++ b/m4/mathfunc.m4 @@ -1,11 +1,11 @@ -# mathfunc.m4 serial 3 -dnl Copyright (C) 2010 Free Software Foundation, Inc. +# mathfunc.m4 serial 11 +dnl Copyright (C) 2010-2013 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, dnl with or without modifications, as long as this notice is preserved. -# gl_MATHFUNC(FUNC, RETTYPE, PARAMTYPES) -# -------------------------------------------------- +# gl_MATHFUNC(FUNC, RETTYPE, PARAMTYPES [, INCLUDES] [, EXTRA-CODE]) +# ------------------------------------------------------------------ # tests whether the function FUNC is available in libc or libm. # RETTYPE is the return type. PARAMTYPES is a parameter list, with parentheses. # It sets FUNC_LIBM to empty or "-lm" accordingly. @@ -13,23 +13,62 @@ dnl with or without modifications, as long as this notice is preserved. AC_DEFUN([gl_MATHFUNC], [ dnl We need the RETTYPE and PARAMTYPES in order to force linking with the - dnl function. With gcc >= 4.3 on glibc/x86_64, calls to the 'fabs' function - dnl are inlined by the compiler, therefore linking of these calls does not - dnl require -lm, but taking the function pointer of 'fabs' does. + dnl function. + dnl 1) With gcc >= 4.3 on glibc/x86_64, calls to the 'fabs' function + dnl are inlined by the compiler, therefore linking of these calls does + dnl not require -lm, but taking the function pointer of 'fabs' does. + dnl 2) On MSVC 9, many math functions exist only as macros with arguments, + dnl whereas the function pointer is undefined. + dnl On the other hand, taking just the function pointer is not enough. + dnl 1) On AIX 7.1, when 'long double' is 128 bit large ("xlc -qldbl128" or + dnl "xlc -qlongdouble" or "gcc -mlong-double-128") many math functions + dnl exist as macros with arguments, that may reference libm or even + dnl completely undefined functions such as __rint128. + dnl 2) In AIX 7.1 with gcc 4.2, when optimization is turned on, calls to + dnl rint() with simple arguments are turned into rintf() calls by the + dnl compiler. But while rint() is resides in libc, rintf() is in libm. m4_pushdef([func], [$1]) - m4_pushdef([FUNC], [translit([$1],[abcdefghijklmnopqrstuvwxyz], - [ABCDEFGHIJKLMNOPQRSTUVWXYZ])]) + m4_pushdef([FUNC], [m4_translit([$1],[abcdefghijklmnopqrstuvwxyz], + [ABCDEFGHIJKLMNOPQRSTUVWXYZ])]) + m4_pushdef([ARGS], [m4_bpatsubst( + [m4_bpatsubst( + [m4_bpatsubst( + [m4_bpatsubst( + [m4_bpatsubst( + [m4_bpatsubst( + [m4_bpatsubst( + [m4_bpatsubst( + [m4_bpatsubst( + [$3], + [int \*], [&i_ret])], + [float \*], [&f_ret])], + [double \*], [&d_ret])], + [long double \*], [&l_ret])], + [int], [2])], + [float], [1.618034f])], + [long double], [1.618033988749894848L])], + [double], [1.6180339887])], + [void], [])]) FUNC[]_LIBM= AC_CACHE_CHECK([whether func() can be used without linking with libm], [gl_cv_func_]func[_no_libm], [ AC_LINK_IFELSE( - [AC_LANG_PROGRAM([[#ifndef __NO_MATH_INLINES - # define __NO_MATH_INLINES 1 /* for glibc */ - #endif - #include - $2 (*funcptr) $3 = ]func[;]], - [[return 0;]])], + [AC_LANG_PROGRAM( + [[#ifndef __NO_MATH_INLINES + # define __NO_MATH_INLINES 1 /* for glibc */ + #endif + #include + $4 + $2 (*funcptr) $3 = ]func[; + int i_ret; + float f_ret; + double d_ret; + long double l_ret;]], + [[$2 y = funcptr ]ARGS[ + ]func[ ]ARGS[; + $5 + return y < 0.3 || y > 1.7; + ]])], [gl_cv_func_]func[_no_libm=yes], [gl_cv_func_]func[_no_libm=no]) ]) @@ -40,12 +79,21 @@ AC_DEFUN([gl_MATHFUNC], save_LIBS="$LIBS" LIBS="$LIBS -lm" AC_LINK_IFELSE( - [AC_LANG_PROGRAM([[#ifndef __NO_MATH_INLINES - # define __NO_MATH_INLINES 1 /* for glibc */ - #endif - #include - $2 (*funcptr) $3 = ]func[;]], - [[return 0;]])], + [AC_LANG_PROGRAM( + [[#ifndef __NO_MATH_INLINES + # define __NO_MATH_INLINES 1 /* for glibc */ + #endif + #include + $4 + $2 (*funcptr) $3 = ]func[; + int i_ret; + float f_ret; + double d_ret; + long double l_ret;]], + [[$2 y = funcptr ]ARGS[ + ]func[ ]ARGS[; + $5 + return y < 0.3 || y > 1.7; + ]])], [gl_cv_func_]func[_in_libm=yes], [gl_cv_func_]func[_in_libm=no]) LIBS="$save_LIBS" @@ -55,6 +103,7 @@ AC_DEFUN([gl_MATHFUNC], fi fi AC_SUBST(FUNC[_LIBM]) + m4_popdef([ARGS]) m4_popdef([FUNC]) m4_popdef([func]) ]) @@ -64,15 +113,15 @@ AC_DEFUN([gl_MATHFUNC], # tests whether the function FUNC is available in libc or libm. # It sets FUNC_LIBM to empty or "-lm" accordingly. # FUNC must be one of the following functions, that are present on all systems -# and provided by libm on all systems except MacOS X, BeOS, Haiku: -# acos asin atan atan2 cbrt copysign cos cosh erf erfc exp fmod hypot j0 j1 -# jn lgamma log log10 log1p pow remainder sin sinh sqrt tan tanh y0 y1 yn +# and provided by libm on all systems except Mac OS X, BeOS, Haiku: +# acos asin atan atan2 cbrt cos cosh erf erfc exp fmod hypot j0 j1 jn lgamma +# log log10 log1p pow remainder sin sinh sqrt tan tanh y0 y1 yn AC_DEFUN([gl_COMMON_DOUBLE_MATHFUNC], [ AC_REQUIRE([gl_COMMON_DOUBLE_MATHFUNC_TEST]) - m4_pushdef([FUNC], [translit([$1],[abcdefghijklmnopqrstuvwxyz], - [ABCDEFGHIJKLMNOPQRSTUVWXYZ])]) + m4_pushdef([FUNC], [m4_translit([$1],[abcdefghijklmnopqrstuvwxyz], + [ABCDEFGHIJKLMNOPQRSTUVWXYZ])]) FUNC[]_LIBM="$POW_LIBM" AC_SUBST(FUNC[_LIBM]) m4_popdef([FUNC]) @@ -86,7 +135,6 @@ AC_DEFUN([gl_COMMON_DOUBLE_MATHFUNC_TEST], dnl gl_MATHFUNC([atan], [double], [(double)]) dnl gl_MATHFUNC([atan2], [double], [(double, double)]) dnl gl_MATHFUNC([cbrt], [double], [(double)]) - dnl gl_MATHFUNC([copysign], [double], [(double, double)]) dnl gl_MATHFUNC([cos], [double], [(double)]) dnl gl_MATHFUNC([cosh], [double], [(double)]) dnl gl_MATHFUNC([erf], [double], [(double)])