summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog8
-rw-r--r--m4/minus-zero.m476
-rw-r--r--m4/signbit.m442
-rw-r--r--tests/minus-zero.h4
4 files changed, 129 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index 56b7dc7174..6a0657b7dc 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,13 @@
2010-12-21 Bruno Haible <bruno@clisp.org>
+ Support for minus zero in autoconf macros.
+ * m4/minus-zero.m4: New file, based on tests/minus-zero.h.
+ * m4/signbit.m4 (gl_FLOAT_SIGNBIT_CODE, gl_DOUBLE_SIGNBIT_CODE,
+ gl_LONG_DOUBLE_SIGNBIT_CODE, gl_FLOATTYPE_SIGNBIT_CODE): New macros.
+ * tests/minus-zero.h: Update comments.
+
+2010-12-21 Bruno Haible <bruno@clisp.org>
+
Tests for module 'ceil'.
* modules/ceil-tests: New file.
* tests/test-ceil1.c: New file, based on tests/test-ceill.c.
diff --git a/m4/minus-zero.m4 b/m4/minus-zero.m4
new file mode 100644
index 0000000000..f6e9745c3e
--- /dev/null
+++ b/m4/minus-zero.m4
@@ -0,0 +1,76 @@
+# minus-zero.m4 serial 1
+dnl Copyright (C) 2010 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.
+
+# Macros for floating-point negative zero.
+# Keep in sync with tests/minus-zero.h!
+
+# Expands to code that defines a variable or macro minus_zerof.
+AC_DEFUN([gl_FLOAT_MINUS_ZERO_CODE],
+[[
+#include <float.h>
+/* minus_zerof represents the value -0.0f. */
+/* HP cc on HP-UX 10.20 has a bug with the constant expression -0.0f.
+ ICC 10.0 has a bug when optimizing the expression -zero.
+ The expression -FLT_MIN * FLT_MIN does not work when cross-compiling
+ to PowerPC on MacOS X 10.5. */
+#if defined __hpux || defined __sgi || defined __ICC
+static float
+compute_minus_zerof (void)
+{
+ return -FLT_MIN * FLT_MIN;
+}
+# define minus_zerof compute_minus_zerof ()
+#else
+float minus_zerof = -0.0f;
+#endif
+]])
+
+# Expands to code that defines a variable or macro minus_zerod.
+AC_DEFUN([gl_DOUBLE_MINUS_ZERO_CODE],
+[[
+#include <float.h>
+/* minus_zerod represents the value -0.0. */
+/* HP cc on HP-UX 10.20 has a bug with the constant expression -0.0.
+ ICC 10.0 has a bug when optimizing the expression -zero.
+ The expression -DBL_MIN * DBL_MIN does not work when cross-compiling
+ to PowerPC on MacOS X 10.5. */
+#if defined __hpux || defined __sgi || defined __ICC
+static double
+compute_minus_zerod (void)
+{
+ return -DBL_MIN * DBL_MIN;
+}
+# define minus_zerod compute_minus_zerod ()
+#else
+double minus_zerod = -0.0;
+#endif
+]])
+
+# Expands to code that defines a variable or macro minus_zerol.
+AC_DEFUN([gl_LONG_DOUBLE_MINUS_ZERO_CODE],
+[[
+#include <float.h>
+#if defined __i386__ && (defined __BEOS__ || defined __OpenBSD__)
+# undef LDBL_MIN
+# define LDBL_MIN 3.3621031431120935063E-4932L
+#endif
+/* minus_zerol represents the value -0.0L. */
+/* HP cc on HP-UX 10.20 has a bug with the constant expression -0.0L.
+ IRIX cc can't put -0.0L into .data, but can compute at runtime.
+ ICC 10.0 has a bug when optimizing the expression -zero.
+ The expression -LDBL_MIN * LDBL_MIN does not work when cross-compiling
+ to PowerPC on MacOS X 10.5. */
+#if defined __hpux || defined __sgi || defined __ICC
+static long double
+compute_minus_zerol (void)
+{
+ return -LDBL_MIN * LDBL_MIN;
+}
+# define minus_zerol compute_minus_zerol ()
+#else
+long double minus_zerol = -0.0L;
+#endif
+]])
diff --git a/m4/signbit.m4 b/m4/signbit.m4
index c6a3891808..00289f5ca1 100644
--- a/m4/signbit.m4
+++ b/m4/signbit.m4
@@ -1,4 +1,4 @@
-# signbit.m4 serial 8
+# signbit.m4 serial 9
dnl Copyright (C) 2007-2010 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
@@ -306,3 +306,43 @@ int main ()
;;
esac
])
+
+# Expands to code that defines a function signbitf(float).
+# It extracts the sign bit of a non-NaN value.
+AC_DEFUN([gl_FLOAT_SIGNBIT_CODE],
+[
+ gl_FLOATTYPE_SIGNBIT_CODE([float], [f], [f])
+])
+
+# Expands to code that defines a function signbitd(double).
+# It extracts the sign bit of a non-NaN value.
+AC_DEFUN([gl_DOUBLE_SIGNBIT_CODE],
+[
+ gl_FLOATTYPE_SIGNBIT_CODE([double], [d], [])
+])
+
+# Expands to code that defines a function signbitl(long double).
+# It extracts the sign bit of a non-NaN value.
+AC_DEFUN([gl_LONG_DOUBLE_SIGNBIT_CODE],
+[
+ gl_FLOATTYPE_SIGNBIT_CODE([long double], [l], [L])
+])
+
+AC_DEFUN([gl_FLOATTYPE_SIGNBIT_CODE],
+[[
+static int
+signbit$2 ($1 value)
+{
+ typedef union { $1 f; unsigned char b[sizeof ($1)]; } float_union;
+ static float_union plus_one = { 1.0$3 }; /* unused bits are zero here */
+ static float_union minus_one = { -1.0$3 }; /* unused bits are zero here */
+ /* Compute the sign bit mask as the XOR of plus_one and minus_one. */
+ float_union u;
+ unsigned int i;
+ u.f = value;
+ for (i = 0; i < sizeof ($1); i++)
+ if (u.b[i] & (plus_one.b[i] ^ minus_one.b[i]))
+ return 1;
+ return 0;
+}
+]])
diff --git a/tests/minus-zero.h b/tests/minus-zero.h
index 65bd1b415e..de22c51d83 100644
--- a/tests/minus-zero.h
+++ b/tests/minus-zero.h
@@ -14,8 +14,11 @@
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
+/* Keep in sync with m4/minus-zero.m4! */
+
#include <float.h>
+
/* minus_zerof represents the value -0.0f. */
/* HP cc on HP-UX 10.20 has a bug with the constant expression -0.0f.
@@ -51,6 +54,7 @@ compute_minus_zerod (void)
double minus_zerod = -0.0;
#endif
+
/* minus_zerol represents the value -0.0L. */
/* HP cc on HP-UX 10.20 has a bug with the constant expression -0.0L.