[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: support for bitwise comparison of floats
From: |
Ben Pfaff |
Subject: |
Re: support for bitwise comparison of floats |
Date: |
Sun, 25 Mar 2007 15:21:48 -0700 |
User-agent: |
Gnus/5.110006 (No Gnus v0.6) Emacs/21.4 (gnu/linux) |
Eric Blake <address@hidden> writes:
> According to Bruno Haible on 3/25/2007 9:57 AM:
>> Eric Blake wrote:
>>> /* 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;
>>> }
[...]
>> 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.
I think that you can detect that you hit the padding by testing
whether u.d == 0. If it's still 0, then you changed a padding
bit.
--
I love deadlines.
I love the whooshing noise they make as they go by.
--Douglas Adams
Re: support for bitwise comparison of floats, Eric Blake, 2007/03/25
Re: support for bitwise comparison of floats, Paul Eggert, 2007/03/29