Boost logo

Boost :

From: Martin Bonner (martin.bonner_at_[hidden])
Date: 2006-08-03 13:09:56


----Original Message----
From: boost-bounces_at_[hidden]
[mailto:boost-bounces_at_[hidden]] On Behalf Of Guillaume Melquiond
Sent: 03 August 2006 17:16 To: boost_at_[hidden]
Subject: Re: [boost] Portable signbit macro/function?

> Le jeudi 03 août 2006 à 17:49 +0200, Johan Råde a écrit :
>
>> All I need to do is to get my hands on the bit patterns of 1.0f,
>> -1.0f and x. Do I really have to copy the memory to do that?
>> That seems like overkill.
>
> You don't have to copy the memory, you can simply read the bit
> patterns
> char by char, if you prefer. Any other kind of access will produce
> wrong
> assembly code on compilers with "strong" optimizers.
>
>> Can't I just form pointers to the float constants, cast the pointers
>> to int pointers, and dereference them?
>
> No you can't. See paragraph 3.10/15 of the C++ standard.
>
> Best regards,
>
> Guillaume

... and of course this whole masking approach wouldn't work for an architecture where the sign of a floating point number was indicated by setting the sign bit such that the parity of all the bits in the number was odd for positive and even for negative!

That is not to say that the bit test via mask is not potentially useful, just that one should be aware of its limitations.

-- 
Martin Bonner
Martin.Bonner_at_[hidden]
Pi Technology, Milton Hall, Ely Road, Milton, Cambridge, CB4 6WZ,
ENGLAND Tel: +44 (0)1223 203894

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk