PreciseSums (version 0.4)

kahanSum: Using the Kahan method, take a more accurate sum

Description

Using the Kahan method, take a more accurate sum

Usage

kahanSum(numbers)

Arguments

numbers

A vector of numbers to sum.

Value

Sum of numbers

References

https://en.wikipedia.org/wiki/Kahan_summation_algorithm

Examples

Run this code
# NOT RUN {
sum(c(1,1e100,1,-1e100)) ## Should be 2, gives 0
kahanSum(c(1,1e100,1,-1e100)) ## Not accurate enough for the correct result. (still = 0)
# }

Run the code above in your browser using DataCamp Workspace