Closed
Description
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