java.lang.Object
org.bzdev.math.Adder
org.bzdev.math.Adder.Kahan
- Enclosing class:
- Adder
Add a series of values using the Kahan summation algorithm.
A description of the algorithm can be found in a
Wikipedia article.
This class is intended for cases were additional numerical accuracy
better than summing the elements of a vector in the order in which they
appear is needed. Accuracy is higher than when the Pairwise class is
used, at the cost of some additional computation per element being
summed.
The documentation for the class Adder.Kahan.State
describes
how to use the Kahan summation algorithm directly (e.g., to avoid
the overhead of some method calls).
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final class
Encapsulate the state of an instance of Adder.Kahan.Nested classes/interfaces inherited from class org.bzdev.math.Adder
Adder.Kahan, Adder.Pairwise
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
add
(double value) Add a single number to the summation.void
add
(double[] array) Add the elements of an array to the summation.void
add
(double[] array, int start, int end) Add the elements of an array to the summation, specifying an offset into the array and the number of elements to process.void
Add the values produced by an Iterable to the summation.getState()
Get the state of this adder.double
getSum()
Get the sum.void
reset()
Reset the class to sum a new set of values.
-
Constructor Details
-
Kahan
public Kahan()Constructor.
-
-
Method Details
-
getState
Get the state of this adder.- Returns:
- this adder's state
- See Also:
-
add
public void add(double[] array) Description copied from class:Adder
Add the elements of an array to the summation. -
add
public void add(double[] array, int start, int end) Description copied from class:Adder
Add the elements of an array to the summation, specifying an offset into the array and the number of elements to process. The indices of the elements added are members of the interval [start,end). -
add
public void add(double value) Description copied from class:Adder
Add a single number to the summation. -
add
Description copied from class:Adder
Add the values produced by an Iterable to the summation. This method will add the elements of any object that can be used in a 'foreach' statement (the "for (TYPE value: object)" syntax) when TYPE is a subclass of Number (e.g., Double, Float, etc.) -
getSum
public double getSum()Description copied from class:Adder
Get the sum. Additional values can be subsequently added. -
reset
public void reset()Description copied from class:Adder
Reset the class to sum a new set of values.
-