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

float_cmp should not apply to results of signum() #4248

Closed
danburkert opened this issue Jul 2, 2019 · 2 comments · Fixed by #4275
Closed

float_cmp should not apply to results of signum() #4248

danburkert opened this issue Jul 2, 2019 · 2 comments · Fixed by #4275
Labels
C-enhancement Category: Enhancement of lints, like adding more cases or adding help messages good-first-issue These issues are a good way to get started with Clippy L-correctness Lint: Belongs in the correctness lint group

Comments

@danburkert
Copy link

danburkert commented Jul 2, 2019

Hello,

It seems to me that clippy should allow the results of two calls to f{32, 64}::signum() to be compared, e.g a contrived example:

fn signs_agree(f1: f64, f2: f64) -> bool {
   return f1.signum() == f2.signum()
}

results in:

error: strict comparison of f32 or f64
 --> src/main.rs:3:4
  |
3 |    f1.signum() == f2.signum()
  |    ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider comparing them within some error: `(f1.signum() - f2.signum()).abs() < error`
  |
  = note: #[deny(clippy::float_cmp)] on by default
note: std::f32::EPSILON and std::f64::EPSILON are available.
 --> src/main.rs:3:4
  |
3 |    f1.signum() == f2.signum()
  |    ^^^^^^^^^^^^^^^^^^^^^^^^^^
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#float_cmp
@flip1995 flip1995 added L-correctness Lint: Belongs in the correctness lint group good-first-issue These issues are a good way to get started with Clippy C-enhancement Category: Enhancement of lints, like adding more cases or adding help messages labels Jul 3, 2019
@jayhardee9
Copy link
Contributor

Can I take this one on?

@flip1995
Copy link
Member

It's all yours. Let us know if you have any questions.

bors added a commit that referenced this issue Jul 16, 2019
Fix float_cmp false positive when comparing signum

fixes #4248

changelog: Fix float_cmp false positive when comparing signum
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-enhancement Category: Enhancement of lints, like adding more cases or adding help messages good-first-issue These issues are a good way to get started with Clippy L-correctness Lint: Belongs in the correctness lint group
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants