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 stores and updates
intermediate sums for all power of two elements such that the final sum can
be generated from intermediate sums that result from equal number of
summands.Modifier and Type | Field and Description |
---|---|
protected boolean[] |
flags |
protected double[] |
sums |
Constructor and Description |
---|
RealSum()
Create a new
RealSum . |
RealSum(int capacity)
Create a new
RealSum . |
Modifier and Type | Method and Description |
---|---|
void |
add(double a)
Add an element to the sum.
|
protected void |
expand(double s) |
double |
getSum()
Get the current sum by summing up all intermediate sums.
|
public RealSum()
RealSum
. The fields for intermediate sums is
initialized with a single element and expanded on demand as new elements
are added.public RealSum(int capacity)
RealSum
. The fields for intermediate sums is
initialized with a given number of elements and will only be expanded on
demand as new elements are added and the number of existing elements is
not sufficient. This may be faster in cases where the required number of
elements is known in prior.capacity
- public final double getSum()
protected final void expand(double s)
public final void add(double a)
a
- the summand to be addedCopyright © 2015–2022 ImgLib2. All rights reserved.