JuliaMath / KahanSummation.jl

Sum and cumulative sum using the Kahan-Babuska-Neumaier algorithm

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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.

About

Sum and cumulative sum using the Kahan-Babuska-Neumaier algorithm

License:MIT License


Languages

Language:Julia 100.0%