]> git.lizzy.rs Git - rust.git/blobdiff - tests/ui/floating_point_mul_add.fixed
Auto merge of #8374 - Alexendoo:bless-revisions, r=camsteffen
[rust.git] / tests / ui / floating_point_mul_add.fixed
index e343c37740da5f8207c5999238b2f48655914e35..169ec02f82be6d1769b2eb7581d8a907dc096d7e 100644 (file)
@@ -1,6 +1,17 @@
 // run-rustfix
+#![feature(const_fn_floating_point_arithmetic)]
 #![warn(clippy::suboptimal_flops)]
 
+/// 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;
+}
+
 fn main() {
     let a: f64 = 1234.567;
     let b: f64 = 45.67834;
@@ -18,4 +29,9 @@ fn main() {
 
     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);
+
+    let _ = a.mul_add(a, b).sqrt();
+
+    // Cases where the lint shouldn't be applied
+    let _ = (a * a + b * b).sqrt();
 }