]> Savannah Git Hosting - gnulib.git/commitdiff
copysign: Provide replacement.
authorBruno Haible <bruno@clisp.org>
Sun, 9 Oct 2011 12:44:58 +0000 (14:44 +0200)
committerBruno Haible <bruno@clisp.org>
Sun, 9 Oct 2011 12:44:58 +0000 (14:44 +0200)
* 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.

ChangeLog
doc/posix-functions/copysign.texi
lib/copysign.c [new file with mode: 0644]
lib/math.in.h
m4/copysign.m4 [new file with mode: 0644]
m4/math_h.m4
modules/copysign
modules/math
tests/test-math-c++.cc

index 362fdf434ef6051f1f157cf250895a47bdfef790..e27cfc1aa952947bac0b9ab46afd7abba76b2272 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,22 @@
+2011-10-09  Bruno Haible  <bruno@clisp.org>
+
+       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  <bruno@clisp.org>
 
        isinf: Ensure macro on AIX 5.1.
index 3533e2b80b11f5afe24493c8cbbba80e689ddcf1..dbacb0db52a2fa69a12850f62a443d9cb525f07e 100644 (file)
@@ -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 (file)
index 0000000..5480245
--- /dev/null
@@ -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 <http://www.gnu.org/licenses/>.  */
+
+#include <config.h>
+
+/* Specification.  */
+#include <math.h>
+
+double
+copysign (double x, double y)
+{
+  return (signbit (x) != signbit (y) ? - x : x);
+}
index a63765824256a21f782fa44d275cdb52acb0a4a3..e14ea15b987513a30031a41e8f6fc335d6566d59 100644 (file)
@@ -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 (file)
index 0000000..15c9bc6
--- /dev/null
@@ -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])
+])
index 1088d1632e7dca04ec13a22650ae4b71c53020ac..240415325916b6d5cc873f05b7a9e3ffa88ed3e0 100644 (file)
@@ -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 <math.h>]],
-    [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])
index 5318e80271f876ad42244fe9261e38db780eed34..656aa5017bfdd42b850122c6c59fa1c1bbb1bb07 100644 (file)
@@ -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:
 
index 9c6f999f92e64b0a0b15f25b060192e618894169..a76abcfbd918d9b66a4e9b0483ff48d63d1b9ffc 100644 (file)
@@ -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' \
index d786273c4270db8402901ee5077c936efca02c14..7ae1ea190f8067245d7682ac200ee65d9b215600 100644 (file)
@@ -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