You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Henri Yandell (JIRA)" <ji...@apache.org> on 2008/01/07 01:00:45 UTC
[jira] Closed: (LANG-381) NumberUtils.min(floatArray) returns wrong
value if floatArray[0] happens to be Float.NaN
[ https://issues.apache.org/jira/browse/LANG-381?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Henri Yandell closed LANG-381.
------------------------------
Resolution: Fixed
svn ci -m "Applying third patch from LANG-381. Fixes the minimum(float[]) type methods to correctly return NaN when it is in the array, and adds an IEEE754rUtils class that obeys the IEEE 754r update in which NaN in min/max methods should be ignored unless all values are NaN. " src
Adding src/java/org/apache/commons/lang/math/IEEE754rUtils.java
Sending src/java/org/apache/commons/lang/math/NumberUtils.java
Adding src/test/org/apache/commons/lang/math/IEEE754rUtilsTest.java
Sending src/test/org/apache/commons/lang/math/NumberUtilsTest.java
Transmitting file data ....
Committed revision 609475.
> 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
>
> Attachments: LANG-381-both.patch, LANG-381-IEEE-754r.patch, LANG-381-JDK.patch
>
>
> 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.