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