From d896f0b2b2a00b53abc0a4e9786f03c5a60a8b9f Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Tue, 21 Dec 2010 14:18:46 +0100 Subject: [PATCH] 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. --- ChangeLog | 8 ++++++ m4/minus-zero.m4 | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ m4/signbit.m4 | 42 +++++++++++++++++++++++++++++- tests/minus-zero.h | 4 +++ 4 files changed, 129 insertions(+), 1 deletion(-) create mode 100644 m4/minus-zero.m4 diff --git a/ChangeLog b/ChangeLog index 56b7dc717..6a0657b7d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,13 @@ 2010-12-21 Bruno Haible + 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 + 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 000000000..f6e9745c3 --- /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 +/* 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 +/* 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 +#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 c6a389180..00289f5ca 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 65bd1b415..de22c51d8 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 . */ +/* Keep in sync with m4/minus-zero.m4! */ + #include + /* 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. -- 2.11.0