Return-Path: Delivered-To: apmail-jakarta-commons-dev-archive@www.apache.org Received: (qmail 92481 invoked from network); 29 Jun 2004 06:06:27 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur-2.apache.org with SMTP; 29 Jun 2004 06:06:27 -0000 Received: (qmail 85805 invoked by uid 500); 29 Jun 2004 06:06:45 -0000 Delivered-To: apmail-jakarta-commons-dev-archive@jakarta.apache.org Received: (qmail 85684 invoked by uid 500); 29 Jun 2004 06:06:43 -0000 Mailing-List: contact commons-dev-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Jakarta Commons Developers List" Reply-To: "Jakarta Commons Developers List" Delivered-To: mailing list commons-dev@jakarta.apache.org Received: (qmail 85619 invoked by uid 500); 29 Jun 2004 06:06:42 -0000 Received: (qmail 85564 invoked by uid 99); 29 Jun 2004 06:06:40 -0000 X-ASF-Spam-Status: No, hits=0.5 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [209.237.227.194] (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.27.1) with SMTP; Mon, 28 Jun 2004 23:06:39 -0700 Received: (qmail 92377 invoked by uid 1718); 29 Jun 2004 06:06:13 -0000 Date: 29 Jun 2004 06:06:13 -0000 Message-ID: <20040629060613.92376.qmail@minotaur.apache.org> From: psteitz@apache.org To: jakarta-commons-cvs@apache.org Subject: cvs commit: jakarta-commons/math/src/java/org/apache/commons/math/stat/univariate/summary Product.java X-Virus-Checked: Checked X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N psteitz 2004/06/28 23:06:13 Modified: math/src/java/org/apache/commons/math/stat/univariate/summary Product.java Log: Documented and fixed NaN handling. Revision Changes Path 1.19 +12 -17 jakarta-commons/math/src/java/org/apache/commons/math/stat/univariate/summary/Product.java Index: Product.java =================================================================== RCS file: /home/cvs/jakarta-commons/math/src/java/org/apache/commons/math/stat/univariate/summary/Product.java,v retrieving revision 1.18 retrieving revision 1.19 diff -u -r1.18 -r1.19 --- Product.java 23 Jun 2004 16:26:16 -0000 1.18 +++ Product.java 29 Jun 2004 06:06:13 -0000 1.19 @@ -17,17 +17,14 @@ import java.io.Serializable; -import org - .apache - .commons - .math - .stat - .univariate - .AbstractStorelessUnivariateStatistic; +import org.apache.commons.math.stat.univariate.AbstractStorelessUnivariateStatistic; /** - * Returns the product for this collection of values. - * + * Returns the product 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$ $Date$ */ public class Product extends AbstractStorelessUnivariateStatistic implements Serializable { @@ -35,8 +32,8 @@ /** Serializable version identifier */ static final long serialVersionUID = 2824226005990582538L; - /** */ - private int n = 0; + /**The number of values that have been added */ + private long n = 0; /** * The current Running Product. @@ -47,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; @@ -79,16 +76,14 @@ /** * Returns the product for this collection of values + * * @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 product 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 product = Double.NaN; if (test(values, begin, length)) { product = 1.0; --------------------------------------------------------------------- To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org For additional commands, e-mail: commons-dev-help@jakarta.apache.org