# HG changeset patch # User Bruno Haible # Date 1208018033 -7200 # Node ID 31d7bf84aa9ae93b741e8db2e7273c91728e93c5 # Parent 5f47b9c9cc457d2bf55bb8836f8719131e13c0ad Override the system isnanf also on IRIX 6.5 with gcc. diff --git a/ChangeLog b/ChangeLog --- 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 --- 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 @@ ]) ]) -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 @@ #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() { + memory_float m; + + if (isnanf (1.0f / 0.0f)) + return 1; + if (!isnanf (NaN ())) return 1; - if (isnanf (1.0f / 0.0f)) - 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