Class RealSum

java.lang.Object
net.imglib2.util.RealSum

public class RealSum extends 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 Details

    • sum

      private double sum
    • compensation

      private double compensation
  • Constructor Details

    • 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 Details

    • 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