Description Usage Arguments Details Value Author(s) References See Also Examples
Functions for performing basic sum operations without roundoff errors
1 2  sumexact(..., na.rm = FALSE)
cumsumexact(x)

x 
numeric vector 
... 
numeric vector(s), numbers or other objects to be summed 
na.rm 
logical. Should missing values be removed? 
All three functions use full precision summation using multiple doubles for intermediate values. The sum of numbers x & y is a=x+y with error term b=error(a+b). That way a+b is equal exactly x+y, so sum of 2 numbers is stored as 2 or fewer values, which when added would underflow. By extension sum of n numbers is calculated with intermediate results stored as array of numbers that can not be added without introducing an error. Only final result is converted to a single number
Function sumexact
returns single number. Function cumsumexact
returns vector of the same length as x
.
Jarek Tuszynski (SAIC) jaroslaw.w.tuszynski@saic.com based on code by Vadim Ogranovich, which is based on algorithms described in references, pointed out by Gabor Grothendieck.
Roundoff error correction is based on: Shewchuk, Jonathan, Adaptive Precision FloatingPoint Arithmetic and Fast Robust Geometric Predicates
McCullough, D.B., (1998) Assessing the Reliability of Statistical Software, Part I, The American Statistician, Vol. 52 No.
McCullough, D.B., (1999) Assessing the Reliability of Statistical Software, Part II, The American Statistician, Vol. 53 No 2
NIST Statistical Reference Datasets (StRD) website
sum
is faster but not errorsave version of
sumexact
cumsum
is equivalent to cumsumexact
1 2 3 4 5 6 7 
[1] 1e+20
[1] 0
[1] 1e+00 1e+20 1e+40 0e+00 1e+20 1e+20
[1] 1e+00 1e+20 1e+40 1e+20 1e+00 0e+00
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.