From c24f331cb6d67118b6e1335d3ebcf95123e87fa8 Mon Sep 17 00:00:00 2001 From: Phil Steitz Date: Tue, 29 Jun 2004 14:50:21 +0000 Subject: [PATCH] Fixed, documented NaN handling. git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/math/trunk@141350 13f79535-47bb-0310-9956-ffa450edef68 --- .../math/stat/univariate/summary/Sum.java | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/java/org/apache/commons/math/stat/univariate/summary/Sum.java b/src/java/org/apache/commons/math/stat/univariate/summary/Sum.java index a9d043ea9..2af1293f1 100644 --- a/src/java/org/apache/commons/math/stat/univariate/summary/Sum.java +++ b/src/java/org/apache/commons/math/stat/univariate/summary/Sum.java @@ -20,9 +20,12 @@ import java.io.Serializable; import org.apache.commons.math.stat.univariate.AbstractStorelessUnivariateStatistic; /** - * The sum of the values that have been added to Univariate. - * - * @version $Revision: 1.20 $ $Date: 2004/06/23 16:26:16 $ + * Returns the sum of the available values. + *

+ * If there are no values in the dataset, or any of the values are + * NaN, then NaN is returned. + * + * @version $Revision: 1.21 $ $Date: 2004/06/29 14:50:21 $ */ public class Sum extends AbstractStorelessUnivariateStatistic implements Serializable { @@ -41,7 +44,7 @@ public class Sum extends AbstractStorelessUnivariateStatistic implements Seriali * @see org.apache.commons.math.stat.univariate.StorelessUnivariateStatistic#increment(double) */ public void increment(final double d) { - if (Double.isNaN(value)) { + if (n == 0) { value = d; } else { value += d; @@ -72,17 +75,15 @@ public class Sum extends AbstractStorelessUnivariateStatistic implements Seriali } /** - * The sum of the values that have been added to Univariate. + * The sum of the values that have been added. + * * @param values Is a double[] containing the values * @param begin processing at this point in the array * @param length the number of elements to include * @return the sum of the values or Double.NaN if the array is empty * @see org.apache.commons.math.stat.univariate.UnivariateStatistic#evaluate(double[], int, int) */ - public double evaluate( - final double[] values, - final int begin, - final int length) { + public double evaluate(final double[] values, final int begin, final int length) { double sum = Double.NaN; if (test(values, begin, length)) { sum = 0.0;