Class KahanSummation


  • public class KahanSummation
    extends Object
    Provides methods and elements for Kahan's algorithm for summing a set of numerical values with extended precision arithmetic. Often, when adding a large set of small values to a large value, the limited precision of computer arithmetic results in the contribution of the small values being lost. This limitation may result in a loss of valuable data if the total sum of the collected small values is large enough enough to make a meaningful contribution to the large value. Kahan's algorithm extends the precision of the computation so that the contribution of small values is preserved.
    • Constructor Detail

      • KahanSummation

        public KahanSummation()
        Standard constructor
    • Method Detail

      • add

        public void add​(double a)
        Add the value to the summation
        Parameters:
        a - a valid floating-point number
      • getSum

        public double getSum()
        The current value of the summation.
        Returns:
        the standard-precision part of the sum, a valid floating-point number.
      • getMean

        public double getMean()
        Gets the mean value of the summands.
        Returns:
        a valid floating-point value.
      • getSummandCount

        public int getSummandCount()
        Gets the number of summands that were added to the summation.
        Returns:
        a value of zero or greater.