[R] Unexpected result from binary greater than operator

From: <chris.bodily_at_autolivasp.com>
Date: Wed 02 Nov 2005 - 03:15:50 EST


Hi All,

I recently encountered results that I did not expect, exhibited by the following code snippet:

test <- function() {

    minX <- 4.2
    min0 <- 4.1
    sigmaG <- 0.1
    Diff <- minX-min0
    print(c(Diff=Diff,sigmaG=sigmaG))

    cat("is Diff > sigmaG?:", Diff > sigmaG,"\n")
    cat("is (4.2 - 4.1) > 0.1?:",(4.2 - 4.1) > 0.1,"\n")
    cat("is 0.1 > 0.1?:", 0.1>0.1,"\n")

}

When I execute the above function I get the following:
> test()

  Diff sigmaG
   0.1 0.1
is Diff > sigmaG?: TRUE
is (4.2 - 4.1) > 0.1?: TRUE
is 0.1 > 0.1?: FALSE

Can someone please help me understand why R returns TRUE for (4.2 - 4.1) > 0.1 ?

Thanks so much,
Chris

I'm running the precompiled R-2.2.0 binary for Windows on WinXP Pro SP1.

>Sys.getlocale()

"LC_COLLATE=English_United States.1252;LC_CTYPE=English_United States.1252;LC_MONETARY=English_United
States.1252;LC_NUMERIC=C;LC_TIME=English_United States.1252"

>version

         _
platform i386-pc-mingw32

arch     i386
os       mingw32

system i386, mingw32
status
major 2
minor 2.0
year 2005
month 10
day 06
svn rev 35749
language R

R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Wed Nov 02 03:21:20 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:40:54 EST