Repository navigation
Fix != to return true when either operand is NaN - #295
Open
SABITHSAHEB wants to merge 1 commit into
Open
SABITHSAHEB wants to merge 1 commit into
SABITHSAHEB wants to merge 1 commit into
Conversation
XPath 1.0 section 3.4 compares numbers per IEEE 754, where NaN is not equal to anything, including itself: '=' with a NaN operand is false and '!=' is true. CoreOperationCompare.equal returned false early for NaN before the 'result ^ invert' step that implements '!=', so both operators answered false. Java's == on doubles already follows IEEE 754, so the early returns are removed and the comparison result flows through the inversion. Completes JXPATH-95.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Thanks for your contribution to Apache Commons!
mvn; that'smvnon the command line by itself.CoreOperationCompare.equal, the shared evaluator for=and!=, returns false early when either operand converts to NaN, which bypasses theresult ^ invertstep that turns the equality result into!=. XPath 1.0 section 3.4 compares numbers per IEEE 754, where NaN is not equal to anything, including itself, so$nan = $nanis false but$nan != $nan,$nan != 0andnumber('foo') != 1must all be true; Xalan and libxml2 both answer true. JXPath answers false for both operators, so a predicate liketxns[amount != 0]silently drops a node whose caller-suppliedamountis a non-numeric string (its number value is NaN) instead of selecting it, and a filter written to catch every value different from the expected one is bypassed by a value that does not parse as a number.This completes JXPATH-95: the reporter pointed out there that
$nan != 1must be true, but the follow-up commit 40689aa made every NaN comparison return false and encoded that intestNan. Java's==on doubles already follows IEEE 754, so the fix deletes the early returns and lets the comparison flow through the inversion.=,<,>,<=,>=with NaN all stay false, and empty node-set comparisons are unaffected (testEmptyNodeSetOperationsstill passes). The updatedtestNanexpectations and the new string-coercion assertions fail on the current code and pass with the fix; the defaultmvngoal passes.