--- a/jdk/src/share/classes/java/util/DoubleSummaryStatistics.java Fri Jan 03 09:49:08 2014 -0800
+++ b/jdk/src/share/classes/java/util/DoubleSummaryStatistics.java Fri Jan 03 10:38:23 2014 -0800
@@ -64,6 +64,7 @@
private long count;
private double sum;
private double sumCompensation; // Low order bits of sum
+ private double simpleSum; // Used to compute right sum for non-finite inputs
private double min = Double.POSITIVE_INFINITY;
private double max = Double.NEGATIVE_INFINITY;
@@ -82,6 +83,7 @@
@Override
public void accept(double value) {
++count;
+ simpleSum += value;
sumWithCompensation(value);
min = Math.min(min, value);
max = Math.max(max, value);
@@ -96,6 +98,7 @@
*/
public void combine(DoubleSummaryStatistics other) {
count += other.count;
+ simpleSum += other.simpleSum;
sumWithCompensation(other.sum);
sumWithCompensation(other.sumCompensation);
min = Math.min(min, other.min);
@@ -147,7 +150,15 @@
*/
public final double getSum() {
// Better error bounds to add both terms as the final sum
- return 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,
+ // return the correctly-signed infinity stored in
+ // simpleSum.
+ return simpleSum;
+ else
+ return tmp;
}
/**