Rust-clippy: float_cmp should not apply to results of signum()

Created on 2 Jul 2019  路  2Comments  路  Source: rust-lang/rust-clippy

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
A-correctness L-enhancement good-first-issue

Most helpful comment

Can I take this one on?

All 2 comments

Can I take this one on?

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

Was this page helpful?
0 / 5 - 0 ratings