Class RealSum


  • public class RealSum
    extends java.lang.Object
    RealSum implements a method to reduce numerical instabilities when summing up a very large number of double precision numbers. Numerical problems occur when a small number is added to an already very large sum. In such case, the reduced accuracy of the very large number may lead to the small number being entirely ignored. The method here is Neumaier's improvement of the Kahan summation algorithm. See this Wikipedia article for details.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private double compensation  
      private double sum  
    • Constructor Summary

      Constructors 
      Constructor Description
      RealSum()
      Create a new RealSum initialized to zero.
      RealSum​(int capacity)
      Deprecated.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void add​(double value)
      Add an element to the sum.
      double getSum()
      Get the current sum.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • sum

        private double sum
      • compensation

        private double compensation
    • Constructor Detail

      • RealSum

        public RealSum()
        Create a new RealSum initialized to zero.
      • RealSum

        @Deprecated
        public RealSum​(int capacity)
        Deprecated.
        Create a new RealSum initialized to zero. This constructor was used in a previous version of RealSum and is kept for backwards compatibility.
        Parameters:
        capacity - unused
    • Method Detail

      • getSum

        public double getSum()
        Get the current sum.
      • add

        public void add​(double value)
        Add an element to the sum.
        Parameters:
        value - the summand to be added