From f96458bc2604b8ce5f632387d2d948287376b023 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Sun, 9 Oct 2011 15:42:35 +0200 Subject: [PATCH] New module 'copysignf'. * lib/math.in.h (copysignf): New declaration. * lib/copysignf.c: New file. * m4/copysignf.m4: New file. * m4/math_h.m4 (gl_MATH_H): Test whether copysignf is declared. (gl_MATH_H_DEFAULTS): Initialize GNULIB_COPYSIGNF, HAVE_COPYSIGNF. * modules/math (Makefile.am): Substitute GNULIB_COPYSIGNF, HAVE_COPYSIGNF. * modules/copysignf: New file. * tests/test-math-c++.cc: Check the declaration of copysignf. * doc/posix-functions/copysignf.texi: Mention the new module. --- ChangeLog | 14 +++++ doc/posix-functions/copysignf.texi | 8 +-- lib/copysignf.c | 26 +++++++++ lib/math.in.h | 44 ++++++++++----- m4/copysignf.m4 | 19 +++++++ m4/math_h.m4 | 113 +++++++++++++++++++------------------ modules/copysignf | 32 +++++++++++ modules/math | 2 + tests/test-math-c++.cc | 3 + 9 files changed, 187 insertions(+), 74 deletions(-) create mode 100644 lib/copysignf.c create mode 100644 m4/copysignf.m4 create mode 100644 modules/copysignf diff --git a/ChangeLog b/ChangeLog index be2b20bd7..1ff29a683 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,19 @@ 2011-10-09 Bruno Haible + New module 'copysignf'. + * lib/math.in.h (copysignf): New declaration. + * lib/copysignf.c: New file. + * m4/copysignf.m4: New file. + * m4/math_h.m4 (gl_MATH_H): Test whether copysignf is declared. + (gl_MATH_H_DEFAULTS): Initialize GNULIB_COPYSIGNF, HAVE_COPYSIGNF. + * modules/math (Makefile.am): Substitute GNULIB_COPYSIGNF, + HAVE_COPYSIGNF. + * modules/copysignf: New file. + * tests/test-math-c++.cc: Check the declaration of copysignf. + * doc/posix-functions/copysignf.texi: Mention the new module. + +2011-10-09 Bruno Haible + Ensure that HAVE_* variables are set to 1 before they are set to 0. * m4/fdopendir.m4 (gl_FUNC_FDOPENDIR): Require gl_DIRENT_H_DEFAULTS. * m4/inet_ntop.m4 (gl_FUNC_INET_NTOP): Require gl_ARPA_INET_H_DEFAULTS. diff --git a/doc/posix-functions/copysignf.texi b/doc/posix-functions/copysignf.texi index 01f2762c3..5c3154f69 100644 --- a/doc/posix-functions/copysignf.texi +++ b/doc/posix-functions/copysignf.texi @@ -4,15 +4,15 @@ POSIX specification:@* @url{http://www.opengroup.org/onlinepubs/9699919799/functions/copysignf.html} -Gnulib module: --- +Gnulib module: copysignf Portability problems fixed by Gnulib: @itemize +@item +This function is missing on some platforms: +Minix 3.1.8, AIX 5.1, IRIX 6.5, Solaris 9, MSVC 9. @end itemize Portability problems not fixed by Gnulib: @itemize -@item -This function is missing on some platforms: -Minix 3.1.8, AIX 5.1, IRIX 6.5, Solaris 9, MSVC 9. @end itemize diff --git a/lib/copysignf.c b/lib/copysignf.c new file mode 100644 index 000000000..82409d4d9 --- /dev/null +++ b/lib/copysignf.c @@ -0,0 +1,26 @@ +/* Copy sign into another 'float' number. + 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 +copysignf (float x, float y) +{ + return (signbit (x) != signbit (y) ? - x : x); +} diff --git a/lib/math.in.h b/lib/math.in.h index e14ea15b9..37f9a2fb8 100644 --- a/lib/math.in.h +++ b/lib/math.in.h @@ -274,6 +274,35 @@ _GL_WARN_ON_USE (ceill, "ceill is unportable - " #endif +#if @GNULIB_COPYSIGNF@ +# if !@HAVE_COPYSIGNF@ +_GL_FUNCDECL_SYS (copysignf, float, (float x, float y)); +# endif +_GL_CXXALIAS_SYS (copysignf, float, (float x, float y)); +_GL_CXXALIASWARN (copysignf); +#elif defined GNULIB_POSIXCHECK +# undef copysignf +# if HAVE_RAW_DECL_COPYSIGNF +_GL_WARN_ON_USE (copysignf, "copysignf is unportable - " + "use gnulib module copysignf for portability"); +# endif +#endif + +#if @GNULIB_COPYSIGN@ +# if !@HAVE_COPYSIGN@ +_GL_FUNCDECL_SYS (copysign, double, (double x, double y)); +# endif +_GL_CXXALIAS_SYS (copysign, double, (double x, double y)); +_GL_CXXALIASWARN (copysign); +#elif defined GNULIB_POSIXCHECK +# undef copysign +# if HAVE_RAW_DECL_COPYSIGN +_GL_WARN_ON_USE (copysign, "copysign is unportable - " + "use gnulib module copysign for portability"); +# endif +#endif + + #if @GNULIB_COSF@ # if !@HAVE_COSF@ # undef cosf @@ -320,21 +349,6 @@ _GL_WARN_ON_USE (coshf, "coshf is unportable - " #endif -#if @GNULIB_COPYSIGN@ -# if !@HAVE_COPYSIGN@ -_GL_FUNCDECL_SYS (copysign, double, (double x, double y)); -# endif -_GL_CXXALIAS_SYS (copysign, double, (double x, double y)); -_GL_CXXALIASWARN (copysign); -#elif defined GNULIB_POSIXCHECK -# undef copysign -# if HAVE_RAW_DECL_COPYSIGN -_GL_WARN_ON_USE (copysign, "copysign is unportable - " - "use gnulib module copysign for portability"); -# endif -#endif - - #if @GNULIB_EXPF@ # if !@HAVE_EXPF@ # undef expf diff --git a/m4/copysignf.m4 b/m4/copysignf.m4 new file mode 100644 index 000000000..00c1fe14b --- /dev/null +++ b/m4/copysignf.m4 @@ -0,0 +1,19 @@ +# copysignf.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_COPYSIGNF], +[ + AC_REQUIRE([gl_MATH_H_DEFAULTS]) + + dnl Determine COPYSIGNF_LIBM. + gl_MATHFUNC([copysignf], [float], [(float, float)]) + if test $gl_cv_func_copysignf_no_libm = no \ + && test $gl_cv_func_copysignf_in_libm = no; then + HAVE_COPYSIGNF=0 + COPYSIGNF_LIBM= + fi + AC_SUBST([COPYSIGNF_LIBM]) +]) diff --git a/m4/math_h.m4 b/m4/math_h.m4 index 240415325..4d5105b12 100644 --- a/m4/math_h.m4 +++ b/m4/math_h.m4 @@ -1,4 +1,4 @@ -# math_h.m4 serial 48 +# math_h.m4 serial 49 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, @@ -39,7 +39,8 @@ AC_DEFUN([gl_MATH_H], dnl Check for declarations of anything we want to poison if the dnl corresponding gnulib module is not in use. gl_WARN_ON_USE_PREPARE([[#include ]], - [acosf acosl asinf asinl atanf atanl ceilf ceill copysign cosf cosl coshf + [acosf acosl asinf asinl atanf atanl + ceilf ceill copysign copysignf cosf cosl coshf expf expl fabsf floorf floorl fmodf frexpf frexpl ldexpf ldexpl logb logf logl log10f modff powf round roundf roundl sinf sinl sinhf sqrtf sqrtl @@ -57,59 +58,60 @@ AC_DEFUN([gl_MATH_MODULE_INDICATOR], AC_DEFUN([gl_MATH_H_DEFAULTS], [ - GNULIB_ACOSF=0; AC_SUBST([GNULIB_ACOSF]) - GNULIB_ACOSL=0; AC_SUBST([GNULIB_ACOSL]) - GNULIB_ASINF=0; AC_SUBST([GNULIB_ASINF]) - 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]) - GNULIB_COPYSIGN=0; AC_SUBST([GNULIB_COPYSIGN]) - GNULIB_COSF=0; AC_SUBST([GNULIB_COSF]) - GNULIB_COSL=0; AC_SUBST([GNULIB_COSL]) - GNULIB_COSHF=0; AC_SUBST([GNULIB_COSHF]) - GNULIB_EXPF=0; AC_SUBST([GNULIB_EXPF]) - GNULIB_EXPL=0; AC_SUBST([GNULIB_EXPL]) - GNULIB_FABSF=0; AC_SUBST([GNULIB_FABSF]) - GNULIB_FLOOR=0; AC_SUBST([GNULIB_FLOOR]) - GNULIB_FLOORF=0; AC_SUBST([GNULIB_FLOORF]) - GNULIB_FLOORL=0; AC_SUBST([GNULIB_FLOORL]) - GNULIB_FMODF=0; AC_SUBST([GNULIB_FMODF]) - GNULIB_FREXPF=0; AC_SUBST([GNULIB_FREXPF]) - GNULIB_FREXP=0; AC_SUBST([GNULIB_FREXP]) - GNULIB_FREXPL=0; AC_SUBST([GNULIB_FREXPL]) - GNULIB_ISFINITE=0; AC_SUBST([GNULIB_ISFINITE]) - GNULIB_ISINF=0; AC_SUBST([GNULIB_ISINF]) - GNULIB_ISNAN=0; AC_SUBST([GNULIB_ISNAN]) - GNULIB_ISNANF=0; AC_SUBST([GNULIB_ISNANF]) - GNULIB_ISNAND=0; AC_SUBST([GNULIB_ISNAND]) - GNULIB_ISNANL=0; AC_SUBST([GNULIB_ISNANL]) - GNULIB_LDEXPF=0; AC_SUBST([GNULIB_LDEXPF]) - GNULIB_LDEXPL=0; AC_SUBST([GNULIB_LDEXPL]) - GNULIB_LOGB=0; AC_SUBST([GNULIB_LOGB]) - GNULIB_LOGF=0; AC_SUBST([GNULIB_LOGF]) - GNULIB_LOGL=0; AC_SUBST([GNULIB_LOGL]) - GNULIB_LOG10F=0; AC_SUBST([GNULIB_LOG10F]) - GNULIB_MODFF=0; AC_SUBST([GNULIB_MODFF]) - GNULIB_POWF=0; AC_SUBST([GNULIB_POWF]) - GNULIB_ROUND=0; AC_SUBST([GNULIB_ROUND]) - GNULIB_ROUNDF=0; AC_SUBST([GNULIB_ROUNDF]) - GNULIB_ROUNDL=0; AC_SUBST([GNULIB_ROUNDL]) - GNULIB_SIGNBIT=0; AC_SUBST([GNULIB_SIGNBIT]) - GNULIB_SINF=0; AC_SUBST([GNULIB_SINF]) - GNULIB_SINL=0; AC_SUBST([GNULIB_SINL]) - GNULIB_SINHF=0; AC_SUBST([GNULIB_SINHF]) - GNULIB_SQRTF=0; AC_SUBST([GNULIB_SQRTF]) - 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]) + GNULIB_ACOSF=0; AC_SUBST([GNULIB_ACOSF]) + GNULIB_ACOSL=0; AC_SUBST([GNULIB_ACOSL]) + GNULIB_ASINF=0; AC_SUBST([GNULIB_ASINF]) + 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]) + GNULIB_COPYSIGN=0; AC_SUBST([GNULIB_COPYSIGN]) + GNULIB_COPYSIGNF=0; AC_SUBST([GNULIB_COPYSIGNF]) + GNULIB_COSF=0; AC_SUBST([GNULIB_COSF]) + GNULIB_COSL=0; AC_SUBST([GNULIB_COSL]) + GNULIB_COSHF=0; AC_SUBST([GNULIB_COSHF]) + GNULIB_EXPF=0; AC_SUBST([GNULIB_EXPF]) + GNULIB_EXPL=0; AC_SUBST([GNULIB_EXPL]) + GNULIB_FABSF=0; AC_SUBST([GNULIB_FABSF]) + GNULIB_FLOOR=0; AC_SUBST([GNULIB_FLOOR]) + GNULIB_FLOORF=0; AC_SUBST([GNULIB_FLOORF]) + GNULIB_FLOORL=0; AC_SUBST([GNULIB_FLOORL]) + GNULIB_FMODF=0; AC_SUBST([GNULIB_FMODF]) + GNULIB_FREXPF=0; AC_SUBST([GNULIB_FREXPF]) + GNULIB_FREXP=0; AC_SUBST([GNULIB_FREXP]) + GNULIB_FREXPL=0; AC_SUBST([GNULIB_FREXPL]) + GNULIB_ISFINITE=0; AC_SUBST([GNULIB_ISFINITE]) + GNULIB_ISINF=0; AC_SUBST([GNULIB_ISINF]) + GNULIB_ISNAN=0; AC_SUBST([GNULIB_ISNAN]) + GNULIB_ISNANF=0; AC_SUBST([GNULIB_ISNANF]) + GNULIB_ISNAND=0; AC_SUBST([GNULIB_ISNAND]) + GNULIB_ISNANL=0; AC_SUBST([GNULIB_ISNANL]) + GNULIB_LDEXPF=0; AC_SUBST([GNULIB_LDEXPF]) + GNULIB_LDEXPL=0; AC_SUBST([GNULIB_LDEXPL]) + GNULIB_LOGB=0; AC_SUBST([GNULIB_LOGB]) + GNULIB_LOGF=0; AC_SUBST([GNULIB_LOGF]) + GNULIB_LOGL=0; AC_SUBST([GNULIB_LOGL]) + GNULIB_LOG10F=0; AC_SUBST([GNULIB_LOG10F]) + GNULIB_MODFF=0; AC_SUBST([GNULIB_MODFF]) + GNULIB_POWF=0; AC_SUBST([GNULIB_POWF]) + GNULIB_ROUND=0; AC_SUBST([GNULIB_ROUND]) + GNULIB_ROUNDF=0; AC_SUBST([GNULIB_ROUNDF]) + GNULIB_ROUNDL=0; AC_SUBST([GNULIB_ROUNDL]) + GNULIB_SIGNBIT=0; AC_SUBST([GNULIB_SIGNBIT]) + GNULIB_SINF=0; AC_SUBST([GNULIB_SINF]) + GNULIB_SINL=0; AC_SUBST([GNULIB_SINL]) + GNULIB_SINHF=0; AC_SUBST([GNULIB_SINHF]) + GNULIB_SQRTF=0; AC_SUBST([GNULIB_SQRTF]) + 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]) dnl Assume proper GNU behavior unless another module says otherwise. HAVE_ACOSF=1; AC_SUBST([HAVE_ACOSF]) HAVE_ACOSL=1; AC_SUBST([HAVE_ACOSL]) @@ -119,6 +121,7 @@ AC_DEFUN([gl_MATH_H_DEFAULTS], HAVE_ATANL=1; AC_SUBST([HAVE_ATANL]) HAVE_ATAN2F=1; AC_SUBST([HAVE_ATAN2F]) HAVE_COPYSIGN=1; AC_SUBST([HAVE_COPYSIGN]) + HAVE_COPYSIGNF=1; AC_SUBST([HAVE_COPYSIGNF]) HAVE_COSF=1; AC_SUBST([HAVE_COSF]) HAVE_COSL=1; AC_SUBST([HAVE_COSL]) HAVE_COSHF=1; AC_SUBST([HAVE_COSHF]) diff --git a/modules/copysignf b/modules/copysignf new file mode 100644 index 000000000..a446046ca --- /dev/null +++ b/modules/copysignf @@ -0,0 +1,32 @@ +Description: +copysignf() function: copy sign into another 'float' number. + +Files: +lib/copysignf.c +m4/copysignf.m4 +m4/mathfunc.m4 + +Depends-on: +math +signbit [test $HAVE_COPYSIGNF = 0] + +configure.ac: +gl_FUNC_COPYSIGNF +if test $HAVE_COPYSIGNF = 0; then + AC_LIBOBJ([copysignf]) +fi +gl_MATH_MODULE_INDICATOR([copysignf]) + +Makefile.am: + +Include: + + +Link: +$(COPYSIGNF_LIBM) + +License: +LGPL + +Maintainer: +Bruno Haible diff --git a/modules/math b/modules/math index a76abcfbd..c0c3a88e7 100644 --- a/modules/math +++ b/modules/math @@ -39,6 +39,7 @@ math.h: math.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $( -e 's/@''GNULIB_CEILF''@/$(GNULIB_CEILF)/g' \ -e 's/@''GNULIB_CEILL''@/$(GNULIB_CEILL)/g' \ -e 's/@''GNULIB_COPYSIGN''@/$(GNULIB_COPYSIGN)/g' \ + -e 's/@''GNULIB_COPYSIGNF''@/$(GNULIB_COPYSIGNF)/g' \ -e 's/@''GNULIB_COSF''@/$(GNULIB_COSF)/g' \ -e 's/@''GNULIB_COSL''@/$(GNULIB_COSL)/g' \ -e 's/@''GNULIB_COSHF''@/$(GNULIB_COSHF)/g' \ @@ -90,6 +91,7 @@ math.h: math.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $( -e 's|@''HAVE_ATANL''@|$(HAVE_ATANL)|g' \ -e 's|@''HAVE_ATAN2F''@|$(HAVE_ATAN2F)|g' \ -e 's|@''HAVE_COPYSIGN''@|$(HAVE_COPYSIGN)|g' \ + -e 's|@''HAVE_COPYSIGNF''@|$(HAVE_COPYSIGNF)|g' \ -e 's|@''HAVE_COSF''@|$(HAVE_COSF)|g' \ -e 's|@''HAVE_COSL''@|$(HAVE_COSL)|g' \ -e 's|@''HAVE_COSHF''@|$(HAVE_COSHF)|g' \ diff --git a/tests/test-math-c++.cc b/tests/test-math-c++.cc index 7ae1ea190..b519992f3 100644 --- a/tests/test-math-c++.cc +++ b/tests/test-math-c++.cc @@ -41,6 +41,9 @@ SIGNATURE_CHECK (GNULIB_NAMESPACE::atan2f, float, (float, float)); #endif //SIGNATURE_CHECK (GNULIB_NAMESPACE::atan2, double, (double, double)); //SIGNATURE_CHECK (GNULIB_NAMESPACE::cbrt, double, (double)); +#if GNULIB_TEST_COPYSIGNF +SIGNATURE_CHECK (GNULIB_NAMESPACE::copysignf, float, (float, float)); +#endif #if GNULIB_TEST_COPYSIGN SIGNATURE_CHECK (GNULIB_NAMESPACE::copysign, double, (double, double)); #endif -- 2.11.0