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
Warn equality with NaN #6643
Comments
Comment author: bouaziz Of course, the same applies for <, <=, >, >= |
Comment author: @damiendoligez I'm not sure I understand what you mean: the compiler cannot know in general whether a given float expression is going to be NaN. As for emitting a warning at run-time, that cannot be done because equality comparison must not do side-effects. |
Comment author: bouaziz I do not want a warning at runtime but it would be great to have it at compile time when comparing with Pervasives.nan. E.g. Of course it would not work with any other value being equal to nan (static analysis, e.g. optimization, could catch some of them though). E.g. Another way of seeing it is to optimize ... = nan (and I mean any value known at compile time to always be equal to nan) as false and then report dead branches like the "then" branch in the previous examples. |
Comment author: @alainfrisch Careful with optimizations: you probably don't want to trigger a warning after inlining a function which results in comparing a float with NaN, as in: let f lim x = let g = f nan x |
Comment author: @xavierleroy The use case is uncommon, and there are limits to the number of special cases the compiler can reasonably warn about. Suspending this PR. |
Original bug ID: 6643
Reporter: bouaziz
Status: resolved (set by @xavierleroy on 2015-12-06T16:19:17Z)
Resolution: suspended
Priority: low
Severity: feature
Category: ~DO NOT USE (was: OCaml general)
Bug description
Since x = nan will always be false for any x, a warning should be issued telling the user to use Pervasives.compare instead
The text was updated successfully, but these errors were encountered: