[R] Floating point imprecision in sum() under R-2.3.1?

Brahm, David David.Brahm at geodecapital.com
Fri Aug 18 22:04:53 CEST 2006

I was concerned by this result (new in R-2.3.1):
R> x <- c(721.077, 592.291, 372.208, 381.182)
R> sum(x) - 2066.758
   [1] 4.547474e-13

But after Roger Peng's <rdpeng at gmail.com> insightful comment that the
relative difference (sum(x)/2066.758 - 1) is exactly what is expected,
I'm convinced that sum() is indeed really being "more accurate" than
it was in 2.2.1, i.e. accurately preserving the numerical imprecision
of the original inputs.  Sorry for the distraction...

-- David Brahm (brahm at alum.mit.edu)

More information about the R-help mailing list