[ https://issues.apache.org/jira/browse/LANG381?page=com.atlassian.jira.plugin.system.issuetabpanels:commenttabpanel#action_12547572
]
bayard edited comment on LANG381 at 12/1/07 8:43 PM:

Last spammy comment on this I promise....
This seems like a confusing bit. If we look at the JDK, we get:
Math.min(Double.NaN, 1.0) => NaN
Math.max(Double.NaN, 1.0) => NaN
However:
Double.compare(Double.NaN, 1.0) => 1
Double.compare(1.0, Double.NaN) => 1
That is, the JDK is not without its problems. It seems to me that the min/max methods need
to take their leads from the JDK ones. So the (double, double, double) ones are implicitly
correct as they are nothing more than wrappers for a couple of Math.min calls.
This bug is not that NaN is returned, but that 1.2 is returned.
ie) If NaN is found in min(double[]), then the min is NaN.
The same holds for max  it should never return 42.0 in the above example.
Thoughts?
was (Author: bayard):
Last spammy comment on this I promise....
This seems like a confusing bit. If we look at the JDK, we get:
Math.min(Double.NaN, 1.0) => NaN
Math.max(Double.NaN, 1.0) => NaN
However:
Double.compare(Double.NaN, 1.0) => 1
Double.compare(1.0, Double.NaN) => 1
That is, the JDK is not without its problems. It seems to me that the min/max methods need
to take their leads from the JDK ones. So the (double, double, double) ones are implicitly
correct as they are nothing more than wrappers for a couple of Math.min calls.
This bug is not that NaN is returned, but that 1.2 is returned.
ie) If NaN is found in min(double[]), then the min is NaN.
The same holds for max  it should never return 42.0 in the above example.
Thoughts?
> NumberUtils.min(floatArray) returns wrong value if floatArray[0] happens to be Float.NaN
> 
>
> Key: LANG381
> URL: https://issues.apache.org/jira/browse/LANG381
> 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 doublearrays 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.
