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 givenvalue
to this adder, using the Kahan summation algorithmadd
(double[] values) Add the given values to this adder.add
(DoubleAdder value) Add the givenvalue
to this adder, using the Kahan summation algorithmcombine
(DoubleAdder other) Add the givenvalue
to this adder, using the Kahan summation algorithmint
compareTo
(DoubleAdder other) double
boolean
float
int
hashCode()
int
intValue()
long
boolean
sameState
(DoubleAdder other) Check ifthis
and theother
DoubleAdder
maintain the same internal state.set
(double value) Set the adder to the givenvalue
.set
(DoubleAdder value) Set the adder to the givenvalue
.static double
sum
(double[] values) Return the sum of the given double array.toString()
double
value()
Methods inherited from class java.lang.Number
byteValue, shortValue
-
Constructor Details
-
DoubleAdder
Create a new adder with the given defaultvalue
.- Parameters:
value
- the initialvalue
of 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:
this
adder, for command chaining
-
set
Set the adder to the givenvalue
.- Parameters:
value
- the new adder value- Returns:
this
adder, for command chaining- Throws:
NullPointerException
- if the givenvalue
isnull
-
add
Add the givenvalue
to this adder, using the Kahan summation algorithm- Parameters:
value
- thevalue
to add- Returns:
this
adder, for command chaining
-
add
Add the given values to this adder.- Parameters:
values
- the values to add.- Returns:
this
adder, for command chaining
-
add
Add the givenvalue
to this adder, using the Kahan summation algorithm- Parameters:
value
- thevalue
to add- Returns:
this
adder, for command chaining- Throws:
NullPointerException
- if the givenvalue
isnull
-
combine
Add the givenvalue
to this adder, using the Kahan summation algorithm- Parameters:
other
- thevalue
to add- Returns:
this
adder, for command chaining- Throws:
NullPointerException
- if the givenvalue
isnull
-
value
-
intValue
-
longValue
-
floatValue
- Specified by:
floatValue
in classNumber
-
doubleValue
- Specified by:
doubleValue
in classNumber
-
compareTo
- Specified by:
compareTo
in interfaceComparable<DoubleAdder>
-
sameState
Check ifthis
and theother
DoubleAdder
maintain the same internal state.- Parameters:
other
- the other object- Returns:
true
ifthis
and theother
adder 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
.
-