2023-04-23 06:03:09 -05:00
|
|
|
//@run-rustfix
|
2021-12-06 05:33:31 -06:00
|
|
|
#![feature(const_fn_floating_point_arithmetic)]
|
2020-02-23 02:04:11 -06:00
|
|
|
#![warn(clippy::suboptimal_flops)]
|
|
|
|
|
2021-12-06 05:33:31 -06:00
|
|
|
/// Allow suboptimal_ops in constant context
|
|
|
|
pub const fn in_const_context() {
|
|
|
|
let a: f64 = 1234.567;
|
|
|
|
let b: f64 = 45.67834;
|
|
|
|
let c: f64 = 0.0004;
|
|
|
|
|
|
|
|
let _ = a * b + c;
|
|
|
|
let _ = c + a * b;
|
|
|
|
}
|
|
|
|
|
2020-02-23 02:04:11 -06:00
|
|
|
fn main() {
|
|
|
|
let a: f64 = 1234.567;
|
|
|
|
let b: f64 = 45.67834;
|
|
|
|
let c: f64 = 0.0004;
|
|
|
|
let d: f64 = 0.0001;
|
|
|
|
|
|
|
|
let _ = a * b + c;
|
2022-10-06 02:44:38 -05:00
|
|
|
let _ = a * b - c;
|
2020-02-23 02:04:11 -06:00
|
|
|
let _ = c + a * b;
|
2022-10-06 02:44:38 -05:00
|
|
|
let _ = c - a * b;
|
2020-02-23 02:04:11 -06:00
|
|
|
let _ = a + 2.0 * 4.0;
|
|
|
|
let _ = a + 2. * 4.;
|
|
|
|
|
|
|
|
let _ = (a * b) + c;
|
|
|
|
let _ = c + (a * b);
|
|
|
|
let _ = a * b * c + d;
|
|
|
|
|
|
|
|
let _ = a.mul_add(b, c) * a.mul_add(b, c) + a.mul_add(b, c) + c;
|
|
|
|
let _ = 1234.567_f64 * 45.67834_f64 + 0.0004_f64;
|
2020-07-14 07:59:59 -05:00
|
|
|
|
|
|
|
let _ = (a * a + b).sqrt();
|
|
|
|
|
|
|
|
// Cases where the lint shouldn't be applied
|
|
|
|
let _ = (a * a + b * b).sqrt();
|
2020-02-23 02:04:11 -06:00
|
|
|
}
|