Skip to content
Prev 98197 / 398498 Next

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

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)