]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/tests/ui/floating_point_mul_add.rs
Auto merge of #97944 - nikic:freebsd-update, r=Mark-Simulacrum
[rust.git] / src / tools / clippy / tests / ui / floating_point_mul_add.rs
1 // run-rustfix
2 #![feature(const_fn_floating_point_arithmetic)]
3 #![warn(clippy::suboptimal_flops)]
4
5 /// Allow suboptimal_ops in constant context
6 pub const fn in_const_context() {
7     let a: f64 = 1234.567;
8     let b: f64 = 45.67834;
9     let c: f64 = 0.0004;
10
11     let _ = a * b + c;
12     let _ = c + a * b;
13 }
14
15 fn main() {
16     let a: f64 = 1234.567;
17     let b: f64 = 45.67834;
18     let c: f64 = 0.0004;
19     let d: f64 = 0.0001;
20
21     let _ = a * b + c;
22     let _ = c + a * b;
23     let _ = a + 2.0 * 4.0;
24     let _ = a + 2. * 4.;
25
26     let _ = (a * b) + c;
27     let _ = c + (a * b);
28     let _ = a * b * c + d;
29
30     let _ = a.mul_add(b, c) * a.mul_add(b, c) + a.mul_add(b, c) + c;
31     let _ = 1234.567_f64 * 45.67834_f64 + 0.0004_f64;
32
33     let _ = (a * a + b).sqrt();
34
35     // Cases where the lint shouldn't be applied
36     let _ = (a * a + b * b).sqrt();
37 }