java.lang.Object
java.lang.Number
io.jenetics.internal.math.DoubleAdder
- All Implemented Interfaces:
Serializable,Comparable<DoubleAdder>
This class implements the the
Kahan
summation algorithm, which significantly reduces the numerical error when
adding double values.
- Since:
- 3.0
- Version:
- 3.0
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionCreate a new adder with the initial value of0.0.DoubleAdder(double value) Create a new adder with the given defaultvalue. -
Method Summary
Modifier and TypeMethodDescriptionadd(double value) Add the givenvalueto this adder, using the Kahan summation algorithmadd(double[] values) Add the given values to this adder.add(DoubleAdder value) Add the givenvalueto this adder, using the Kahan summation algorithmcombine(DoubleAdder other) Add the givenvalueto this adder, using the Kahan summation algorithmintcompareTo(DoubleAdder other) doublebooleanfloatinthashCode()intintValue()longbooleansameState(DoubleAdder other) Check ifthisand theotherDoubleAddermaintain the same internal state.set(double value) Set the adder to the givenvalue.set(DoubleAdder value) Set the adder to the givenvalue.static doublesum(double[] values) Return the sum of the given double array.toString()doublevalue()Methods inherited from class java.lang.Number
byteValue, shortValue
-
Constructor Details
-
DoubleAdder
Create a new adder with the given defaultvalue.- Parameters:
value- the initialvalueof this adder.
-
DoubleAdder
public DoubleAdder()Create a new adder with the initial value of0.0.
-
-
Method Details
-
set
Set the adder to the givenvalue.- Parameters:
value- the new adder value- Returns:
thisadder, for command chaining
-
set
Set the adder to the givenvalue.- Parameters:
value- the new adder value- Returns:
thisadder, for command chaining- Throws:
NullPointerException- if the givenvalueisnull
-
add
Add the givenvalueto this adder, using the Kahan summation algorithm- Parameters:
value- thevalueto add- Returns:
thisadder, for command chaining
-
add
Add the given values to this adder.- Parameters:
values- the values to add.- Returns:
thisadder, for command chaining
-
add
Add the givenvalueto this adder, using the Kahan summation algorithm- Parameters:
value- thevalueto add- Returns:
thisadder, for command chaining- Throws:
NullPointerException- if the givenvalueisnull
-
combine
Add the givenvalueto this adder, using the Kahan summation algorithm- Parameters:
other- thevalueto add- Returns:
thisadder, for command chaining- Throws:
NullPointerException- if the givenvalueisnull
-
value
-
intValue
-
longValue
-
floatValue
- Specified by:
floatValuein classNumber
-
doubleValue
- Specified by:
doubleValuein classNumber
-
compareTo
- Specified by:
compareToin interfaceComparable<DoubleAdder>
-
sameState
Check ifthisand theotherDoubleAddermaintain the same internal state.- Parameters:
other- the other object- Returns:
trueifthisand theotheradder have the same state,false otherwise
-
hashCode
-
equals
-
toString
-
sum
Return the sum of the given double array.- Parameters:
values- the values to sum up.- Returns:
- the sum of the given
values. - Throws:
NullPointerException- if the given array isnull.
-