From: Bruno Haible Date: Sun, 9 Oct 2011 12:44:58 +0000 (+0200) Subject: copysign: Provide replacement. X-Git-Tag: v0.1~1618 X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=5835ba726cff8bff6b8d83d407d72ab723dbcece;p=gnulib.git copysign: Provide replacement. * lib/math.in.h (copysign): New declaration. * lib/copysign.c: New file. * m4/copysign.m4: New file. * m4/math_h.m4 (gl_MATH_H): Test whether copysign is declared. (gl_MATH_H_DEFAULTS): Initialize GNULIB_COPYSIGN, HAVE_COPYSIGN. * modules/math (Makefile.am): Substitute GNULIB_COPYSIGN, HAVE_COPYSIGN. * modules/copysign (Description): Clarify. (Files): Add lib/copysign.c, m4/copysign.m4. (Depends-on): Add math, signbit. (configure.ac): Invoke gl_FUNC_COPYSIGN, AC_LIBOBJ, gl_MATH_MODULE_INDICATOR. * tests/test-math-c++.cc: Check the declaration of copysign. * doc/posix-functions/copysign.texi: Mention the effects of the module on Minix and MSVC. --- diff --git a/ChangeLog b/ChangeLog index 362fdf434e..e27cfc1aa9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,22 @@ +2011-10-09 Bruno Haible + + copysign: Provide replacement. + * lib/math.in.h (copysign): New declaration. + * lib/copysign.c: New file. + * m4/copysign.m4: New file. + * m4/math_h.m4 (gl_MATH_H): Test whether copysign is declared. + (gl_MATH_H_DEFAULTS): Initialize GNULIB_COPYSIGN, HAVE_COPYSIGN. + * modules/math (Makefile.am): Substitute GNULIB_COPYSIGN, + HAVE_COPYSIGN. + * modules/copysign (Description): Clarify. + (Files): Add lib/copysign.c, m4/copysign.m4. + (Depends-on): Add math, signbit. + (configure.ac): Invoke gl_FUNC_COPYSIGN, AC_LIBOBJ, + gl_MATH_MODULE_INDICATOR. + * tests/test-math-c++.cc: Check the declaration of copysign. + * doc/posix-functions/copysign.texi: Mention the effects of the module + on Minix and MSVC. + 2011-10-09 Bruno Haible isinf: Ensure macro on AIX 5.1. diff --git a/doc/posix-functions/copysign.texi b/doc/posix-functions/copysign.texi index 3533e2b80b..dbacb0db52 100644 --- a/doc/posix-functions/copysign.texi +++ b/doc/posix-functions/copysign.texi @@ -8,11 +8,11 @@ Gnulib module: copysign Portability problems fixed by Gnulib: @itemize +@item +This function is missing on some platforms: +Minix 3.1.8, MSVC 9. @end itemize Portability problems not fixed by Gnulib: @itemize -@item -This function is missing on some platforms: -Minix 3.1.8, MSVC 9. @end itemize diff --git a/lib/copysign.c b/lib/copysign.c new file mode 100644 index 0000000000..5480245768 --- /dev/null +++ b/lib/copysign.c @@ -0,0 +1,26 @@ +/* Copy sign into another 'double' 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 + +double +copysign (double x, double y) +{ + return (signbit (x) != signbit (y) ? - x : x); +} diff --git a/lib/math.in.h b/lib/math.in.h index a637658242..e14ea15b98 100644 --- a/lib/math.in.h +++ b/lib/math.in.h @@ -320,6 +320,21 @@ _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/copysign.m4 b/m4/copysign.m4 new file mode 100644 index 0000000000..15c9bc60c3 --- /dev/null +++ b/m4/copysign.m4 @@ -0,0 +1,19 @@ +# copysign.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_COPYSIGN], +[ + AC_REQUIRE([gl_MATH_H_DEFAULTS]) + + dnl Determine COPYSIGN_LIBM. + gl_MATHFUNC([copysign], [double], [(double, double)]) + if test $gl_cv_func_copysign_no_libm = no \ + && test $gl_cv_func_copysign_in_libm = no; then + HAVE_COPYSIGN=0 + COPYSIGN_LIBM= + fi + AC_SUBST([COPYSIGN_LIBM]) +]) diff --git a/m4/math_h.m4 b/m4/math_h.m4 index 1088d1632e..2404153259 100644 --- a/m4/math_h.m4 +++ b/m4/math_h.m4 @@ -1,4 +1,4 @@ -# math_h.m4 serial 47 +# math_h.m4 serial 48 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,7 @@ 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 cosf cosl coshf + [acosf acosl asinf asinl atanf atanl ceilf ceill copysign 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 @@ -67,6 +67,7 @@ AC_DEFUN([gl_MATH_H_DEFAULTS], 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]) @@ -117,6 +118,7 @@ AC_DEFUN([gl_MATH_H_DEFAULTS], HAVE_ATANF=1; AC_SUBST([HAVE_ATANF]) HAVE_ATANL=1; AC_SUBST([HAVE_ATANL]) HAVE_ATAN2F=1; AC_SUBST([HAVE_ATAN2F]) + HAVE_COPYSIGN=1; AC_SUBST([HAVE_COPYSIGN]) 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/copysign b/modules/copysign index 5318e80271..656aa5017b 100644 --- a/modules/copysign +++ b/modules/copysign @@ -1,13 +1,21 @@ Description: -copysign() function: copy sign. +copysign() function: copy sign into another 'double' number. Files: +lib/copysign.c +m4/copysign.m4 m4/mathfunc.m4 Depends-on: +math +signbit [test $HAVE_COPYSIGN = 0] configure.ac: -gl_MATHFUNC([copysign], [double], [(double, double)]) +gl_FUNC_COPYSIGN +if test $HAVE_COPYSIGN = 0; then + AC_LIBOBJ([copysign]) +fi +gl_MATH_MODULE_INDICATOR([copysign]) Makefile.am: diff --git a/modules/math b/modules/math index 9c6f999f92..a76abcfbd9 100644 --- a/modules/math +++ b/modules/math @@ -38,6 +38,7 @@ math.h: math.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $( -e 's/@''GNULIB_CEIL''@/$(GNULIB_CEIL)/g' \ -e 's/@''GNULIB_CEILF''@/$(GNULIB_CEILF)/g' \ -e 's/@''GNULIB_CEILL''@/$(GNULIB_CEILL)/g' \ + -e 's/@''GNULIB_COPYSIGN''@/$(GNULIB_COPYSIGN)/g' \ -e 's/@''GNULIB_COSF''@/$(GNULIB_COSF)/g' \ -e 's/@''GNULIB_COSL''@/$(GNULIB_COSL)/g' \ -e 's/@''GNULIB_COSHF''@/$(GNULIB_COSHF)/g' \ @@ -88,6 +89,7 @@ math.h: math.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $( -e 's|@''HAVE_ATANF''@|$(HAVE_ATANF)|g' \ -e 's|@''HAVE_ATANL''@|$(HAVE_ATANL)|g' \ -e 's|@''HAVE_ATAN2F''@|$(HAVE_ATAN2F)|g' \ + -e 's|@''HAVE_COPYSIGN''@|$(HAVE_COPYSIGN)|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 d786273c42..7ae1ea190f 100644 --- a/tests/test-math-c++.cc +++ b/tests/test-math-c++.cc @@ -41,7 +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)); -//SIGNATURE_CHECK (GNULIB_NAMESPACE::copysign, double, (double, double)); +#if GNULIB_TEST_COPYSIGN +SIGNATURE_CHECK (GNULIB_NAMESPACE::copysign, double, (double, double)); +#endif #if GNULIB_TEST_COSF SIGNATURE_CHECK (GNULIB_NAMESPACE::cosf, float, (float)); #endif