From f923bbee7c5ea96982c4939c7be3cc2023523c3c Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Sat, 12 Apr 2008 18:33:53 +0200 Subject: [PATCH] Override the system isnanf also on IRIX 6.5 with gcc. --- ChangeLog | 5 +++++ m4/isnanf.m4 | 34 +++++++++++++++++++++++++++++----- 2 files changed, 34 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index 9bbda9e38..a85a5e0a2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2008-04-12 Bruno Haible + + * m4/isnanf.m4 (gl_ISNANF_WORKS): Add a test for a special NaN. + Reported by Nelson H. F. Beebe . + 2008-04-12 Jim Meyering * m4/math_h.m4 (gl_MATH_H): Fix typos. diff --git a/m4/isnanf.m4 b/m4/isnanf.m4 index cff22369e..133895583 100644 --- a/m4/isnanf.m4 +++ b/m4/isnanf.m4 @@ -1,4 +1,4 @@ -# isnanf.m4 serial 5 +# isnanf.m4 serial 6 dnl Copyright (C) 2007-2008 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -47,12 +47,14 @@ AC_DEFUN([gl_HAVE_ISNANF_NO_LIBM], ]) ]) -dnl Test whether isnanf() recognizes a NaN (this fails on IRIX 6.5) and rejects -dnl Infinity (this fails on Solaris 2.5.1). +dnl Test whether isnanf() rejects Infinity (this fails on Solaris 2.5.1), +dnl recognizes a NaN (this fails on IRIX 6.5 with cc), and recognizes a NaN +dnl with in-memory representation 0x7fbfffff (this fails on IRIX 6.5). AC_DEFUN([gl_ISNANF_WORKS], [ AC_REQUIRE([AC_PROG_CC]) AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles + AC_REQUIRE([gl_FLOAT_EXPONENT_LOCATION]) AC_CACHE_CHECK([whether isnan(float) works], [gl_cv_func_isnanf_works], [ AC_TRY_RUN([ @@ -75,12 +77,34 @@ NaN () #else # define NaN() (0.0f / 0.0f) #endif +#define NWORDS \ + ((sizeof (float) + sizeof (unsigned int) - 1) / sizeof (unsigned int)) +typedef union { unsigned int word[NWORDS]; float value; } memory_float; int main() { - if (!isnanf (NaN ())) - return 1; + memory_float m; + if (isnanf (1.0f / 0.0f)) return 1; + + if (!isnanf (NaN ())) + return 1; + +#if defined FLT_EXPBIT0_WORD && defined FLT_EXPBIT0_BIT + /* The isnanf function should be immune against changes in the sign bit and + in the mantissa bits. The xor operation twiddles a bit that can only be + a sign bit or a mantissa bit. */ + if (FLT_EXPBIT0_WORD == 0 && FLT_EXPBIT0_BIT > 0) + { + m.value = NaN (); + /* Set the bits below the exponent to 01111...111. */ + m.word[0] &= -1U << FLT_EXPBIT0_BIT; + m.word[0] |= 1U << (FLT_EXPBIT0_BIT - 1) - 1; + if (!isnanf (m.value)) + return 1; + } +#endif + return 0; }], [gl_cv_func_isnanf_works=yes], [gl_cv_func_isnanf_works=no], [case "$host_os" in -- 2.11.0