psteitz 2004/06/29 07:50:21 Modified: math/src/java/org/apache/commons/math/stat/univariate/summary Sum.java Log: Fixed, documented NaN handling. Revision Changes Path 1.21 +10 -9 jakarta-commons/math/src/java/org/apache/commons/math/stat/univariate/summary/Sum.java Index: Sum.java =================================================================== RCS file: /home/cvs/jakarta-commons/math/src/java/org/apache/commons/math/stat/univariate/summary/Sum.java,v retrieving revision 1.20 retrieving revision 1.21 diff -u -r1.20 -r1.21 --- Sum.java 23 Jun 2004 16:26:16 -0000 1.20 +++ Sum.java 29 Jun 2004 14:50:21 -0000 1.21 @@ -20,8 +20,11 @@ import org.apache.commons.math.stat.univariate.AbstractStorelessUnivariateStatistic; /** - * The sum of the values that have been added to Univariate. - * + * Returns the sum of the available values. + * <p> + * If there are no values in the dataset, or any of the values are + * <code>NaN</code>, then <code>NaN</code> is returned. + * * @version $Revision$ $Date$ */ public class Sum extends AbstractStorelessUnivariateStatistic implements Serializable { @@ -41,7 +44,7 @@ * @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 @@ } /** - * 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;
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]