Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

#529 NaN ne NaN is false

v8.7.1
closed
Michael Kay
5
2012-10-08
2006-06-05
Michael Kay
No

The result of the comparison (NaN ne NaN) should be
true, but is currently false. The same problem occurs
if the != operator is used.

Source fix: in ValueComparison.java, method compare(),
line 500, change

if (v1 instanceof NumericValue &&
((NumericValue)v1).isNaN()) {
return false;
}

to:

if (v1 instanceof NumericValue &&
((NumericValue)v1).isNaN()) {
if (op == Token.FNE && v2 instanceof
NumericValue && ((NumericValue)v2).isNaN()) {
return true;
}
return false;
}

Discussion

  • Michael Kay
    Michael Kay
    2006-06-05

    Logged In: YES
    user_id=251681

    Correction to fix. The previous fix does not cover all
    cases. The rule is that if either operand of "ne" or "!=" is
    NaN, the result is true. So the code at the start of the
    compare() method should be changed from:

    if (v1 instanceof NumericValue && ((NumericValue)v1).isNaN()) {
    return false;
    }
    if (v2 instanceof NumericValue &&
    ((NumericValue)v2).isNaN()) {
    return false;
    }

    to:

    if (v1 instanceof NumericValue && ((NumericValue)v1).isNaN()) {
    return (op == Token.FNE);
    }
    if (v2 instanceof NumericValue &&
    ((NumericValue)v2).isNaN()) {
    return (op == Token.FNE);
    }