8214761: Bug in parallel Kahan summation implementation

Reviewed-by: darcy
This commit is contained in:
Ian Graves 2021-09-03 00:50:11 +00:00
parent 7fff22afe7
commit dd871819a0
5 changed files with 235 additions and 10 deletions

View file

@ -156,7 +156,9 @@ public class DoubleSummaryStatistics implements DoubleConsumer {
count += other.count;
simpleSum += other.simpleSum;
sumWithCompensation(other.sum);
sumWithCompensation(other.sumCompensation);
// Subtract compensation bits
sumWithCompensation(-other.sumCompensation);
min = Math.min(min, other.min);
max = Math.max(max, other.max);
}
@ -241,7 +243,7 @@ public class DoubleSummaryStatistics implements DoubleConsumer {
*/
public final double getSum() {
// Better error bounds to add both terms as the final sum
double tmp = sum + sumCompensation;
double tmp = sum - sumCompensation;
if (Double.isNaN(tmp) && Double.isInfinite(simpleSum))
// If the compensated sum is spuriously NaN from
// accumulating one or more same-signed infinite values,