PreciseSums (version 0.6)

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

Description

Using the Kahan method, take a more accurate sum

Usage

kahanSum(numbers)

Value

Sum of numbers

Arguments

numbers

A vector of numbers to sum.

References

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

Examples

Run this code
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 DataLab