Gentle ping.
On 12/9/18 7:37 PM, Ivan Gerasimov wrote:
Hello!
DoubleSummaryStatistics takes advantage of Kahan summation algorithm
to reduce the error of the total sum.
Internally it maintains a field double sumCompensation, which keeps
lower bits (which were rounded off) of the last addition.
Note, that the compensation has to be subtracted from the result to
add those bits back:
166 private void sumWithCompensation(double value) {
167 double tmp = value - sumCompensation;
168 double velvel = sum + tmp; // Little wolf of rounding error
169 sumCompensation = (velvel - sum) - tmp;
170 sum = velvel;
171 }
At the line 169, tmp normally has more lower bits than (velvel - sum).
However, when two DoubleSummaryStatistics objects are combined, this
compensation part is *added* to the total, which may result in a less
accurate result.
The same bug is replicated in DoubleStreams.
Would you please help review the fix?
BUGURL: https://bugs.openjdk.java.net/browse/JDK-8214761
WEBREV: http://cr.openjdk.java.net/~igerasim/8214761/00/webrev/
--
With kind regards,
Ivan Gerasimov