From p.dalgaard at biostat.ku.dk  Wed Mar 24 15:50:40 2004
From: p.dalgaard at biostat.ku.dk (Peter Dalgaard)
Date: Wed Mar 24 15:52:09 2004
Subject: [Rd] "==" gives incorrect answers! (PR#6691)
In-Reply-To: <20040324143547.2F7581043D@slim.kubism.ku.dk>
References: <20040324143547.2F7581043D@slim.kubism.ku.dk>
Message-ID: <x2zna62ta7.fsf@biostat.ku.dk>

dongyunhkim@yahoo.com writes:

> 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

Please, do read up on elementary computer theory, in particular the
parts about inexact representation of decimal numbers as floating
point numbers, and why equality of such numbers cannot be trusted!

What you're seeing is the moral equivalent of 

1/3 + 1/6 = 0.333 + 0.666 = 0.999 != 1

-- 
   O__  ---- Peter Dalgaard             Blegdamsvej 3  
  c/ /'_ --- Dept. of Biostatistics     2200 Cph. N   
 (*) \(*) -- University of Copenhagen   Denmark      Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard@biostat.ku.dk)             FAX: (+45) 35327907


[Rd] "==" gives incorrect answers! (PR#6691)
Peter Dalgaard