From: Bruno Haible Date: Thu, 8 Mar 2012 19:24:53 +0000 (+0100) Subject: New module 'exp2f'. X-Git-Tag: v0.1~908 X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=bff4a106924f9531c45661e5d163470e9faa521a;p=gnulib.git New module 'exp2f'. * lib/math.in.h (exp2f): New declaration. * lib/exp2f.c: New file. * m4/exp2f.m4: New file. * m4/math_h.m4 (gl_MATH_H): Test whether exp2f is declared. (gl_MATH_H_DEFAULTS): Initialize GNULIB_EXP2F, HAVE_DECL_EXP2F. * modules/math (Makefile.am): Substitute GNULIB_EXP2F, HAVE_DECL_EXP2F. * modules/exp2f: New file. * tests/test-math-c++.cc: Check the declaration of exp2f. * doc/posix-functions/exp2f.texi: Mention the new module and the IRIX problem. --- diff --git a/ChangeLog b/ChangeLog index af5fd9f25c..ebd2796c72 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,17 @@ +2012-03-08 Bruno Haible + + New module 'exp2f'. + * lib/math.in.h (exp2f): New declaration. + * lib/exp2f.c: New file. + * m4/exp2f.m4: New file. + * m4/math_h.m4 (gl_MATH_H): Test whether exp2f is declared. + (gl_MATH_H_DEFAULTS): Initialize GNULIB_EXP2F, HAVE_DECL_EXP2F. + * modules/math (Makefile.am): Substitute GNULIB_EXP2F, HAVE_DECL_EXP2F. + * modules/exp2f: New file. + * tests/test-math-c++.cc: Check the declaration of exp2f. + * doc/posix-functions/exp2f.texi: Mention the new module and the + IRIX problem. + 2012-03-08 Bruno Haible Tests for module 'exp2'. diff --git a/doc/posix-functions/exp2f.texi b/doc/posix-functions/exp2f.texi index acf65f4a7d..3a9a4e8895 100644 --- a/doc/posix-functions/exp2f.texi +++ b/doc/posix-functions/exp2f.texi @@ -4,15 +4,18 @@ POSIX specification:@* @url{http://www.opengroup.org/onlinepubs/9699919799/functions/exp2f.html} -Gnulib module: --- +Gnulib module: exp2f Portability problems fixed by Gnulib: @itemize +@item +This function is missing on some platforms: +FreeBSD 5.2.1, NetBSD 5.0, OpenBSD 3.8, Minix 3.1.8, AIX 5.1, HP-UX 11, older IRIX 6.5, OSF/1 4.0, Solaris 9, MSVC 9, Interix 3.5. +@item +This function is not declared on some platforms: +IRIX 6.5. @end itemize Portability problems not fixed by Gnulib: @itemize -@item -This function is missing on some platforms: -FreeBSD 5.2.1, NetBSD 5.0, OpenBSD 3.8, Minix 3.1.8, AIX 5.1, HP-UX 11, IRIX 6.5, OSF/1 4.0, Solaris 9, MSVC 9, Interix 3.5. @end itemize diff --git a/lib/exp2f.c b/lib/exp2f.c new file mode 100644 index 0000000000..a3a3cdd45c --- /dev/null +++ b/lib/exp2f.c @@ -0,0 +1,26 @@ +/* Exponential base 2 function. + Copyright (C) 2011-2012 Free Software Foundation, Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +#include + +/* Specification. */ +#include + +float +exp2f (float x) +{ + return (float) exp2 ((double) x); +} diff --git a/lib/math.in.h b/lib/math.in.h index d0df55b603..642d8b3b00 100644 --- a/lib/math.in.h +++ b/lib/math.in.h @@ -532,6 +532,20 @@ _GL_WARN_ON_USE (expl, "expl is unportable - " #endif +#if @GNULIB_EXP2F@ +# if !@HAVE_DECL_EXP2F@ +_GL_FUNCDECL_SYS (exp2f, float, (float x)); +# endif +_GL_CXXALIAS_SYS (exp2f, float, (float x)); +_GL_CXXALIASWARN (exp2f); +#elif defined GNULIB_POSIXCHECK +# undef exp2f +# if HAVE_RAW_DECL_EXP2F +_GL_WARN_ON_USE (exp2f, "exp2f is unportable - " + "use gnulib module exp2f for portability"); +# endif +#endif + #if @GNULIB_EXP2@ # if @REPLACE_EXP2@ # if !(defined __cplusplus && defined GNULIB_NAMESPACE) diff --git a/m4/exp2f.m4 b/m4/exp2f.m4 new file mode 100644 index 0000000000..3be34e4f1c --- /dev/null +++ b/m4/exp2f.m4 @@ -0,0 +1,34 @@ +# exp2f.m4 serial 1 +dnl Copyright (C) 2011-2012 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. + +AC_DEFUN([gl_FUNC_EXP2F], +[ + AC_REQUIRE([gl_MATH_H_DEFAULTS]) + AC_REQUIRE([gl_FUNC_EXP2]) + + dnl Persuade glibc to declare exp2f(). + AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS]) + + dnl Test whether exp2f() exists. Assume that exp2f(), if it exists, is + dnl defined in the same library as exp2(). + save_LIBS="$LIBS" + LIBS="$LIBS $EXP2_LIBM" + AC_CHECK_FUNCS([exp2f]) + LIBS="$save_LIBS" + if test $ac_cv_func_exp2f = yes; then + HAVE_EXP2F=1 + EXP2F_LIBM="$EXP2_LIBM" + dnl Also check whether it's declared. + dnl IRIX 6.5 has exp2f() in libm but doesn't declare it in . + AC_CHECK_DECL([exp2f], , [HAVE_DECL_EXP2F=0], [[#include ]]) + else + HAVE_EXP2F=0 + HAVE_DECL_EXP2F=0 + dnl Find libraries needed to link lib/exp2f.c. + EXP2F_LIBM="$EXP2_LIBM" + fi + AC_SUBST([EXP2F_LIBM]) +]) diff --git a/m4/math_h.m4 b/m4/math_h.m4 index 938dcf190e..772b998ba6 100644 --- a/m4/math_h.m4 +++ b/m4/math_h.m4 @@ -1,4 +1,4 @@ -# math_h.m4 serial 89 +# math_h.m4 serial 90 dnl Copyright (C) 2007-2012 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -41,7 +41,8 @@ AC_DEFUN([gl_MATH_H], gl_WARN_ON_USE_PREPARE([[#include ]], [acosf acosl asinf asinl atanf atanl cbrt cbrtf cbrtl ceilf ceill copysign copysignf copysignl cosf cosl coshf - expf expl exp2 expm1 expm1f expm1l fabsf fabsl floorf floorl fma fmaf fmal + expf expl exp2 exp2f expm1 expm1f expm1l + fabsf fabsl floorf floorl fma fmaf fmal fmod fmodf fmodl frexpf frexpl hypotf hypotl ldexpf ldexpl logb logf logl log10f log10l modf modff modfl powf remainder remainderf remainderl @@ -82,6 +83,7 @@ AC_DEFUN([gl_MATH_H_DEFAULTS], GNULIB_EXPF=0; AC_SUBST([GNULIB_EXPF]) GNULIB_EXPL=0; AC_SUBST([GNULIB_EXPL]) GNULIB_EXP2=0; AC_SUBST([GNULIB_EXP2]) + GNULIB_EXP2F=0; AC_SUBST([GNULIB_EXP2F]) GNULIB_EXPM1=0; AC_SUBST([GNULIB_EXPM1]) GNULIB_EXPM1F=0; AC_SUBST([GNULIB_EXPM1F]) GNULIB_EXPM1L=0; AC_SUBST([GNULIB_EXPM1L]) @@ -204,6 +206,7 @@ AC_DEFUN([gl_MATH_H_DEFAULTS], HAVE_DECL_COSL=1; AC_SUBST([HAVE_DECL_COSL]) HAVE_DECL_EXPL=1; AC_SUBST([HAVE_DECL_EXPL]) HAVE_DECL_EXP2=1; AC_SUBST([HAVE_DECL_EXP2]) + HAVE_DECL_EXP2F=1; AC_SUBST([HAVE_DECL_EXP2F]) HAVE_DECL_EXPM1L=1; AC_SUBST([HAVE_DECL_EXPM1L]) HAVE_DECL_FLOORF=1; AC_SUBST([HAVE_DECL_FLOORF]) HAVE_DECL_FLOORL=1; AC_SUBST([HAVE_DECL_FLOORL]) diff --git a/modules/exp2f b/modules/exp2f new file mode 100644 index 0000000000..cb98872201 --- /dev/null +++ b/modules/exp2f @@ -0,0 +1,32 @@ +Description: +exp2f() function: exponential base 2 function. + +Files: +lib/exp2f.c +m4/exp2f.m4 + +Depends-on: +math +extensions +exp2 [test $HAVE_EXP2F = 0] + +configure.ac: +gl_FUNC_EXP2F +if test $HAVE_EXP2F = 0; then + AC_LIBOBJ([exp2f]) +fi +gl_MATH_MODULE_INDICATOR([exp2f]) + +Makefile.am: + +Include: + + +Link: +$(EXP2F_LIBM) + +License: +LGPL + +Maintainer: +Bruno Haible diff --git a/modules/math b/modules/math index bb03a846d5..31166184dd 100644 --- a/modules/math +++ b/modules/math @@ -50,6 +50,7 @@ math.h: math.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $( -e 's/@''GNULIB_EXPF''@/$(GNULIB_EXPF)/g' \ -e 's/@''GNULIB_EXPL''@/$(GNULIB_EXPL)/g' \ -e 's/@''GNULIB_EXP2''@/$(GNULIB_EXP2)/g' \ + -e 's/@''GNULIB_EXP2F''@/$(GNULIB_EXP2F)/g' \ -e 's/@''GNULIB_EXPM1''@/$(GNULIB_EXPM1)/g' \ -e 's/@''GNULIB_EXPM1F''@/$(GNULIB_EXPM1F)/g' \ -e 's/@''GNULIB_EXPM1L''@/$(GNULIB_EXPM1L)/g' \ @@ -172,6 +173,7 @@ math.h: math.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $( -e 's|@''HAVE_DECL_COSL''@|$(HAVE_DECL_COSL)|g' \ -e 's|@''HAVE_DECL_EXPL''@|$(HAVE_DECL_EXPL)|g' \ -e 's|@''HAVE_DECL_EXP2''@|$(HAVE_DECL_EXP2)|g' \ + -e 's|@''HAVE_DECL_EXP2F''@|$(HAVE_DECL_EXP2F)|g' \ -e 's|@''HAVE_DECL_EXPM1L''@|$(HAVE_DECL_EXPM1L)|g' \ -e 's|@''HAVE_DECL_FLOORF''@|$(HAVE_DECL_FLOORF)|g' \ -e 's|@''HAVE_DECL_FLOORL''@|$(HAVE_DECL_FLOORL)|g' \ diff --git a/tests/test-math-c++.cc b/tests/test-math-c++.cc index 18ec07a910..904e927d00 100644 --- a/tests/test-math-c++.cc +++ b/tests/test-math-c++.cc @@ -124,6 +124,9 @@ SIGNATURE_CHECK (GNULIB_NAMESPACE::expf, float, (float)); SIGNATURE_CHECK (GNULIB_NAMESPACE::expl, long double, (long double)); #endif +#if GNULIB_TEST_EXP2F +SIGNATURE_CHECK (GNULIB_NAMESPACE::exp2f, float, (float)); +#endif #if GNULIB_TEST_EXP2 SIGNATURE_CHECK (GNULIB_NAMESPACE::exp2, double, (double)); #endif