Skip to content

"square can be computed more efficiently" is wrong #7058

Closed
@RReverser

Description

@RReverser

Lint name:
suboptimal_flops

I tried this code:

#![warn(clippy::suboptimal_flops)]

pub fn sample_sqr(x: f64) -> f64 {
    x.powi(2)
}

I expected to see this happen: it should pass.

Instead, this happened: it says "square can be computed more efficiently" and suggests to use x * x instead.

This is incorrect, because, unlike powf, powi produces exactly same native code as x * x, and is more natural to read (IMO). If anything, due to usage of intrinsic, it might be optimised even more than bare expression, although they're unlikely to be different on practice.

Meta

  • cargo clippy -V: clippy 0.1.53 (2e495d2 2021-04-08)
  • rustc -Vv:
        rustc 1.53.0-nightly (2e495d2e8 2021-04-08)
        binary: rustc
        commit-hash: 2e495d2e845cf27740e3665f718acfd3aa17253e
        commit-date: 2021-04-08
        host: x86_64-unknown-linux-gnu
        release: 1.53.0-nightly
        LLVM version: 12.0.0
    

Metadata

Metadata

Assignees

Labels

C-bugCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't havegood 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