(iterable)
return sum(partials, 0.0)
Full precision summation using multiple floats for intermediate values
Full precision summation using multiple floats for intermediate values
Full precision summation using multiple floats for intermediate values
def msum(iterable):
    "Full precision summation using multiple floats for intermediate values"
    # sorted, non-overlapping partial sums
    partials = []
    for x in iterable:
        i = 0
        for y in partials:
            if abs(x) < abs(y):
                x, y = y, x
            hi = x + y
            lo = y - (hi - x)
            if lo:
                partials[i] = lo
                i += 1
            x = hi
        partials[i:] = [x]
    return sum(partials, 0.0)
def msum ( iterable ) : # sorted, non-overlapping partial sums partials = [ ] for x in iterable : i = 0 for y in partials : if abs ( x ) < abs ( y ) : x , y = y , x hi = x + y lo = y - ( hi - x ) if lo : partials [ i ] = lo i += 1 x = hi partials [ i : ] = [ x ] return sum ( partials , 0.0 )