Mercurial > hg > octave-nkf > gnulib-hg
changeset 13976:31894df2c5e8
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.
author | Bruno Haible <bruno@clisp.org> |
---|---|
date | Tue, 21 Dec 2010 14:18:46 +0100 |
parents | 0af73906c87a |
children | dcd86f222143 |
files | ChangeLog m4/minus-zero.m4 m4/signbit.m4 tests/minus-zero.h |
diffstat | 4 files changed, 129 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +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'.
new file mode 100644 --- /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 +]])
--- 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 @@ ;; 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; +} +]])
--- 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 @@ 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.