bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: support for bitwise comparison of floats


From: Eric Blake
Subject: Re: support for bitwise comparison of floats
Date: Sun, 25 Mar 2007 08:56:35 -0600
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.10) Gecko/20070221 Thunderbird/1.5.0.10 Mnenhy/0.7.4.666

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

According to Bruno Haible on 3/25/2007 4:54 AM:
> Eric Blake wrote:
>> You can also assume IEEE rules, and compare against signed infinity:
>> 1 / +0. => +infinity
>> 1 / -0. => -infinity
> 
> Nice trick :-)
> 
> But here you depend on the IEEE rules for exceptions upon division by zero.

Is this any more portable, by avoiding floating point division altogether?
  It works on x86, at any rate.  It assumes that a long is big enough that
twiddling the low-order bit in the long will make the long double non-zero
without also making it a NaN.  Although it doesn't work on signaling NaN
as is.

/* return true iff the representation of d needs a leading '-' */
bool
is_negative (long double d)
{
  if (d == 0)
    {
      union {
        long double d;
        long l;
      } u;
      u.d = d;
      u.l |= 1;
      return u.d < 0;
    }
  return d < 0;
}

- --
Don't work too hard, make some time for fun as well!

Eric Blake             address@hidden
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (Cygwin)
Comment: Public key at home.comcast.net/~ericblake/eblake.gpg
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFGBo2B84KuGfSFAYARArwyAKCZxGSMrhTt7U0rEjKuFnBCzXzmGgCeKsQK
/Ged2WRa7qx6dq0lLDb3k0w=
=hxtk
-----END PGP SIGNATURE-----




reply via email to

[Prev in Thread] Current Thread [Next in Thread]