Skip to content
Prev 32589 / 398528 Next

Numbers that look equal, should be equal, but if() doesn't see as equal (repost with code included)

On Wed, 28 May 2003, Paul Lemmens wrote:

            
How you you think 0.25 gets converted to an internal number?  It might be
0 + 2/10 + 5/100, and 2/10 and 5/100 cannot be represented exactly in 
binary arithmetic.  (R uses the system's strtod routine, so how it is done 
is system-dependent: on my systems it does end up with the same bit 
pattern as 1/4.)

As a real example
[1] FALSE

since
[1] 0.30000000000000004 0.29999999999999999

yet
[1] 0.1 0.2 0.3