changeset 15908:2f40da163bc2

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.
author Bruno Haible <bruno@clisp.org>
date Sun, 09 Oct 2011 14:44:58 +0200
parents 4483180d8a93
children 7c3f393e9c20
files ChangeLog doc/posix-functions/copysign.texi lib/copysign.c lib/math.in.h m4/copysign.m4 m4/math_h.m4 modules/copysign modules/math tests/test-math-c++.cc
diffstat 9 files changed, 101 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- 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.
--- a/doc/posix-functions/copysign.texi
+++ b/doc/posix-functions/copysign.texi
@@ -8,11 +8,11 @@
 
 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
new file mode 100644
--- /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 <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);
+}
--- a/lib/math.in.h
+++ b/lib/math.in.h
@@ -320,6 +320,21 @@
 #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
new file mode 100644
--- /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])
+])
--- 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 @@
   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 @@
   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 @@
   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])
--- 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:
 
--- a/modules/math
+++ b/modules/math
@@ -38,6 +38,7 @@
 	      -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 @@
 	      -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' \
--- a/tests/test-math-c++.cc
+++ b/tests/test-math-c++.cc
@@ -41,7 +41,9 @@
 #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