Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Kahan summation for fsum and fsumf #742

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Commits on Feb 14, 2023

  1. Use Kahan summation for fsum and fsumf

    This compensated summation gives a more precise result than the original
    algorithm, as demonstrated through extra precision in the tests. It also
    drops recursion and the extra branching.
    
    I used double precision internally for fsumf since I assume its purpose
    is to interface with single precision, not necessary constrain itself to
    only using single precision. If needed, it can be trivially changed to
    use single precision internally while still passing the tests.
    
    In fsumf, naive summation using double precision is likely sufficient,
    and more precise than single precision Kaham summation. In other words,
    Kahan summation with double precision in fsumf may be overkill.
    
    In the fsumf test, neither 10000.1 nor 1.1 can be represented exactly.
    The former is rounded down and the latter is rounded up (by less) to the
    nearest representable value. As a result, the most precise sum is just
    shy of the "obvious" result.
    skeeto committed Feb 14, 2023
    Configuration menu
    Copy the full SHA
    35924d4 View commit details
    Browse the repository at this point in the history