[R] wrong answer for simple expressions

Drew Hoysak dhoysak at ccs.carleton.ca
Thu Nov 11 18:24:10 CET 2004

I am experiencing strange (to me) output when trying to do simple
calculations.  Expressions that should equal zero yield non-zero

> a <- 4.1-3.1
> b <- 5.1-4.1
> a-b
[1] -4.440892e-16

> (4.1-3.1)-(5.1-4.1)
[1] -4.440892e-16

When this last expression is expanded, I get the right answer:

> 4.1-3.1-5.1+4.1
[1] 0

I am using the binary packaged version R-2.0.0-0.fdr.1.fc2.i386.rpm for
Linux Fedora Core 2.  I had the same problem with version 1.9.0-0

Can anyone tell me what is going on?


Drew Hoysak

More information about the R-help mailing list