From: Bruno Haible Date: Sat, 8 Oct 2011 19:16:48 +0000 (+0200) Subject: New module 'sqrtf'. X-Git-Tag: v0.1~1669 X-Git-Url: http://erislabs.org.uk/gitweb/?a=commitdiff_plain;h=6a586a91c909c2dde4390037f5ee672978075b49;p=gnulib.git New module 'sqrtf'. * lib/math.in.h (sqrtf): New declaration. * lib/sqrtf.c: New file. * m4/sqrtf.m4: New file. * m4/math_h.m4 (gl_MATH_H): Test whether sqrtf is declared. (gl_MATH_H_DEFAULTS): Initialize GNULIB_SQRTF, HAVE_SQRTF. * modules/math (Makefile.am): Substitute GNULIB_SQRTF, HAVE_SQRTF. * modules/sqrtf: New file. * tests/test-math-c++.cc: Check the declaration of sqrtf. * doc/posix-functions/sqrtf.texi: Mention the new module. --- diff --git a/ChangeLog b/ChangeLog index ce4e57a21..006f338c3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,18 @@ 2011-10-08 Bruno Haible + New module 'sqrtf'. + * lib/math.in.h (sqrtf): New declaration. + * lib/sqrtf.c: New file. + * m4/sqrtf.m4: New file. + * m4/math_h.m4 (gl_MATH_H): Test whether sqrtf is declared. + (gl_MATH_H_DEFAULTS): Initialize GNULIB_SQRTF, HAVE_SQRTF. + * modules/math (Makefile.am): Substitute GNULIB_SQRTF, HAVE_SQRTF. + * modules/sqrtf: New file. + * tests/test-math-c++.cc: Check the declaration of sqrtf. + * doc/posix-functions/sqrtf.texi: Mention the new module. + +2011-10-08 Bruno Haible + Tests: Avoid link failures w.r.t. libintl. * modules/faccessat-tests (Makefile.am): Link test-faccessat against $(LIBINTL). diff --git a/doc/posix-functions/sqrtf.texi b/doc/posix-functions/sqrtf.texi index acb4b2e41..89198e8e7 100644 --- a/doc/posix-functions/sqrtf.texi +++ b/doc/posix-functions/sqrtf.texi @@ -4,14 +4,10 @@ POSIX specification:@* @url{http://www.opengroup.org/onlinepubs/9699919799/functions/sqrtf.html} -Gnulib module: --- +Gnulib module: sqrtf 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 a80f24f6c..609cb9caf 100644 --- a/lib/math.in.h +++ b/lib/math.in.h @@ -600,6 +600,21 @@ _GL_WARN_ON_USE (sinl, "sinl is unportable - " #endif +#if @GNULIB_SQRTF@ +# if !@HAVE_SQRTF@ +# undef sqrtf +_GL_FUNCDECL_SYS (sqrtf, float, (float x)); +# endif +_GL_CXXALIAS_SYS (sqrtf, float, (float x)); +_GL_CXXALIASWARN (sqrtf); +#elif defined GNULIB_POSIXCHECK +# undef sqrtf +# if HAVE_RAW_DECL_SQRTF +_GL_WARN_ON_USE (sqrtf, "sqrtf is unportable - " + "use gnulib module sqrtf for portability"); +# endif +#endif + #if @GNULIB_SQRTL@ # if !@HAVE_SQRTL@ || !@HAVE_DECL_SQRTL@ _GL_FUNCDECL_SYS (sqrtl, long double, (long double x)); diff --git a/lib/sqrtf.c b/lib/sqrtf.c new file mode 100644 index 000000000..02ec7c276 --- /dev/null +++ b/lib/sqrtf.c @@ -0,0 +1,26 @@ +/* Square root. + 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 +sqrtf (float x) +{ + return (float) sqrt ((double) x); +} diff --git a/m4/math_h.m4 b/m4/math_h.m4 index 6ba94489e..ef3331f90 100644 --- a/m4/math_h.m4 +++ b/m4/math_h.m4 @@ -1,4 +1,4 @@ -# math_h.m4 serial 31 +# math_h.m4 serial 32 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, @@ -41,7 +41,7 @@ AC_DEFUN([gl_MATH_H], gl_WARN_ON_USE_PREPARE([[#include ]], [acosl asinl atanl ceilf ceill cosl expl fabsf floorf floorl fmodf frexpf frexpl - ldexpf ldexpl logb logl modff round roundf roundl sinl sqrtl + ldexpf ldexpl logb logl modff round roundf roundl sinl sqrtf sqrtl tanl trunc truncf truncl]) ]) @@ -88,6 +88,7 @@ AC_DEFUN([gl_MATH_H_DEFAULTS], GNULIB_ROUNDL=0; AC_SUBST([GNULIB_ROUNDL]) GNULIB_SIGNBIT=0; AC_SUBST([GNULIB_SIGNBIT]) GNULIB_SINL=0; AC_SUBST([GNULIB_SINL]) + GNULIB_SQRTF=0; AC_SUBST([GNULIB_SQRTF]) GNULIB_SQRTL=0; AC_SUBST([GNULIB_SQRTL]) GNULIB_TANL=0; AC_SUBST([GNULIB_TANL]) GNULIB_TRUNC=0; AC_SUBST([GNULIB_TRUNC]) @@ -109,6 +110,7 @@ AC_DEFUN([gl_MATH_H_DEFAULTS], HAVE_LOGL=1; AC_SUBST([HAVE_LOGL]) HAVE_MODFF=1; AC_SUBST([HAVE_MODFF]) HAVE_SINL=1; AC_SUBST([HAVE_SINL]) + HAVE_SQRTF=1; AC_SUBST([HAVE_SQRTF]) HAVE_SQRTL=1; AC_SUBST([HAVE_SQRTL]) HAVE_TANL=1; AC_SUBST([HAVE_TANL]) HAVE_DECL_ACOSL=1; AC_SUBST([HAVE_DECL_ACOSL]) diff --git a/m4/sqrtf.m4 b/m4/sqrtf.m4 new file mode 100644 index 000000000..962a9261f --- /dev/null +++ b/m4/sqrtf.m4 @@ -0,0 +1,25 @@ +# sqrtf.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_SQRTF], +[ + AC_REQUIRE([gl_MATH_H_DEFAULTS]) + AC_REQUIRE([gl_FUNC_SQRT]) + + dnl Test whether sqrtf() exists. Assume that sqrtf(), if it exists, is + dnl defined in the same library as sqrt(). + save_LIBS="$LIBS" + LIBS="$LIBS $SQRT_LIBM" + AC_CHECK_FUNCS([sqrtf]) + LIBS="$save_LIBS" + if test $ac_cv_func_sqrtf = yes; then + SQRTF_LIBM="$SQRT_LIBM" + else + HAVE_SQRTF=0 + SQRTF_LIBM="$SQRT_LIBM" + fi + AC_SUBST([SQRTF_LIBM]) +]) diff --git a/modules/math b/modules/math index 6d8da2ed9..57647eee6 100644 --- a/modules/math +++ b/modules/math @@ -60,6 +60,7 @@ math.h: math.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $( -e 's/@''GNULIB_ROUNDL''@/$(GNULIB_ROUNDL)/g' \ -e 's/@''GNULIB_SIGNBIT''@/$(GNULIB_SIGNBIT)/g' \ -e 's/@''GNULIB_SINL''@/$(GNULIB_SINL)/g' \ + -e 's/@''GNULIB_SQRTF''@/$(GNULIB_SQRTF)/g' \ -e 's/@''GNULIB_SQRTL''@/$(GNULIB_SQRTL)/g' \ -e 's/@''GNULIB_TANL''@/$(GNULIB_TANL)/g' \ -e 's/@''GNULIB_TRUNC''@/$(GNULIB_TRUNC)/g' \ @@ -81,6 +82,7 @@ math.h: math.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $( -e 's|@''HAVE_LOGL''@|$(HAVE_LOGL)|g' \ -e 's|@''HAVE_MODFF''@|$(HAVE_MODFF)|g' \ -e 's|@''HAVE_SINL''@|$(HAVE_SINL)|g' \ + -e 's|@''HAVE_SQRTF''@|$(HAVE_SQRTF)|g' \ -e 's|@''HAVE_SQRTL''@|$(HAVE_SQRTL)|g' \ -e 's|@''HAVE_TANL''@|$(HAVE_TANL)|g' \ -e 's|@''HAVE_DECL_ACOSL''@|$(HAVE_DECL_ACOSL)|g' \ diff --git a/modules/sqrtf b/modules/sqrtf new file mode 100644 index 000000000..412364956 --- /dev/null +++ b/modules/sqrtf @@ -0,0 +1,31 @@ +Description: +sqrtf() function: square root. + +Files: +lib/sqrtf.c +m4/sqrtf.m4 + +Depends-on: +math +sqrt [test $HAVE_SQRTF = 0] + +configure.ac: +gl_FUNC_SQRTF +if test $HAVE_SQRTF = 0; then + AC_LIBOBJ([sqrtf]) +fi +gl_MATH_MODULE_INDICATOR([sqrtf]) + +Makefile.am: + +Include: + + +Link: +$(SQRTF_LIBM) + +License: +LGPL + +Maintainer: +Bruno Haible diff --git a/tests/test-math-c++.cc b/tests/test-math-c++.cc index 25b7697a1..e04904ec8 100644 --- a/tests/test-math-c++.cc +++ b/tests/test-math-c++.cc @@ -72,6 +72,9 @@ SIGNATURE_CHECK (GNULIB_NAMESPACE::modff, float, (float, float *)); //SIGNATURE_CHECK (GNULIB_NAMESPACE::rint, double, (double)); //SIGNATURE_CHECK (GNULIB_NAMESPACE::sin, double, (double)); //SIGNATURE_CHECK (GNULIB_NAMESPACE::sinh, double, (double)); +#if GNULIB_TEST_SQRTF +SIGNATURE_CHECK (GNULIB_NAMESPACE::sqrtf, float, (float)); +#endif //SIGNATURE_CHECK (GNULIB_NAMESPACE::sqrt, double, (double)); //SIGNATURE_CHECK (GNULIB_NAMESPACE::tan, double, (double)); //SIGNATURE_CHECK (GNULIB_NAMESPACE::tanh, double, (double));