Skip to content

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

Closed
@danburkert

Description

@danburkert

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-enhancementCategory: Enhancement of lints, like adding more cases or adding help messagesL-correctnessLint: Belongs in the correctness lint groupgood first issueThese issues are a good way to get started with Clippy

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions