|
Boost : |
Subject: Re: [boost] [review][constrained_value] Review of Constrained Value Library begins today
From: Thorsten Ottosen (thorsten.ottosen_at_[hidden])
Date: 2008-12-09 07:20:12
John Maddock skrev:
> Thorsten Ottosen wrote:
>>> I don't fully understand this...AFAIK, this is not allowed for an
>>> IEEE complient implementation. How could we ever implement
>>> *anything* with
>>> respect to floats then?
>
> With difficulty :-(
>
> Here's the thought experiment I came up with to verify that this is a
> real issue:
>
> * Imagine that the constraint is that the value is > 1, and that we're
> working with double's.
> * Imagine that the value being assigned is the result of some complex
> computation, and that the assignment function is inlined.
> * The compiler may now take the value being assigned as it exists in a
> register (from the computation), and perform a the check on that.
> * If the register containing the result is wider than a double (say
> Intels 80-bit long double), and the result is very slightly > 1, then
> the comparison will succeed.
> * The value is now stored in the object - and rounded down to double
> precision in the process.
> * The value may have been rounded down to exactly 1, and the constrait
> is now broken!
>
> Obviously if the constraint had been >= 1 then we'd be OK in this case
> (but then values very slightly < 1 may get rounded up, so we could
> eroniously reject a value).
This might be quite OK. At least this preserves the invariant and
therefore seems much better than the alternative.
-Thorsten
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk