-----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             [EMAIL PROTECTED]
-----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