commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pste...@apache.org
Subject cvs commit: jakarta-commons/math/src/java/org/apache/commons/math/stat/univariate/summary Product.java
Date Tue, 29 Jun 2004 06:06:13 GMT
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.
  + * <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 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


Mime
View raw message