From a365e1e5d3afa9a9f12d38eacaade8cd8fe0020e Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Sun, 9 Oct 2011 00:31:51 +0200 Subject: [PATCH] New module 'atan2f'. * lib/math.in.h (atan2f): New declaration. * lib/atan2f.c: New file. * m4/atan2f.m4: New file. * m4/math_h.m4 (gl_MATH_H): Test whether atan2f is declared. (gl_MATH_H_DEFAULTS): Initialize GNULIB_ATAN2F, HAVE_ATAN2F. * modules/math (Makefile.am): Substitute GNULIB_ATAN2F, HAVE_ATAN2F. * modules/atan2f: New file. * tests/test-math-c++.cc: Check the declaration of atan2f. * doc/posix-functions/atan2f.texi: Mention the new module. --- ChangeLog | 11 +++++++++++ doc/posix-functions/atan2f.texi | 10 +++++----- lib/atan2f.c | 26 ++++++++++++++++++++++++++ lib/math.in.h | 16 ++++++++++++++++ m4/atan2f.m4 | 25 +++++++++++++++++++++++++ m4/math_h.m4 | 4 +++- modules/atan2f | 31 +++++++++++++++++++++++++++++++ modules/math | 2 ++ tests/test-math-c++.cc | 3 +++ 9 files changed, 122 insertions(+), 6 deletions(-) create mode 100644 lib/atan2f.c create mode 100644 m4/atan2f.m4 create mode 100644 modules/atan2f diff --git a/ChangeLog b/ChangeLog index 4f1fdbdaa..f8a5a7306 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,16 @@ 2011-10-08 Bruno Haible + New module 'atan2f'. + * lib/math.in.h (atan2f): New declaration. + * lib/atan2f.c: New file. + * m4/atan2f.m4: New file. + * m4/math_h.m4 (gl_MATH_H): Test whether atan2f is declared. + (gl_MATH_H_DEFAULTS): Initialize GNULIB_ATAN2F, HAVE_ATAN2F. + * modules/math (Makefile.am): Substitute GNULIB_ATAN2F, HAVE_ATAN2F. + * modules/atan2f: New file. + * tests/test-math-c++.cc: Check the declaration of atan2f. + * doc/posix-functions/atan2f.texi: Mention the new module. + atan2: Use a .m4 file. * m4/atan2.m4: New file. * modules/atan2 (Files): Add it. diff --git a/doc/posix-functions/atan2f.texi b/doc/posix-functions/atan2f.texi index 817f20b0a..14f180cdc 100644 --- a/doc/posix-functions/atan2f.texi +++ b/doc/posix-functions/atan2f.texi @@ -4,14 +4,10 @@ POSIX specification:@* @url{http://www.opengroup.org/onlinepubs/9699919799/functions/atan2f.html} -Gnulib module: --- +Gnulib module: atan2f 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/atan2f.c b/lib/atan2f.c new file mode 100644 index 000000000..09771f6a3 --- /dev/null +++ b/lib/atan2f.c @@ -0,0 +1,26 @@ +/* Angle of a point in the plane. + 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 +atan2f (float y, float x) +{ + return (float) atan2 ((double) y, (double) x); +} diff --git a/lib/math.in.h b/lib/math.in.h index 94076815a..512425cb1 100644 --- a/lib/math.in.h +++ b/lib/math.in.h @@ -198,6 +198,22 @@ _GL_WARN_ON_USE (atanl, "atanl is unportable - " #endif +#if @GNULIB_ATAN2F@ +# if !@HAVE_ATAN2F@ +# undef atan2f +_GL_FUNCDECL_SYS (atan2f, float, (float y, float x)); +# endif +_GL_CXXALIAS_SYS (atan2f, float, (float y, float x)); +_GL_CXXALIASWARN (atan2f); +#elif defined GNULIB_POSIXCHECK +# undef atan2f +# if HAVE_RAW_DECL_ATAN2F +_GL_WARN_ON_USE (atan2f, "atan2f is unportable - " + "use gnulib module atan2f for portability"); +# endif +#endif + + #if @GNULIB_CEILF@ # if @REPLACE_CEILF@ # if !(defined __cplusplus && defined GNULIB_NAMESPACE) diff --git a/m4/atan2f.m4 b/m4/atan2f.m4 new file mode 100644 index 000000000..34aeb59bb --- /dev/null +++ b/m4/atan2f.m4 @@ -0,0 +1,25 @@ +# atan2f.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_ATAN2F], +[ + AC_REQUIRE([gl_MATH_H_DEFAULTS]) + AC_REQUIRE([gl_FUNC_ATAN2]) + + dnl Test whether atan2f() exists. Assume that atan2f(), if it exists, is + dnl defined in the same library as atan2(). + save_LIBS="$LIBS" + LIBS="$LIBS $ATAN2_LIBM" + AC_CHECK_FUNCS([atan2f]) + LIBS="$save_LIBS" + if test $ac_cv_func_atan2f = yes; then + ATAN2F_LIBM="$ATAN2_LIBM" + else + HAVE_ATAN2F=0 + ATAN2F_LIBM="$ATAN2_LIBM" + fi + AC_SUBST([ATAN2F_LIBM]) +]) diff --git a/m4/math_h.m4 b/m4/math_h.m4 index 81f382d7f..79c0ae1aa 100644 --- a/m4/math_h.m4 +++ b/m4/math_h.m4 @@ -1,4 +1,4 @@ -# math_h.m4 serial 42 +# math_h.m4 serial 43 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, @@ -63,6 +63,7 @@ AC_DEFUN([gl_MATH_H_DEFAULTS], GNULIB_ASINL=0; AC_SUBST([GNULIB_ASINL]) GNULIB_ATANF=0; AC_SUBST([GNULIB_ATANF]) GNULIB_ATANL=0; AC_SUBST([GNULIB_ATANL]) + GNULIB_ATAN2F=0; AC_SUBST([GNULIB_ATAN2F]) GNULIB_CEIL=0; AC_SUBST([GNULIB_CEIL]) GNULIB_CEILF=0; AC_SUBST([GNULIB_CEILF]) GNULIB_CEILL=0; AC_SUBST([GNULIB_CEILL]) @@ -112,6 +113,7 @@ AC_DEFUN([gl_MATH_H_DEFAULTS], HAVE_ASINL=1; AC_SUBST([HAVE_ASINL]) HAVE_ATANF=1; AC_SUBST([HAVE_ATANF]) HAVE_ATANL=1; AC_SUBST([HAVE_ATANL]) + HAVE_ATAN2F=1; AC_SUBST([HAVE_ATAN2F]) HAVE_COSF=1; AC_SUBST([HAVE_COSF]) HAVE_COSL=1; AC_SUBST([HAVE_COSL]) HAVE_EXPF=1; AC_SUBST([HAVE_EXPF]) diff --git a/modules/atan2f b/modules/atan2f new file mode 100644 index 000000000..f2d7dc65e --- /dev/null +++ b/modules/atan2f @@ -0,0 +1,31 @@ +Description: +atan2f() function: angle of a point in the plane. + +Files: +lib/atan2f.c +m4/atan2f.m4 + +Depends-on: +math +atan2 [test $HAVE_ATAN2F = 0] + +configure.ac: +gl_FUNC_ATAN2F +if test $HAVE_ATAN2F = 0; then + AC_LIBOBJ([atan2f]) +fi +gl_MATH_MODULE_INDICATOR([atan2f]) + +Makefile.am: + +Include: + + +Link: +$(ATAN2F_LIBM) + +License: +LGPL + +Maintainer: +Bruno Haible diff --git a/modules/math b/modules/math index 9a9181fbd..4cd261d86 100644 --- a/modules/math +++ b/modules/math @@ -34,6 +34,7 @@ math.h: math.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $( -e 's/@''GNULIB_ASINL''@/$(GNULIB_ASINL)/g' \ -e 's/@''GNULIB_ATANF''@/$(GNULIB_ATANF)/g' \ -e 's/@''GNULIB_ATANL''@/$(GNULIB_ATANL)/g' \ + -e 's/@''GNULIB_ATAN2F''@/$(GNULIB_ATAN2F)/g' \ -e 's/@''GNULIB_CEIL''@/$(GNULIB_CEIL)/g' \ -e 's/@''GNULIB_CEILF''@/$(GNULIB_CEILF)/g' \ -e 's/@''GNULIB_CEILL''@/$(GNULIB_CEILL)/g' \ @@ -83,6 +84,7 @@ math.h: math.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $( -e 's|@''HAVE_ASINL''@|$(HAVE_ASINL)|g' \ -e 's|@''HAVE_ATANF''@|$(HAVE_ATANF)|g' \ -e 's|@''HAVE_ATANL''@|$(HAVE_ATANL)|g' \ + -e 's|@''HAVE_ATAN2F''@|$(HAVE_ATAN2F)|g' \ -e 's|@''HAVE_COSF''@|$(HAVE_COSF)|g' \ -e 's|@''HAVE_COSL''@|$(HAVE_COSL)|g' \ -e 's|@''HAVE_EXPF''@|$(HAVE_EXPF)|g' \ diff --git a/tests/test-math-c++.cc b/tests/test-math-c++.cc index d0f8c6e91..a26a86ffb 100644 --- a/tests/test-math-c++.cc +++ b/tests/test-math-c++.cc @@ -36,6 +36,9 @@ SIGNATURE_CHECK (GNULIB_NAMESPACE::asinf, float, (float)); SIGNATURE_CHECK (GNULIB_NAMESPACE::atanf, float, (float)); #endif //SIGNATURE_CHECK (GNULIB_NAMESPACE::atan, double, (double)); +#if GNULIB_TEST_ATAN2F +SIGNATURE_CHECK (GNULIB_NAMESPACE::atan2f, float, (float, float)); +#endif //SIGNATURE_CHECK (GNULIB_NAMESPACE::atan2, double, (double, double)); //SIGNATURE_CHECK (GNULIB_NAMESPACE::cbrt, double, (double)); //SIGNATURE_CHECK (GNULIB_NAMESPACE::copysign, double, (double, double)); -- 2.11.0