[ 
https://issues.apache.org/jira/browse/LANG-381?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12547663
 ] 

Thomas Vandahl commented on LANG-381:
-------------------------------------

I see your point. I think the JavaDoc comment in Float.compareTo(Float) (since 
1.2) says what was intended:

"There are two ways in which comparisons performed by this method differ from 
those performed by the Java language numerical comparison operators (<, <=, ==, 
>= >) when applied to primitive floats:
- Float.NaN is considered by this method to be equal to itself and greater than 
all other float values (including Float.POSITIVE_INFINITY).
- 0.0f is considered by this method to be greater than -0.0f."

So assuming this is the correct way to do things, I guess the min-method should 
return 1.2 and the max-method should return NaN. In any case the result should 
not depend on the value of the first element of the array.

> NumberUtils.min(floatArray) returns wrong value if floatArray[0] happens to 
> be Float.NaN
> ----------------------------------------------------------------------------------------
>
>                 Key: LANG-381
>                 URL: https://issues.apache.org/jira/browse/LANG-381
>             Project: Commons Lang
>          Issue Type: Bug
>    Affects Versions: 2.3
>            Reporter: Thomas Vandahl
>             Fix For: 2.4
>
>
> The min() method of NumberUtils returns the wrong result if  the first value 
> of the array happens to be Float.NaN. The following code snippet shows the 
> behaviour:
>         float a[] = new float[] {(float) 1.2, Float.NaN, (float) 3.7, (float) 
> 27.0, (float) 42.0, Float.NaN};
>         float b[] = new float[] {Float.NaN, (float) 1.2, Float.NaN, (float) 
> 3.7, (float) 27.0, (float) 42.0, Float.NaN};
>         
>         float min = NumberUtils.min(a);
>         System.out.println("min(a): " + min); // output: 1.2
>         min = NumberUtils.min(b);
>         System.out.println("min(b): " + min); // output: NaN
> This problem may exist for double-arrays as well. 
> Proposal: Use Float.compare(float, float) or NumberUtils.compare(float, 
> float) to achieve a consistent result.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to