|
![](/i/fill.gif) |
Warp wrote:
> Answering my own question, the bit pattern for 0.3 is:
>
> 0 01111111101 0011001100110011001100110011001100110011001100110011
>
> This makes be believe that 0.3 is actually not accurately representable
> with base-2 floating point numbers, and hence converting from double to
> float does lose precision, technically speaking.
test :: Double -> Bool
test x =
let y = realToFrac x :: Float
in x == (realToFrac y)
> test 0
True
> test 1
True
> test 0.3
False
> test 0.1
False
> test 0.25
True
1/10 is a recurring binary fraction. This is the source of all the
trouble. (As you know, 10 = 2 * 5. 1/2 is no problem, 1/5 is.)
Post a reply to this message
|
![](/i/fill.gif) |