Made increment and evaluate methods consistent wrt NaN values, improved javadoc, formatting.

git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/math/trunk@141318 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Phil Steitz 2004-06-18 13:24:06 +00:00
parent e5ea3a0485
commit d3322d7d6c
1 changed files with 15 additions and 15 deletions

View File

@ -17,35 +17,38 @@ package org.apache.commons.math.stat.univariate.rank;
import java.io.Serializable; import java.io.Serializable;
import org import org.apache.commons.math.stat.univariate.AbstractStorelessUnivariateStatistic;
.apache
.commons
.math
.stat
.univariate
.AbstractStorelessUnivariateStatistic;
/** /**
* Returns the maximum of the available values. * Returns the maximum of the available values.
* <p>
* <ul>
* <li>The result is <code>NaN</code> iff all values are <code>NaN</code>
* (i.e. <code>NaN</code> values have no impact on the value of the statistic).</li>
* <li>If any of the values equals <code>Double.POSITIVE_INFINITY</code>,
* the result is <code>Double.POSITIVE_INFINITY.</code></li>
* </ul>
* *
* @version $Revision: 1.16 $ $Date: 2004/04/27 16:42:33 $ * @version $Revision: 1.17 $ $Date: 2004/06/18 13:24:06 $
*/ */
public class Max extends AbstractStorelessUnivariateStatistic implements Serializable { public class Max extends AbstractStorelessUnivariateStatistic implements Serializable {
/** Serializable version identifier */ /** Serializable version identifier */
static final long serialVersionUID = -5593383832225844641L; static final long serialVersionUID = -5593383832225844641L;
/** */ /** Number of values that have been added */
private long n = 0; private long n = 0;
/** */ /** Current value of the statistic */
private double value = Double.NaN; private double value = Double.NaN;
/** /**
* @see org.apache.commons.math.stat.univariate.StorelessUnivariateStatistic#increment(double) * @see org.apache.commons.math.stat.univariate.StorelessUnivariateStatistic#increment(double)
*/ */
public void increment(final double d) { public void increment(final double d) {
value = Double.isNaN(value) ? d : Math.max(value, d); if (d > value || Double.isNaN(value)) {
value = d;
}
n++; n++;
} }
@ -76,10 +79,7 @@ public class Max extends AbstractStorelessUnivariateStatistic implements Seriali
* *
* @see org.apache.commons.math.stat.univariate.UnivariateStatistic#evaluate(double[], int, int) * @see org.apache.commons.math.stat.univariate.UnivariateStatistic#evaluate(double[], int, int)
*/ */
public double evaluate( public double evaluate(final double[] values, final int begin, final int length) {
final double[] values,
final int begin,
final int length) {
double max = Double.NaN; double max = Double.NaN;
if (test(values, begin, length)) { if (test(values, begin, length)) {
max = values[begin]; max = values[begin];