3.3.12. pci.api.summation module

A module with utilities for performing summation in a way that reduces numerical error

New in version 2019.

3.3.12.1. Kahan Summation

class pci.api.summation.KahanSummation(start=0)

Bases: object

Calculating the sum of many floating-point numbers has the potential to introduce numerical error.

This class is a utility to do summation in a way that reduces this numerical error using an algorithm attributed to William Kahan

Initialize this class by specifying a start value, which has a default value of 0.

This example demonstrates how to use this class.

1from pci.api.summation import KahanSummation
2
3k = KahanSummation()
4for val in vals:
5    k += val
6
7print(k.sum)
property sum
pci.api.summation.ksum(iterable, start=0)

Utility function to perform Kahan Summation on an iterable object (e.g. list, tuple, set, etc.)