Functions for performing basic sum operations without round-off errors
Usage
sumexact(..., na.rm = FALSE)
cumsumexact(x)
Arguments
x
numeric vector
...
numeric vector(s), numbers or other objects to be summed
na.rm
logical. Should missing values be removed?
Details
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 under-flow. 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
Value
Function sumexact returns single number. Function cumsumexact
returns vector of the same length as x.
Author(s)
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.