Issue Details (XML | Word | Printable)

Key: LANG-381
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: Unassigned
Reporter: Thomas Vandahl
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
Commons Lang

NumberUtils.min(floatArray) returns wrong value if floatArray[0] happens to be Float.NaN

Created: 30/Nov/07 01:17 PM   Updated: 06/Jan/08 11:59 PM
Return to search
Component/s: None
Affects Version/s: 2.3
Fix Version/s: 2.4

Time Tracking:
Not Specified

File Attachments:
  Size
Text File Licensed for inclusion in ASF works LANG-381-both.patch 2008-01-05 08:31 AM Henri Yandell 17 kB
Text File Licensed for inclusion in ASF works LANG-381-IEEE-754r.patch 2008-01-05 07:47 AM Henri Yandell 5 kB
Text File Licensed for inclusion in ASF works LANG-381-JDK.patch 2008-01-05 07:33 AM Henri Yandell 3 kB

Resolution Date: 06/Jan/08 11:59 PM


 Description  « Hide
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.



 All   Comments   Work Log   Change History   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order
Henri Yandell made changes - 02/Dec/07 03:34 AM
Field Original Value New Value
Fix Version/s 2.4 [ 12312481 ]
Henri Yandell made changes - 05/Jan/08 07:33 AM
Attachment LANG-381-JDK.patch [ 12372553 ]
Henri Yandell made changes - 05/Jan/08 07:47 AM
Attachment LANG-381-IEEE-754r.patch [ 12372554 ]
Henri Yandell made changes - 05/Jan/08 08:31 AM
Attachment LANG-381-both.patch [ 12372559 ]
Henri Yandell made changes - 06/Jan/08 11:59 PM
Resolution Fixed [ 1 ]
Status Open [ 1 ] Closed [ 6 ]