Files
rust/tests/ui/floating_point_hypot.rs

17 lines
488 B
Rust
Raw Normal View History

2020-06-17 13:43:11 -03:00
#![warn(clippy::imprecise_flops)]
fn main() {
let x = 3f32;
let y = 4f32;
let _ = (x * x + y * y).sqrt();
2025-02-11 17:57:08 +01:00
//~^ imprecise_flops
let _ = ((x + 1f32) * (x + 1f32) + y * y).sqrt();
2025-02-11 17:57:08 +01:00
//~^ imprecise_flops
let _ = (x.powi(2) + y.powi(2)).sqrt();
2025-02-11 17:57:08 +01:00
//~^ imprecise_flops
// Cases where the lint shouldn't be applied
2020-06-17 13:43:11 -03:00
// TODO: linting this adds some complexity, but could be done
let _ = x.mul_add(x, y * y).sqrt();
let _ = (x * 4f32 + y * y).sqrt();
}