Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect NaN handling #115

Open
waldemarhorwat opened this issue Apr 4, 2024 · 2 comments
Open

Incorrect NaN handling #115

waldemarhorwat opened this issue Apr 4, 2024 · 2 comments

Comments

@waldemarhorwat
Copy link

The proposed specification of regular comparisons involving NaNs produces incorrect results per the IEEE 754 spec, which states that a NaN should compare as neither equal, less than, nor greater than anything.

@jessealama
Copy link
Collaborator

Thanks for spotting that. I took a look at the spec again. If I understand it correctly, we can compare quiet NaN (which is the only kind of NaN that we intend to model in this proposal, as it currently stands) with any other value using equals, without throwing. If that's right, the next question is: what value should be returned? Looking again at the spec, you're right that (quiet) NaN should not be equal to anything else. I guess the equals function could return undefined in that case?

undefined is an odd thing for a predicate to return, though. I wonder if these considerations suggest reverting to an earlier line of thinking with this proposal, where we only had a cmp operation (no lessThan or equals) that would return -1, 0, 1, and undefined.

As for lessThan, I see you're right. It looks like an exception ought to be thrown if either argument is NaN, even a quiet NaN. Perhaps we should throw an exception (RangeException seems most appropriate to me).

Does that match your understanding?

@littledan
Copy link
Member

Thanks for catching this. Let's just follow the IEEE 754 spec, as we do for Number, and return false. The intention of this proposal is to follow IEEE 754, and I hope it's OK for us to land fixes like this during Stage 2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants