From 21492d6c3ca00ff0827528640804732f2ed66470 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Sun, 9 Oct 2011 00:59:02 +0200 Subject: [PATCH] New module 'tanhf'. * lib/math.in.h (tanhf): New declaration. * lib/tanhf.c: New file. * m4/tanhf.m4: New file. * m4/math_h.m4 (gl_MATH_H): Test whether tanhf is declared. (gl_MATH_H_DEFAULTS): Initialize GNULIB_TANHF, HAVE_TANHF. * modules/math (Makefile.am): Substitute GNULIB_TANHF, HAVE_TANHF. * modules/tanhf: New file. * tests/test-math-c++.cc: Check the declaration of tanhf. * doc/posix-functions/tanhf.texi: Mention the new module. --- ChangeLog | 11 +++++++++++ doc/posix-functions/tanhf.texi | 10 +++++----- lib/math.in.h | 16 ++++++++++++++++ lib/tanhf.c | 26 ++++++++++++++++++++++++++ m4/math_h.m4 | 6 ++++-- m4/tanhf.m4 | 25 +++++++++++++++++++++++++ modules/math | 2 ++ modules/tanhf | 31 +++++++++++++++++++++++++++++++ tests/test-math-c++.cc | 3 +++ 9 files changed, 123 insertions(+), 7 deletions(-) create mode 100644 lib/tanhf.c create mode 100644 m4/tanhf.m4 create mode 100644 modules/tanhf diff --git a/ChangeLog b/ChangeLog index e05e78da0..16af4120d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,16 @@ 2011-10-08 Bruno Haible + New module 'tanhf'. + * lib/math.in.h (tanhf): New declaration. + * lib/tanhf.c: New file. + * m4/tanhf.m4: New file. + * m4/math_h.m4 (gl_MATH_H): Test whether tanhf is declared. + (gl_MATH_H_DEFAULTS): Initialize GNULIB_TANHF, HAVE_TANHF. + * modules/math (Makefile.am): Substitute GNULIB_TANHF, HAVE_TANHF. + * modules/tanhf: New file. + * tests/test-math-c++.cc: Check the declaration of tanhf. + * doc/posix-functions/tanhf.texi: Mention the new module. + tanh: Use a .m4 file. * m4/tanh.m4: New file. * modules/tanh (Files): Add it. diff --git a/doc/posix-functions/tanhf.texi b/doc/posix-functions/tanhf.texi index 1b7cb4fe6..6c7369548 100644 --- a/doc/posix-functions/tanhf.texi +++ b/doc/posix-functions/tanhf.texi @@ -4,14 +4,10 @@ POSIX specification:@* @url{http://www.opengroup.org/onlinepubs/9699919799/functions/tanhf.html} -Gnulib module: --- +Gnulib module: tanhf Portability problems fixed by Gnulib: @itemize -@end itemize - -Portability problems not fixed by Gnulib: -@itemize @item This function is missing on some platforms: Minix 3.1.8, AIX 5.1, Solaris 9. @@ -19,3 +15,7 @@ Minix 3.1.8, AIX 5.1, Solaris 9. This function is only defined as a macro with arguments on some platforms: MSVC 9. @end itemize + +Portability problems not fixed by Gnulib: +@itemize +@end itemize diff --git a/lib/math.in.h b/lib/math.in.h index d7da584d1..a63765824 100644 --- a/lib/math.in.h +++ b/lib/math.in.h @@ -845,6 +845,22 @@ _GL_WARN_ON_USE (tanl, "tanl is unportable - " #endif +#if @GNULIB_TANHF@ +# if !@HAVE_TANHF@ +# undef tanhf +_GL_FUNCDECL_SYS (tanhf, float, (float x)); +# endif +_GL_CXXALIAS_SYS (tanhf, float, (float x)); +_GL_CXXALIASWARN (tanhf); +#elif defined GNULIB_POSIXCHECK +# undef tanhf +# if HAVE_RAW_DECL_TANHF +_GL_WARN_ON_USE (tanhf, "tanhf is unportable - " + "use gnulib module tanhf for portability"); +# endif +#endif + + #if @GNULIB_TRUNCF@ # if @REPLACE_TRUNCF@ # if !(defined __cplusplus && defined GNULIB_NAMESPACE) diff --git a/lib/tanhf.c b/lib/tanhf.c new file mode 100644 index 000000000..b7591a0d6 --- /dev/null +++ b/lib/tanhf.c @@ -0,0 +1,26 @@ +/* Hyperbolic tangent function. + Copyright (C) 2011 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 +tanhf (float x) +{ + return (float) tanh ((double) x); +} diff --git a/m4/math_h.m4 b/m4/math_h.m4 index 670976442..0fb405b93 100644 --- a/m4/math_h.m4 +++ b/m4/math_h.m4 @@ -1,4 +1,4 @@ -# math_h.m4 serial 45 +# math_h.m4 serial 46 dnl Copyright (C) 2007-2011 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -43,7 +43,7 @@ AC_DEFUN([gl_MATH_H], expf expl fabsf floorf floorl fmodf frexpf frexpl ldexpf ldexpl logb logf logl log10f modff powf round roundf roundl sinf sinl sinhf sqrtf sqrtl - tanf tanl trunc truncf truncl]) + tanf tanl tanhf trunc truncf truncl]) ]) AC_DEFUN([gl_MATH_MODULE_INDICATOR], @@ -105,6 +105,7 @@ AC_DEFUN([gl_MATH_H_DEFAULTS], GNULIB_SQRTL=0; AC_SUBST([GNULIB_SQRTL]) GNULIB_TANF=0; AC_SUBST([GNULIB_TANF]) GNULIB_TANL=0; AC_SUBST([GNULIB_TANL]) + GNULIB_TANHF=0; AC_SUBST([GNULIB_TANHF]) GNULIB_TRUNC=0; AC_SUBST([GNULIB_TRUNC]) GNULIB_TRUNCF=0; AC_SUBST([GNULIB_TRUNCF]) GNULIB_TRUNCL=0; AC_SUBST([GNULIB_TRUNCL]) @@ -140,6 +141,7 @@ AC_DEFUN([gl_MATH_H_DEFAULTS], HAVE_SQRTL=1; AC_SUBST([HAVE_SQRTL]) HAVE_TANF=1; AC_SUBST([HAVE_TANF]) HAVE_TANL=1; AC_SUBST([HAVE_TANL]) + HAVE_TANHF=1; AC_SUBST([HAVE_TANHF]) HAVE_DECL_ACOSL=1; AC_SUBST([HAVE_DECL_ACOSL]) HAVE_DECL_ASINL=1; AC_SUBST([HAVE_DECL_ASINL]) HAVE_DECL_ATANL=1; AC_SUBST([HAVE_DECL_ATANL]) diff --git a/m4/tanhf.m4 b/m4/tanhf.m4 new file mode 100644 index 000000000..2608f97ee --- /dev/null +++ b/m4/tanhf.m4 @@ -0,0 +1,25 @@ +# tanhf.m4 serial 1 +dnl Copyright (C) 2011 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_TANHF], +[ + AC_REQUIRE([gl_MATH_H_DEFAULTS]) + AC_REQUIRE([gl_FUNC_TANH]) + + dnl Test whether tanhf() exists. Assume that tanhf(), if it exists, is + dnl defined in the same library as tanh(). + save_LIBS="$LIBS" + LIBS="$LIBS $TANH_LIBM" + AC_CHECK_FUNCS([tanhf]) + LIBS="$save_LIBS" + if test $ac_cv_func_tanhf = yes; then + TANHF_LIBM="$TANH_LIBM" + else + HAVE_TANHF=0 + TANHF_LIBM="$TANH_LIBM" + fi + AC_SUBST([TANHF_LIBM]) +]) diff --git a/modules/math b/modules/math index 5edfe2a02..9c6f999f9 100644 --- a/modules/math +++ b/modules/math @@ -76,6 +76,7 @@ math.h: math.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $( -e 's/@''GNULIB_SQRTL''@/$(GNULIB_SQRTL)/g' \ -e 's/@''GNULIB_TANF''@/$(GNULIB_TANF)/g' \ -e 's/@''GNULIB_TANL''@/$(GNULIB_TANL)/g' \ + -e 's/@''GNULIB_TANHF''@/$(GNULIB_TANHF)/g' \ -e 's/@''GNULIB_TRUNC''@/$(GNULIB_TRUNC)/g' \ -e 's/@''GNULIB_TRUNCF''@/$(GNULIB_TRUNCF)/g' \ -e 's/@''GNULIB_TRUNCL''@/$(GNULIB_TRUNCL)/g' \ @@ -111,6 +112,7 @@ math.h: math.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $( -e 's|@''HAVE_SQRTL''@|$(HAVE_SQRTL)|g' \ -e 's|@''HAVE_TANF''@|$(HAVE_TANF)|g' \ -e 's|@''HAVE_TANL''@|$(HAVE_TANL)|g' \ + -e 's|@''HAVE_TANHF''@|$(HAVE_TANHF)|g' \ -e 's|@''HAVE_DECL_ACOSL''@|$(HAVE_DECL_ACOSL)|g' \ -e 's|@''HAVE_DECL_ASINL''@|$(HAVE_DECL_ASINL)|g' \ -e 's|@''HAVE_DECL_ATANL''@|$(HAVE_DECL_ATANL)|g' \ diff --git a/modules/tanhf b/modules/tanhf new file mode 100644 index 000000000..44f606e75 --- /dev/null +++ b/modules/tanhf @@ -0,0 +1,31 @@ +Description: +tanhf() function: hyperbolic tangent function. + +Files: +lib/tanhf.c +m4/tanhf.m4 + +Depends-on: +math +tanh [test $HAVE_TANHF = 0] + +configure.ac: +gl_FUNC_TANHF +if test $HAVE_TANHF = 0; then + AC_LIBOBJ([tanhf]) +fi +gl_MATH_MODULE_INDICATOR([tanhf]) + +Makefile.am: + +Include: + + +Link: +$(TANHF_LIBM) + +License: +LGPL + +Maintainer: +Bruno Haible diff --git a/tests/test-math-c++.cc b/tests/test-math-c++.cc index bcb5b6da4..d786273c4 100644 --- a/tests/test-math-c++.cc +++ b/tests/test-math-c++.cc @@ -116,6 +116,9 @@ SIGNATURE_CHECK (GNULIB_NAMESPACE::sqrtf, float, (float)); SIGNATURE_CHECK (GNULIB_NAMESPACE::tanf, float, (float)); #endif //SIGNATURE_CHECK (GNULIB_NAMESPACE::tan, double, (double)); +#if GNULIB_TEST_TANHF +SIGNATURE_CHECK (GNULIB_NAMESPACE::tanhf, float, (float)); +#endif //SIGNATURE_CHECK (GNULIB_NAMESPACE::tanh, double, (double)); //SIGNATURE_CHECK (GNULIB_NAMESPACE::y0, double, (double)); //SIGNATURE_CHECK (GNULIB_NAMESPACE::y1, double, (double)); -- 2.11.0