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

View source: R/sums.R

kahanSumR Documentation

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

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)

PreciseSums documentation built on April 22, 2023, 1:13 a.m.