2021-11-20 08:04:08 -06:00
|
|
|
#![feature(const_fn_floating_point_arithmetic)]
|
2020-02-23 02:04:11 -06:00
|
|
|
#![warn(clippy::suboptimal_flops)]
|
|
|
|
|
2021-11-20 08:04:08 -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.mul_add(b, c);
|
2022-10-02 23:00:51 -05:00
|
|
|
let _ = a.mul_add(b, -c);
|
2020-02-23 02:04:11 -06:00
|
|
|
let _ = a.mul_add(b, c);
|
2022-10-02 23:00:51 -05:00
|
|
|
let _ = a.mul_add(-b, c);
|
2020-02-23 02:04:11 -06:00
|
|
|
let _ = 2.0f64.mul_add(4.0, a);
|
|
|
|
let _ = 2.0f64.mul_add(4., a);
|
|
|
|
|
|
|
|
let _ = a.mul_add(b, c);
|
|
|
|
let _ = a.mul_add(b, c);
|
|
|
|
let _ = (a * b).mul_add(c, d);
|
|
|
|
|
|
|
|
let _ = a.mul_add(b, c).mul_add(a.mul_add(b, c), a.mul_add(b, c)) + c;
|
|
|
|
let _ = 1234.567_f64.mul_add(45.67834_f64, 0.0004_f64);
|
2020-05-25 11:54:39 -05:00
|
|
|
|
|
|
|
let _ = a.mul_add(a, b).sqrt();
|
|
|
|
|
2023-10-27 09:28:10 -05:00
|
|
|
let u = 1usize;
|
|
|
|
let _ = b.mul_add(-(u as f64), a);
|
|
|
|
|
2020-05-25 11:54:39 -05:00
|
|
|
// Cases where the lint shouldn't be applied
|
|
|
|
let _ = (a * a + b * b).sqrt();
|
2020-02-23 02:04:11 -06:00
|
|
|
}
|
2023-11-18 06:50:18 -06:00
|
|
|
|
|
|
|
fn _issue11831() {
|
|
|
|
struct NotAFloat;
|
|
|
|
|
|
|
|
impl std::ops::Add<f64> for NotAFloat {
|
|
|
|
type Output = Self;
|
|
|
|
|
|
|
|
fn add(self, _: f64) -> Self {
|
|
|
|
NotAFloat
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
let a = NotAFloat;
|
|
|
|
let b = 1.0_f64;
|
|
|
|
let c = 1.0;
|
|
|
|
|
|
|
|
let _ = a + b * c;
|
|
|
|
}
|