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

According to Bruno Haible on 3/25/2007 9:57 AM:
> Eric Blake wrote:
>> Is this any more portable, by avoiding floating point division altogether?
>>
>> /* 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;
>> }
> 
> You are picking a particular bit in a 'long double' representation. If you
> picked any bit different from the sign bit, this code is fine (assuming
> !isnanl(d) is already known). If you picked the sign bit, +0.0 will be
> considered negative too.

Actually, if I picked the sign bit, then both -0 and +0 would be
considered positive, since neither 0 compares less than 0.

> It's an endianness issue and depends on the bit
> storage order in words. You might have picked the wrong bit for m68k...
> It's safer to use   u.l |= 8;   since noone will put the sign bit at
> bit 3 or 28 (except the HP-PA designers perhaps :-)).

Yes, I like your idea of using a bit other than the LSB as a way to ensure
that the sign bit is not hit.  But you also have to pick a bit that does
not fall in the 2-byte padding of the 10-byte x86 long double.

- --
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

iD8DBQFGBvOH84KuGfSFAYARAnsVAKDBDe0uwPWfPZ7j8/RYKbQqVsqIfgCdGI+Y
gHxqppJppVeJPVQyLSq0r30=
=vvsY
-----END PGP SIGNATURE-----


Reply via email to