Skip to content

ordNumber is not compatible with IEEE 754 floats #306

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

Open
anttih opened this issue Jul 26, 2023 · 2 comments
Open

ordNumber is not compatible with IEEE 754 floats #306

anttih opened this issue Jul 26, 2023 · 2 comments

Comments

@anttih
Copy link

anttih commented Jul 26, 2023

purs compiles the following:

(1.0 < nan) == false

to

1.0 < nan === false

but if we instead go through the Ord API we can observe different behavior that is not compatible with IEEE 754:

compare 1.0 nan == GT

In addition to just being wrong, the more practical issue is that any alternative backend that does not inline the use of comparison operators to operators that implement IEEE 754 correctly won't pass the prelude test suite. For example backend-es does not pass the prelude test suite.

One simple fix that was floated around in Discord is to just remove the tests using NaN from the test suite and leave the behavior undefined.

@garyb
Copy link
Member

garyb commented Jul 26, 2023

This is one of the situations where Poset would have been nice to have, since comparing NaN with something should be NC.

There are issues with Eq too though, since NaN comparisons aren't reflexive.

@natefaubion
Copy link

I think the only solution for status quo is to consider NaN behavior undefined for the purposes of Eq and Ord, and we just shouldn't test it.

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