You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Phil Steitz <ph...@gmail.com> on 2005/10/14 05:38:58 UTC

Re: DO NOT REPLY [Bug 37019] - [math] NaN handling in StatsUtil.min, StatsUtil.max methods

This should be discussed in a separate ticket against the Complex
class (done now - 37086).

The general policy in [math] is to use NaN consistently with floating
point arithemtic specs (IEEE 754 for real, C99x Annex G for complex
arithmetic) so for statistics such as Sum, Mean, etc. that involve
arithmetic computations, NaN values force the return value to be NaN.

The Min and Max order statistics ignore NaNs.  Slightly
inconsistently, the Percentile and Median order statistics use the
total ordering determined by Double.compareTo which considers NaN as
larger than any value (including Double.POSITIVE_INFINITY) and
consider NaNs in the computation.  All of this is specified in the
javadoc for these statistics.

Phil

>
> ------- Additional Comments From elharo@metalab.unc.edu  2005-10-13 16:45 -------
> The Complex class also has some questionable and undocumented behavior with
> respect to NaN (and Inf). It might be worthwhile considering on a general NaN
> policy for the math classes.
>
> --

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Re: DO NOT REPLY [Bug 37019] - [math] NaN handling in StatsUtil.min, StatsUtil.max methods

Posted by Kim van der Linde <ki...@kimvdlinde.com>.
Ok, that means that the patches for Min and Max should be as follows:

For class Max:

     public void increment(final double d)
     {
	if (!Double.isNaN(d))
	    value = (d > value) ? d : value;
         n++;
     }

     public double evaluate(final double[] values, final int begin, 
final int length)
     {
         double max = Double.NaN;
         if (test(values, begin, length))
         {
             max = values[begin];
             for (int i = begin; i < begin + length; i++)
	    {
	        if (!Double.isNaN(values[i]))
		    max = (max > values[i]) ? max : values[i];
             }
         }
         return max;
     }

and for class Min

     public void increment(final double d)
     {
	if (!Double.isNaN(d))
	    value = (d < value) ? d : value;
         n++;
     }

    public double evaluate(final double[] values,final int begin, final 
int length)
	{
         double min = Double.NaN;
         if (test(values, begin, length))
		{
             min = values[begin];
             for (int i = begin; i < begin + length; i++)
			{
				if (!Double.isNaN(values[i]))
	                min = (min < values[i]) ? min : values[i];
             }
         }
         return min;
     }

Kim
Phil Steitz wrote:

> This should be discussed in a separate ticket against the Complex
> class (done now - 37086).
> 
> The general policy in [math] is to use NaN consistently with floating
> point arithemtic specs (IEEE 754 for real, C99x Annex G for complex
> arithmetic) so for statistics such as Sum, Mean, etc. that involve
> arithmetic computations, NaN values force the return value to be NaN.
> 
> The Min and Max order statistics ignore NaNs.  Slightly
> inconsistently, the Percentile and Median order statistics use the
> total ordering determined by Double.compareTo which considers NaN as
> larger than any value (including Double.POSITIVE_INFINITY) and
> consider NaNs in the computation.  All of this is specified in the
> javadoc for these statistics.
> 
> Phil
> 
> 
>>------- Additional Comments From elharo@metalab.unc.edu  2005-10-13 16:45 -------
>>The Complex class also has some questionable and undocumented behavior with
>>respect to NaN (and Inf). It might be worthwhile considering on a general NaN
>>policy for the math classes.
>>
>>--
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-dev-help@jakarta.apache.org
> 

-- 
http://www.kimvdlinde.com

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org