On 2010-01-18 I wrote: > 2010-01-18 Bruno Haible <br...@clisp.org> > > New modules for common <math.h> functions. > * m4/mathfunc.m4: New file.
Oops. This commit had 3 bugs: - The autoconf test for atan2, copysign, fmod, hypot, jn, ldexp, modf, nextafter, pow, remainder, yn always failed, for example: checking whether atan2 can be used without linking with libm... no checking whether atan2 can be used with libm... no The reason being that they take more than one argument. - On x86_64 systems, the test reported a incorrect "yes": checking whether fabs can be used without linking with libm... yes This was because calls to fabs are expanded inline by gcc on this platform, and therefore the test code linked fine without ever requiring the 'fabs' function in libm. - The macros @FUNC_LIBM@ were not expanded. This fixes it. Now I'm also adding unit tests for these functions. 2010-01-24 Bruno Haible <br...@clisp.org> Fix tests for for common <math.h> functions. * m4/mathfunc.m4 (gl_MATHFUNC): Take two additional parameters. Use a code snippet that references the function pointer, rather than merely calling the function. Substitute the FUNC_LIBM variable. * m4/sqrt.m4 (gl_FUNC_SQRT): Update gl_MATHFUNC invocation. * modules/acos (configure.ac): Likewise. * modules/asin (configure.ac): Likewise. * modules/atan (configure.ac): Likewise. * modules/atan2 (configure.ac): Likewise. * modules/cbrt (configure.ac): Likewise. * modules/copysign (configure.ac): Likewise. * modules/cos (configure.ac): Likewise. * modules/cosh (configure.ac): Likewise. * modules/erf (configure.ac): Likewise. * modules/erfc (configure.ac): Likewise. * modules/exp (configure.ac): Likewise. * modules/fabs (configure.ac): Likewise. * modules/fmod (configure.ac): Likewise. * modules/hypot (configure.ac): Likewise. * modules/j0 (configure.ac): Likewise. * modules/j1 (configure.ac): Likewise. * modules/jn (configure.ac): Likewise. * modules/ldexp (configure.ac): Likewise. * modules/lgamma (configure.ac): Likewise. * modules/log (configure.ac): Likewise. * modules/log10 (configure.ac): Likewise. * modules/log1p (configure.ac): Likewise. * modules/logb (configure.ac): Likewise. * modules/modf (configure.ac): Likewise. * modules/nextafter (configure.ac): Likewise. * modules/pow (configure.ac): Likewise. * modules/remainder (configure.ac): Likewise. * modules/rint (configure.ac): Likewise. * modules/sin (configure.ac): Likewise. * modules/sinh (configure.ac): Likewise. * modules/tan (configure.ac): Likewise. * modules/tanh (configure.ac): Likewise. * modules/y0 (configure.ac): Likewise. * modules/y1 (configure.ac): Likewise. * modules/yn (configure.ac): Likewise. --- m4/mathfunc.m4.orig Mon Jan 25 01:40:23 2010 +++ m4/mathfunc.m4 Mon Jan 25 01:34:33 2010 @@ -1,15 +1,21 @@ -# mathfunc.m4 serial 1 +# mathfunc.m4 serial 2 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 @@ # define __NO_MATH_INLINES 1 /* for glibc */ #endif #include <math.h> - 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 @@ # define __NO_MATH_INLINES 1 /* for glibc */ #endif #include <math.h> - 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,7 @@ FUNC[]_LIBM=-lm fi fi + AC_SUBST(FUNC[_LIBM]) m4_popdef([FUNC]) m4_popdef([func]) ]) --- m4/sqrt.m4.orig Mon Jan 25 01:40:24 2010 +++ m4/sqrt.m4 Mon Jan 25 01:37:16 2010 @@ -1,4 +1,4 @@ -# sqrt.m4 serial 1 +# sqrt.m4 serial 2 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, @@ -6,5 +6,5 @@ AC_DEFUN([gl_FUNC_SQRT], [ - gl_MATHFUNC([sqrt]) + gl_MATHFUNC([sqrt], [double], [(double)]) ]) --- modules/acos.orig Mon Jan 25 01:40:24 2010 +++ modules/acos Mon Jan 25 01:36:53 2010 @@ -7,7 +7,7 @@ Depends-on: configure.ac: -gl_MATHFUNC([acos]) +gl_MATHFUNC([acos], [double], [(double)]) Makefile.am: --- modules/asin.orig Mon Jan 25 01:40:24 2010 +++ modules/asin Mon Jan 25 01:36:54 2010 @@ -7,7 +7,7 @@ Depends-on: configure.ac: -gl_MATHFUNC([asin]) +gl_MATHFUNC([asin], [double], [(double)]) Makefile.am: --- modules/atan.orig Mon Jan 25 01:40:24 2010 +++ modules/atan Mon Jan 25 01:36:54 2010 @@ -7,7 +7,7 @@ Depends-on: configure.ac: -gl_MATHFUNC([atan]) +gl_MATHFUNC([atan], [double], [(double)]) Makefile.am: --- modules/atan2.orig Mon Jan 25 01:40:24 2010 +++ modules/atan2 Mon Jan 25 01:36:54 2010 @@ -7,7 +7,7 @@ Depends-on: configure.ac: -gl_MATHFUNC([atan2]) +gl_MATHFUNC([atan2], [double], [(double, double)]) Makefile.am: --- modules/cbrt.orig Mon Jan 25 01:40:24 2010 +++ modules/cbrt Mon Jan 25 01:36:54 2010 @@ -7,7 +7,7 @@ Depends-on: configure.ac: -gl_MATHFUNC([cbrt]) +gl_MATHFUNC([cbrt], [double], [(double)]) Makefile.am: --- modules/copysign.orig Mon Jan 25 01:40:24 2010 +++ modules/copysign Mon Jan 25 01:36:54 2010 @@ -7,7 +7,7 @@ Depends-on: configure.ac: -gl_MATHFUNC([copysign]) +gl_MATHFUNC([copysign], [double], [(double, double)]) Makefile.am: --- modules/cos.orig Mon Jan 25 01:40:24 2010 +++ modules/cos Mon Jan 25 01:36:54 2010 @@ -7,7 +7,7 @@ Depends-on: configure.ac: -gl_MATHFUNC([cos]) +gl_MATHFUNC([cos], [double], [(double)]) Makefile.am: --- modules/cosh.orig Mon Jan 25 01:40:24 2010 +++ modules/cosh Mon Jan 25 01:36:54 2010 @@ -7,7 +7,7 @@ Depends-on: configure.ac: -gl_MATHFUNC([cosh]) +gl_MATHFUNC([cosh], [double], [(double)]) Makefile.am: --- modules/erf.orig Mon Jan 25 01:40:24 2010 +++ modules/erf Mon Jan 25 01:36:55 2010 @@ -7,7 +7,7 @@ Depends-on: configure.ac: -gl_MATHFUNC([erf]) +gl_MATHFUNC([erf], [double], [(double)]) Makefile.am: --- modules/erfc.orig Mon Jan 25 01:40:24 2010 +++ modules/erfc Mon Jan 25 01:36:55 2010 @@ -7,7 +7,7 @@ Depends-on: configure.ac: -gl_MATHFUNC([erfc]) +gl_MATHFUNC([erfc], [double], [(double)]) Makefile.am: --- modules/exp.orig Mon Jan 25 01:40:24 2010 +++ modules/exp Mon Jan 25 01:36:55 2010 @@ -7,7 +7,7 @@ Depends-on: configure.ac: -gl_MATHFUNC([exp]) +gl_MATHFUNC([exp], [double], [(double)]) Makefile.am: --- modules/fabs.orig Mon Jan 25 01:40:24 2010 +++ modules/fabs Mon Jan 25 01:36:55 2010 @@ -7,7 +7,7 @@ Depends-on: configure.ac: -gl_MATHFUNC([fabs]) +gl_MATHFUNC([fabs], [double], [(double)]) Makefile.am: --- modules/fmod.orig Mon Jan 25 01:40:24 2010 +++ modules/fmod Mon Jan 25 01:36:55 2010 @@ -7,7 +7,7 @@ Depends-on: configure.ac: -gl_MATHFUNC([fmod]) +gl_MATHFUNC([fmod], [double], [(double, double)]) Makefile.am: --- modules/hypot.orig Mon Jan 25 01:40:24 2010 +++ modules/hypot Mon Jan 25 01:36:55 2010 @@ -7,7 +7,7 @@ Depends-on: configure.ac: -gl_MATHFUNC([hypot]) +gl_MATHFUNC([hypot], [double], [(double, double)]) Makefile.am: --- modules/j0.orig Mon Jan 25 01:40:24 2010 +++ modules/j0 Mon Jan 25 01:36:55 2010 @@ -7,7 +7,7 @@ Depends-on: configure.ac: -gl_MATHFUNC([j0]) +gl_MATHFUNC([j0], [double], [(double)]) Makefile.am: --- modules/j1.orig Mon Jan 25 01:40:24 2010 +++ modules/j1 Mon Jan 25 01:36:55 2010 @@ -7,7 +7,7 @@ Depends-on: configure.ac: -gl_MATHFUNC([j1]) +gl_MATHFUNC([j1], [double], [(double)]) Makefile.am: --- modules/jn.orig Mon Jan 25 01:40:24 2010 +++ modules/jn Mon Jan 25 01:36:55 2010 @@ -7,7 +7,7 @@ Depends-on: configure.ac: -gl_MATHFUNC([jn]) +gl_MATHFUNC([jn], [double], [(int, double)]) Makefile.am: --- modules/ldexp.orig Mon Jan 25 01:40:24 2010 +++ modules/ldexp Mon Jan 25 01:36:55 2010 @@ -7,7 +7,7 @@ Depends-on: configure.ac: -gl_MATHFUNC([ldexp]) +gl_MATHFUNC([ldexp], [double], [(double, int)]) Makefile.am: --- modules/lgamma.orig Mon Jan 25 01:40:24 2010 +++ modules/lgamma Mon Jan 25 01:36:55 2010 @@ -7,7 +7,7 @@ Depends-on: configure.ac: -gl_MATHFUNC([lgamma]) +gl_MATHFUNC([lgamma], [double], [(double)]) Makefile.am: --- modules/log.orig Mon Jan 25 01:40:24 2010 +++ modules/log Mon Jan 25 01:36:55 2010 @@ -7,7 +7,7 @@ Depends-on: configure.ac: -gl_MATHFUNC([log]) +gl_MATHFUNC([log], [double], [(double)]) Makefile.am: --- modules/log10.orig Mon Jan 25 01:40:24 2010 +++ modules/log10 Mon Jan 25 01:36:55 2010 @@ -7,7 +7,7 @@ Depends-on: configure.ac: -gl_MATHFUNC([log10]) +gl_MATHFUNC([log10], [double], [(double)]) Makefile.am: --- modules/log1p.orig Mon Jan 25 01:40:24 2010 +++ modules/log1p Mon Jan 25 01:36:56 2010 @@ -7,7 +7,7 @@ Depends-on: configure.ac: -gl_MATHFUNC([log1p]) +gl_MATHFUNC([log1p], [double], [(double)]) Makefile.am: --- modules/logb.orig Mon Jan 25 01:40:24 2010 +++ modules/logb Mon Jan 25 01:36:56 2010 @@ -7,7 +7,7 @@ Depends-on: configure.ac: -gl_MATHFUNC([logb]) +gl_MATHFUNC([logb], [double], [(double)]) Makefile.am: --- modules/modf.orig Mon Jan 25 01:40:24 2010 +++ modules/modf Mon Jan 25 01:36:56 2010 @@ -7,7 +7,7 @@ Depends-on: configure.ac: -gl_MATHFUNC([modf]) +gl_MATHFUNC([modf], [double], [(double, double *)]) Makefile.am: --- modules/nextafter.orig Mon Jan 25 01:40:29 2010 +++ modules/nextafter Mon Jan 25 01:36:56 2010 @@ -7,7 +7,7 @@ Depends-on: configure.ac: -gl_MATHFUNC([nextafter]) +gl_MATHFUNC([nextafter], [double], [(double)]) Makefile.am: --- modules/pow.orig Mon Jan 25 01:40:29 2010 +++ modules/pow Mon Jan 25 01:36:56 2010 @@ -7,7 +7,7 @@ Depends-on: configure.ac: -gl_MATHFUNC([pow]) +gl_MATHFUNC([pow], [double], [(double, double)]) Makefile.am: --- modules/remainder.orig Mon Jan 25 01:40:29 2010 +++ modules/remainder Mon Jan 25 01:36:56 2010 @@ -7,7 +7,7 @@ Depends-on: configure.ac: -gl_MATHFUNC([remainder]) +gl_MATHFUNC([remainder], [double], [(double, double)]) Makefile.am: --- modules/rint.orig Mon Jan 25 01:40:29 2010 +++ modules/rint Mon Jan 25 01:36:56 2010 @@ -7,7 +7,7 @@ Depends-on: configure.ac: -gl_MATHFUNC([rint]) +gl_MATHFUNC([rint], [double], [(double)]) Makefile.am: --- modules/sin.orig Mon Jan 25 01:40:29 2010 +++ modules/sin Mon Jan 25 01:36:56 2010 @@ -7,7 +7,7 @@ Depends-on: configure.ac: -gl_MATHFUNC([sin]) +gl_MATHFUNC([sin], [double], [(double)]) Makefile.am: --- modules/sinh.orig Mon Jan 25 01:40:29 2010 +++ modules/sinh Mon Jan 25 01:36:56 2010 @@ -7,7 +7,7 @@ Depends-on: configure.ac: -gl_MATHFUNC([sinh]) +gl_MATHFUNC([sinh], [double], [(double)]) Makefile.am: --- modules/tan.orig Mon Jan 25 01:40:29 2010 +++ modules/tan Mon Jan 25 01:36:56 2010 @@ -7,7 +7,7 @@ Depends-on: configure.ac: -gl_MATHFUNC([tan]) +gl_MATHFUNC([tan], [double], [(double)]) Makefile.am: --- modules/tanh.orig Mon Jan 25 01:40:29 2010 +++ modules/tanh Mon Jan 25 01:36:56 2010 @@ -7,7 +7,7 @@ Depends-on: configure.ac: -gl_MATHFUNC([tanh]) +gl_MATHFUNC([tanh], [double], [(double)]) Makefile.am: --- modules/y0.orig Mon Jan 25 01:40:29 2010 +++ modules/y0 Mon Jan 25 01:36:56 2010 @@ -7,7 +7,7 @@ Depends-on: configure.ac: -gl_MATHFUNC([y0]) +gl_MATHFUNC([y0], [double], [(double)]) Makefile.am: --- modules/y1.orig Mon Jan 25 01:40:29 2010 +++ modules/y1 Mon Jan 25 01:36:57 2010 @@ -7,7 +7,7 @@ Depends-on: configure.ac: -gl_MATHFUNC([y1]) +gl_MATHFUNC([y1], [double], [(double)]) Makefile.am: --- modules/yn.orig Mon Jan 25 01:40:29 2010 +++ modules/yn Mon Jan 25 01:36:57 2010 @@ -7,7 +7,7 @@ Depends-on: configure.ac: -gl_MATHFUNC([yn]) +gl_MATHFUNC([yn], [double], [(int, double)]) Makefile.am: