about summary refs log tree commit diff
path: root/src/tools/clippy/tests/ui/floating_point_log.fixed
diff options
context:
space:
mode:
Diffstat (limited to 'src/tools/clippy/tests/ui/floating_point_log.fixed')
-rw-r--r--src/tools/clippy/tests/ui/floating_point_log.fixed58
1 files changed, 58 insertions, 0 deletions
diff --git a/src/tools/clippy/tests/ui/floating_point_log.fixed b/src/tools/clippy/tests/ui/floating_point_log.fixed
new file mode 100644
index 00000000000..42c5e5d2bae
--- /dev/null
+++ b/src/tools/clippy/tests/ui/floating_point_log.fixed
@@ -0,0 +1,58 @@
+// run-rustfix
+#![allow(dead_code, clippy::double_parens)]
+#![warn(clippy::suboptimal_flops, clippy::imprecise_flops)]
+
+const TWO: f32 = 2.0;
+const E: f32 = std::f32::consts::E;
+
+fn check_log_base() {
+    let x = 1f32;
+    let _ = x.log2();
+    let _ = x.log10();
+    let _ = x.ln();
+    let _ = x.log2();
+    let _ = x.ln();
+
+    let x = 1f64;
+    let _ = x.log2();
+    let _ = x.log10();
+    let _ = x.ln();
+}
+
+fn check_ln1p() {
+    let x = 1f32;
+    let _ = 2.0f32.ln_1p();
+    let _ = 2.0f32.ln_1p();
+    let _ = x.ln_1p();
+    let _ = (x / 2.0).ln_1p();
+    let _ = x.powi(2).ln_1p();
+    let _ = (x.powi(2) / 2.0).ln_1p();
+    let _ = ((std::f32::consts::E - 1.0)).ln_1p();
+    let _ = x.ln_1p();
+    let _ = x.powi(2).ln_1p();
+    let _ = (x + 2.0).ln_1p();
+    let _ = (x / 2.0).ln_1p();
+    // Cases where the lint shouldn't be applied
+    let _ = (1.0 + x + 2.0).ln();
+    let _ = (x + 1.0 + 2.0).ln();
+    let _ = (x + 1.0 / 2.0).ln();
+    let _ = (1.0 + x - 2.0).ln();
+
+    let x = 1f64;
+    let _ = 2.0f64.ln_1p();
+    let _ = 2.0f64.ln_1p();
+    let _ = x.ln_1p();
+    let _ = (x / 2.0).ln_1p();
+    let _ = x.powi(2).ln_1p();
+    let _ = x.ln_1p();
+    let _ = x.powi(2).ln_1p();
+    let _ = (x + 2.0).ln_1p();
+    let _ = (x / 2.0).ln_1p();
+    // Cases where the lint shouldn't be applied
+    let _ = (1.0 + x + 2.0).ln();
+    let _ = (x + 1.0 + 2.0).ln();
+    let _ = (x + 1.0 / 2.0).ln();
+    let _ = (1.0 + x - 2.0).ln();
+}
+
+fn main() {}