commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Phil Steitz (JIRA)" <j...@apache.org>
Subject [jira] Commented: (LANG-381) NumberUtils.min(floatArray) returns wrong value if floatArray[0] happens to be Float.NaN
Date Tue, 04 Dec 2007 03:32:43 GMT

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

Phil Steitz commented on LANG-381:
----------------------------------

The orignial IEEE 754 spec prescribes behavior like the JDK, i.e. min(x, NaN) = max(x, NaN)
= NaN.  This is under discussion for change in IEEE 745r.  See [1] for a summary of the issues.
  The rationale for returning NaN in these cases is to propagate the signal that something
has gone awry in computation somewhere - *not* to pretend that the comparison actually makes
sense.   A better approach for most applications, IMO, is to treat NaNs as missing data, especially
in cases like the present where they appear as elements in a set.  In any case, the important
thing is to document clearly what the API contract is.  I will adapt the [math] code and test
cases if this is what we want to do for lang.

[1] http://en.wikipedia.org/wiki/NaN

> 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.


Mime
View raw message