From ligges at statistik.uni-dortmund.de  Wed Mar 24 15:44:30 2004
From: ligges at statistik.uni-dortmund.de (ligges@statistik.uni-dortmund.de)
Date: Wed Mar 24 15:44:31 2004
Subject: [Rd] "==" gives incorrect answers! (PR#6691)
Message-ID: <20040324144430.07D4C1045F@slim.kubism.ku.dk>

dongyunhkim@yahoo.com wrote:

> Full_Name: Dong-Yun Kim
> Version: 1.7.0/1.8.1
> OS: WinMe/WinXP
> Submission from: (NULL) (4.33.147.192)
> 
> 
> Hi all,
> 
> It appears that R has a problem with evaluating logical "==" operator. The
> following are a few examples I found:
> 
> 
>>2.1+0.2==2.3
> 
> [1] FALSE
> 
>>2.7+0.1==2.8
> 
> [1] FALSE
> 
>>2.7+0.2==2.9
> 
> [1] FALSE
> 
>>3.1+0.2==3.3
> 
> [1] FALSE
> 
> Thanks.
> 
> Dong-Yun Kim
> 
> ______________________________________________
> R-devel@stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-devel

Not a bug!

These are (expected!) numerical issues of the representation of those 
values. Please read help("==") which tells you:

"For numerical values, remember == and != do not allow for the finite 
representation of fractions, nor for rounding error. Using all.equal 
with identical is almost always preferable."

And ?all.equal and ?identical tell you to use:

  identical(all.equal(2.7 + 0.1, 2.8), TRUE)


Uwe Ligges


[Rd] "==" gives incorrect answers! (PR#6691)
ligges@statistik.uni-dortmund.de