Skip to content

JuliaMath/KahanSummation.jl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

43 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

KahanSummation.jl

Travis Coveralls

This package provides variants of sum and cumsum, called sum_kbn and cumsum_kbn respectively, using the Kahan-Babuska-Neumaier (KBN) algorithm for additional precision. These functions are typically slower and less memory efficient than sum and cumsum.

These functions were formerly part of Julia's Base library. This package works and is supported.


Examples

julia> using KahanSummation

julia> vec = [1.0, 1.0e16, -1.0e16, -0.5];

julia> sum(vec), sum_kbn(vec)
(-0.5, 0.5)

julia> vec = [1.0, 1.0e16, 1.0, -1.0e16];

julia> cumsum_kbn(vec) .- cumsum(vec)
4-element Array{Float64,1}:
 0.0
 0.0
 2.0
 1.0

see the tests for more examples.