POV-Ray : Newsgroups : povray.off-topic : That's got to be one of the stupider design choices I've seen : Re: That's got to be one of the stupider design choices I've seen Server Time
4 Sep 2024 11:21:42 EDT (-0400)
  Re: That's got to be one of the stupider design choices I've seen  
From: Invisible
Date: 19 Feb 2010 05:20:48
Message: <4b7e6600$1@news.povray.org>
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

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.