[R] problem with sum function

William Dunlap wdunlap at tibco.com
Thu Mar 1 23:01:37 CET 2012


In base ten, using any fixed number of digits, compute
   1/3 + 1/3 + 1/3
(doing the divisions before the additions).
Why isn't it 1?

1/5 has the same sort of problem in base two.

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com 

> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of Mark A. Albins
> Sent: Thursday, March 01, 2012 1:50 PM
> To: r-help at r-project.org
> Subject: [R] problem with sum function
> 
> Hi!
> 
> I'm running R version 2.13.0 (2011-04-13)
> Platform: i386-pc-mingw32/i386 (32-bit)
> 
> When i type in the command:
> 
> sum(c(-0.2, 0.8, 0.8, -3.2, 1.8))
> 
> R returns the value:
> 
> -5.551115e-17
> 
> Why doesn't R return zero in this case?  There shouldn't be any rounding
> error in a simple sum.
> 
> Thanks,
> 
> Mark
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list