summaryrefslogtreecommitdiff
path: root/m4/signbit.m4
diff options
context:
space:
mode:
authorBruno Haible <bruno@clisp.org>2010-12-21 14:18:46 +0100
committerBruno Haible <bruno@clisp.org>2010-12-21 17:30:26 +0100
commitd896f0b2b2a00b53abc0a4e9786f03c5a60a8b9f (patch)
tree71b7fee7f6b088e705665a39aa3eebd3f05583b3 /m4/signbit.m4
parentfe2a2304a8635cdaabe93e4f5e49960bec1512b1 (diff)
downloadgnulib-d896f0b2b2a00b53abc0a4e9786f03c5a60a8b9f.tar.gz
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.
Diffstat (limited to 'm4/signbit.m4')
-rw-r--r--m4/signbit.m442
1 files changed, 41 insertions, 1 deletions
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;
+}
+]])