]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/tests/ui/floating_point_mul_add.fixed
Auto merge of #99099 - Stargateur:phantomdata_debug, r=joshtriplett
[rust.git] / src / tools / clippy / tests / ui / floating_point_mul_add.fixed
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.mul_add(b, c);
22     let _ = a.mul_add(b, c);
23     let _ = 2.0f64.mul_add(4.0, a);
24     let _ = 2.0f64.mul_add(4., a);
25
26     let _ = a.mul_add(b, c);
27     let _ = a.mul_add(b, c);
28     let _ = (a * b).mul_add(c, d);
29
30     let _ = a.mul_add(b, c).mul_add(a.mul_add(b, c), a.mul_add(b, c)) + c;
31     let _ = 1234.567_f64.mul_add(45.67834_f64, 0.0004_f64);
32
33     let _ = a.mul_add(a, b).sqrt();
34
35     // Cases where the lint shouldn't be applied
36     let _ = (a * a + b * b).sqrt();
37 }