X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=m4%2Fmathfunc.m4;h=d09aacaa328c45f61e1ce797ae3a68e599ae8723;hb=16b34ac99b135d6cd6c8c2cf1e277ee3b867d9ac;hp=8d9d826f206aec587b01250c4b768e6eeacd3b9f;hpb=8b893ddd3707e3ca0703933d9a72eaea356759e5;p=gnulib.git diff --git a/m4/mathfunc.m4 b/m4/mathfunc.m4 index 8d9d826f2..d09aacaa3 100644 --- a/m4/mathfunc.m4 +++ b/m4/mathfunc.m4 @@ -1,15 +1,21 @@ -# mathfunc.m4 serial 1 +# mathfunc.m4 serial 3 dnl Copyright (C) 2010 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([sqrt]) -# tests whether the sqrt function is available in libc or libm. It sets -# SQRT_LIBM to empty or "-lm" accordingly. +# gl_MATHFUNC(FUNC, RETTYPE, PARAMTYPES) +# -------------------------------------------------- +# 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. 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. m4_pushdef([func], [$1]) m4_pushdef([FUNC], [translit([$1],[abcdefghijklmnopqrstuvwxyz], [ABCDEFGHIJKLMNOPQRSTUVWXYZ])]) @@ -22,8 +28,8 @@ AC_DEFUN([gl_MATHFUNC], # define __NO_MATH_INLINES 1 /* for glibc */ #endif #include - double x;]], - [[return ]func[ (x) > 2 || ]func[ (x) < 0.4;]])], + $2 (*funcptr) $3 = ]func[;]], + [[return 0;]])], [gl_cv_func_]func[_no_libm=yes], [gl_cv_func_]func[_no_libm=no]) ]) @@ -38,8 +44,8 @@ AC_DEFUN([gl_MATHFUNC], # define __NO_MATH_INLINES 1 /* for glibc */ #endif #include - double x;]], - [[return ]func[ (x) > 2 || ]func[ (x) < 0.4;]])], + $2 (*funcptr) $3 = ]func[;]], + [[return 0;]])], [gl_cv_func_]func[_in_libm=yes], [gl_cv_func_]func[_in_libm=no]) LIBS="$save_LIBS" @@ -48,6 +54,62 @@ AC_DEFUN([gl_MATHFUNC], FUNC[]_LIBM=-lm fi fi + AC_SUBST(FUNC[_LIBM]) m4_popdef([FUNC]) m4_popdef([func]) ]) + +# gl_COMMON_DOUBLE_MATHFUNC(FUNC) +# ------------------------------- +# 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 + +AC_DEFUN([gl_COMMON_DOUBLE_MATHFUNC], +[ + AC_REQUIRE([gl_COMMON_DOUBLE_MATHFUNC_TEST]) + m4_pushdef([FUNC], [translit([$1],[abcdefghijklmnopqrstuvwxyz], + [ABCDEFGHIJKLMNOPQRSTUVWXYZ])]) + FUNC[]_LIBM="$POW_LIBM" + AC_SUBST(FUNC[_LIBM]) + m4_popdef([FUNC]) +]) + +AC_DEFUN([gl_COMMON_DOUBLE_MATHFUNC_TEST], +[ + dnl We could use any of the following: + dnl gl_MATHFUNC([acos], [double], [(double)]) + dnl gl_MATHFUNC([asin], [double], [(double)]) + 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)]) + dnl gl_MATHFUNC([erfc], [double], [(double)]) + dnl gl_MATHFUNC([exp], [double], [(double)]) + dnl gl_MATHFUNC([fmod], [double], [(double, double)]) + dnl gl_MATHFUNC([hypot], [double], [(double, double)]) + dnl gl_MATHFUNC([j0], [double], [(double)]) + dnl gl_MATHFUNC([j1], [double], [(double)]) + dnl gl_MATHFUNC([jn], [double], [(int, double)]) + dnl gl_MATHFUNC([lgamma], [double], [(double)]) + dnl gl_MATHFUNC([log], [double], [(double)]) + dnl gl_MATHFUNC([log10], [double], [(double)]) + dnl gl_MATHFUNC([log1p], [double], [(double)]) + dnl gl_MATHFUNC([pow], [double], [(double, double)]) + dnl gl_MATHFUNC([remainder], [double], [(double, double)]) + dnl gl_MATHFUNC([sin], [double], [(double)]) + dnl gl_MATHFUNC([sinh], [double], [(double)]) + dnl gl_MATHFUNC([sqrt], [double], [(double)]) + dnl gl_MATHFUNC([tan], [double], [(double)]) + dnl gl_MATHFUNC([tanh], [double], [(double)]) + dnl gl_MATHFUNC([y0], [double], [(double)]) + dnl gl_MATHFUNC([y1], [double], [(double)]) + dnl gl_MATHFUNC([yn], [double], [(int, double)]) + gl_MATHFUNC([pow], [double], [(double, double)]) +])