[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
copysign on MSVC
From: |
Bruno Haible |
Subject: |
copysign on MSVC |
Date: |
Sun, 9 Oct 2011 14:45:02 +0200 |
User-agent: |
KMail/1.13.6 (Linux/2.6.37.6-0.5-desktop; KDE/4.6.0; x86_64; ; ) |
MSVC 9 does not have the copysign() function. Here's the workaround.
2011-10-09 Bruno Haible <address@hidden>
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.
=============================== lib/copysign.c ===============================
/* 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);
}
=============================== m4/copysign.m4 ===============================
# 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])
])
==============================================================================
--- doc/posix-functions/copysign.texi.orig Sun Oct 9 14:35:20 2011
+++ doc/posix-functions/copysign.texi Sun Oct 9 14:34:16 2011
@@ -8,11 +8,11 @@
Portability problems fixed by Gnulib:
@itemize
address@hidden
+This function is missing on some platforms:
+Minix 3.1.8, MSVC 9.
@end itemize
Portability problems not fixed by Gnulib:
@itemize
address@hidden
-This function is missing on some platforms:
-Minix 3.1.8, MSVC 9.
@end itemize
--- lib/math.in.h.orig Sun Oct 9 14:35:20 2011
+++ lib/math.in.h Sun Oct 9 14:23:48 2011
@@ -320,6 +320,21 @@
#endif
+#if @GNULIB_COPYSIGN@
+# if address@hidden@
+_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 address@hidden@
# undef expf
--- m4/math_h.m4.orig Sun Oct 9 14:35:20 2011
+++ m4/math_h.m4 Sun Oct 9 14:26:15 2011
@@ -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])
--- modules/copysign.orig Sun Oct 9 14:35:20 2011
+++ modules/copysign Sun Oct 9 14:30:23 2011
@@ -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:
--- modules/math.orig Sun Oct 9 14:35:20 2011
+++ modules/math Sun Oct 9 14:25:11 2011
@@ -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' \
--- tests/test-math-c++.cc.orig Sun Oct 9 14:35:20 2011
+++ tests/test-math-c++.cc Sun Oct 9 14:27:05 2011
@@ -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
--
In memoriam Oskar Schindler <http://en.wikipedia.org/wiki/Oskar_Schindler>
<http://www.shoah.dk/Courage/Schindler.htm>
- copysign on MSVC,
Bruno Haible <=