]> git.lizzy.rs Git - rust.git/commitdiff
Split test cases into separate files
authorKrishna Veera Reddy <veerareddy@email.arizona.edu>
Sat, 21 Dec 2019 01:57:47 +0000 (17:57 -0800)
committerKrishna Sai Veera Reddy <veerareddy@email.arizona.edu>
Mon, 24 Feb 2020 06:20:34 +0000 (22:20 -0800)
tests/ui/floating_point_arithmetic.rs [deleted file]
tests/ui/floating_point_arithmetic.stderr [deleted file]
tests/ui/floating_point_exp.rs [new file with mode: 0644]
tests/ui/floating_point_exp.stderr [new file with mode: 0644]
tests/ui/floating_point_log.rs [new file with mode: 0644]
tests/ui/floating_point_log.stderr [new file with mode: 0644]
tests/ui/floating_point_powf.rs [new file with mode: 0644]
tests/ui/floating_point_powf.stderr [new file with mode: 0644]

diff --git a/tests/ui/floating_point_arithmetic.rs b/tests/ui/floating_point_arithmetic.rs
deleted file mode 100644 (file)
index ff59494..0000000
+++ /dev/null
@@ -1,111 +0,0 @@
-#![allow(dead_code)]
-#![warn(clippy::floating_point_improvements)]
-
-const TWO: f32 = 2.0;
-const E: f32 = std::f32::consts::E;
-
-fn check_log_base() {
-    let x = 1f32;
-    let _ = x.log(2f32);
-    let _ = x.log(10f32);
-    let _ = x.log(std::f32::consts::E);
-    let _ = x.log(TWO);
-    let _ = x.log(E);
-
-    let x = 1f64;
-    let _ = x.log(2f64);
-    let _ = x.log(10f64);
-    let _ = x.log(std::f64::consts::E);
-}
-
-fn check_ln1p() {
-    let x = 1f32;
-    let _ = (1.0 + x).ln();
-    let _ = (1.0 + x * 2.0).ln();
-    let _ = (1.0 + x.powi(2)).ln();
-    let _ = (1.0 + x.powi(2) * 2.0).ln();
-    let _ = (1.0 + (std::f32::consts::E - 1.0)).ln();
-    // Cases where the lint shouldn't be applied
-    let _ = (x + 1.0).ln();
-    let _ = (1.0 + x + 2.0).ln();
-    let _ = (1.0 + x - 2.0).ln();
-
-    let x = 1f64;
-    let _ = (1.0 + x).ln();
-    let _ = (1.0 + x * 2.0).ln();
-    let _ = (1.0 + x.powi(2)).ln();
-    // Cases where the lint shouldn't be applied
-    let _ = (x + 1.0).ln();
-    let _ = (1.0 + x + 2.0).ln();
-    let _ = (1.0 + x - 2.0).ln();
-}
-
-fn check_powf() {
-    let x = 3f32;
-    let _ = 2f32.powf(x);
-    let _ = std::f32::consts::E.powf(x);
-    let _ = x.powf(1.0 / 2.0);
-    let _ = x.powf(1.0 / 3.0);
-    let _ = x.powf(2.0);
-    let _ = x.powf(-2.0);
-    let _ = x.powf(2.1);
-    let _ = x.powf(-2.1);
-    let _ = x.powf(16_777_217.0);
-    let _ = x.powf(-16_777_217.0);
-
-    let x = 3f64;
-    let _ = 2f64.powf(x);
-    let _ = std::f64::consts::E.powf(x);
-    let _ = x.powf(1.0 / 2.0);
-    let _ = x.powf(1.0 / 3.0);
-    let _ = x.powf(2.0);
-    let _ = x.powf(-2.0);
-    let _ = x.powf(2.1);
-    let _ = x.powf(-2.1);
-    let _ = x.powf(9_007_199_254_740_993.0);
-    let _ = x.powf(-9_007_199_254_740_993.0);
-}
-
-fn check_expm1() {
-    let x = 2f32;
-    let _ = x.exp() - 1.0;
-    let _ = x.exp() - 1.0 + 2.0;
-    // Cases where the lint shouldn't be applied
-    let _ = x.exp() - 2.0;
-    let _ = x.exp() - 1.0 * 2.0;
-
-    let x = 2f64;
-    let _ = x.exp() - 1.0;
-    let _ = x.exp() - 1.0 + 2.0;
-    // Cases where the lint shouldn't be applied
-    let _ = x.exp() - 2.0;
-    let _ = x.exp() - 1.0 * 2.0;
-}
-
-fn check_log_division() {
-    let x = 3f32;
-    let y = 2f32;
-    let b = 4f32;
-
-    let _ = x.log2() / y.log2();
-    let _ = x.log10() / y.log10();
-    let _ = x.ln() / y.ln();
-    let _ = x.log(4.0) / y.log(4.0);
-    let _ = x.log(b) / y.log(b);
-    let _ = x.log(b) / y.log(x);
-    let _ = x.log(b) / 2f32.log(b);
-
-    let x = 3f64;
-    let y = 2f64;
-    let b = 4f64;
-
-    let _ = x.log2() / y.log2();
-    let _ = x.log10() / y.log10();
-    let _ = x.ln() / y.ln();
-    let _ = x.log(4.0) / y.log(4.0);
-    let _ = x.log(b) / y.log(b);
-    let _ = x.log(b) / y.log(x);
-    let _ = x.log(b) / 2f64.log(b);
-}
-
-fn main() {}
diff --git a/tests/ui/floating_point_arithmetic.stderr b/tests/ui/floating_point_arithmetic.stderr
deleted file mode 100644 (file)
index 076b8d4..0000000
+++ /dev/null
@@ -1,268 +0,0 @@
-error: logarithm for bases 2, 10 and e can be computed more accurately
-  --> $DIR/floating_point_arithmetic.rs:9:13
-   |
-LL |     let _ = x.log(2f32);
-   |             ^^^^^^^^^^^ help: consider using: `x.log2()`
-   |
-   = note: `-D clippy::floating-point-improvements` implied by `-D warnings`
-
-error: logarithm for bases 2, 10 and e can be computed more accurately
-  --> $DIR/floating_point_arithmetic.rs:10:13
-   |
-LL |     let _ = x.log(10f32);
-   |             ^^^^^^^^^^^^ help: consider using: `x.log10()`
-
-error: logarithm for bases 2, 10 and e can be computed more accurately
-  --> $DIR/floating_point_arithmetic.rs:11:13
-   |
-LL |     let _ = x.log(std::f32::consts::E);
-   |             ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `x.ln()`
-
-error: logarithm for bases 2, 10 and e can be computed more accurately
-  --> $DIR/floating_point_arithmetic.rs:12:13
-   |
-LL |     let _ = x.log(TWO);
-   |             ^^^^^^^^^^ help: consider using: `x.log2()`
-
-error: logarithm for bases 2, 10 and e can be computed more accurately
-  --> $DIR/floating_point_arithmetic.rs:13:13
-   |
-LL |     let _ = x.log(E);
-   |             ^^^^^^^^ help: consider using: `x.ln()`
-
-error: logarithm for bases 2, 10 and e can be computed more accurately
-  --> $DIR/floating_point_arithmetic.rs:16:13
-   |
-LL |     let _ = x.log(2f64);
-   |             ^^^^^^^^^^^ help: consider using: `x.log2()`
-
-error: logarithm for bases 2, 10 and e can be computed more accurately
-  --> $DIR/floating_point_arithmetic.rs:17:13
-   |
-LL |     let _ = x.log(10f64);
-   |             ^^^^^^^^^^^^ help: consider using: `x.log10()`
-
-error: logarithm for bases 2, 10 and e can be computed more accurately
-  --> $DIR/floating_point_arithmetic.rs:18:13
-   |
-LL |     let _ = x.log(std::f64::consts::E);
-   |             ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `x.ln()`
-
-error: ln(1 + x) can be computed more accurately
-  --> $DIR/floating_point_arithmetic.rs:23:13
-   |
-LL |     let _ = (1.0 + x).ln();
-   |             ^^^^^^^^^^^^^^ help: consider using: `x.ln_1p()`
-
-error: ln(1 + x) can be computed more accurately
-  --> $DIR/floating_point_arithmetic.rs:24:13
-   |
-LL |     let _ = (1.0 + x * 2.0).ln();
-   |             ^^^^^^^^^^^^^^^^^^^^ help: consider using: `(x * 2.0).ln_1p()`
-
-error: ln(1 + x) can be computed more accurately
-  --> $DIR/floating_point_arithmetic.rs:25:13
-   |
-LL |     let _ = (1.0 + x.powi(2)).ln();
-   |             ^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `x.powi(2).ln_1p()`
-
-error: ln(1 + x) can be computed more accurately
-  --> $DIR/floating_point_arithmetic.rs:26:13
-   |
-LL |     let _ = (1.0 + x.powi(2) * 2.0).ln();
-   |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `(x.powi(2) * 2.0).ln_1p()`
-
-error: ln(1 + x) can be computed more accurately
-  --> $DIR/floating_point_arithmetic.rs:27:13
-   |
-LL |     let _ = (1.0 + (std::f32::consts::E - 1.0)).ln();
-   |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `((std::f32::consts::E - 1.0)).ln_1p()`
-
-error: ln(1 + x) can be computed more accurately
-  --> $DIR/floating_point_arithmetic.rs:34:13
-   |
-LL |     let _ = (1.0 + x).ln();
-   |             ^^^^^^^^^^^^^^ help: consider using: `x.ln_1p()`
-
-error: ln(1 + x) can be computed more accurately
-  --> $DIR/floating_point_arithmetic.rs:35:13
-   |
-LL |     let _ = (1.0 + x * 2.0).ln();
-   |             ^^^^^^^^^^^^^^^^^^^^ help: consider using: `(x * 2.0).ln_1p()`
-
-error: ln(1 + x) can be computed more accurately
-  --> $DIR/floating_point_arithmetic.rs:36:13
-   |
-LL |     let _ = (1.0 + x.powi(2)).ln();
-   |             ^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `x.powi(2).ln_1p()`
-
-error: exponent for bases 2 and e can be computed more accurately
-  --> $DIR/floating_point_arithmetic.rs:45:13
-   |
-LL |     let _ = 2f32.powf(x);
-   |             ^^^^^^^^^^^^ help: consider using: `x.exp2()`
-
-error: exponent for bases 2 and e can be computed more accurately
-  --> $DIR/floating_point_arithmetic.rs:46:13
-   |
-LL |     let _ = std::f32::consts::E.powf(x);
-   |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `x.exp()`
-
-error: square-root of a number can be computed more efficiently and accurately
-  --> $DIR/floating_point_arithmetic.rs:47:13
-   |
-LL |     let _ = x.powf(1.0 / 2.0);
-   |             ^^^^^^^^^^^^^^^^^ help: consider using: `x.sqrt()`
-
-error: cube-root of a number can be computed more accurately
-  --> $DIR/floating_point_arithmetic.rs:48:13
-   |
-LL |     let _ = x.powf(1.0 / 3.0);
-   |             ^^^^^^^^^^^^^^^^^ help: consider using: `x.cbrt()`
-
-error: exponentiation with integer powers can be computed more efficiently
-  --> $DIR/floating_point_arithmetic.rs:49:13
-   |
-LL |     let _ = x.powf(2.0);
-   |             ^^^^^^^^^^^ help: consider using: `x.powi(2)`
-
-error: exponentiation with integer powers can be computed more efficiently
-  --> $DIR/floating_point_arithmetic.rs:50:13
-   |
-LL |     let _ = x.powf(-2.0);
-   |             ^^^^^^^^^^^^ help: consider using: `x.powi(-2)`
-
-error: exponent for bases 2 and e can be computed more accurately
-  --> $DIR/floating_point_arithmetic.rs:57:13
-   |
-LL |     let _ = 2f64.powf(x);
-   |             ^^^^^^^^^^^^ help: consider using: `x.exp2()`
-
-error: exponent for bases 2 and e can be computed more accurately
-  --> $DIR/floating_point_arithmetic.rs:58:13
-   |
-LL |     let _ = std::f64::consts::E.powf(x);
-   |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `x.exp()`
-
-error: square-root of a number can be computed more efficiently and accurately
-  --> $DIR/floating_point_arithmetic.rs:59:13
-   |
-LL |     let _ = x.powf(1.0 / 2.0);
-   |             ^^^^^^^^^^^^^^^^^ help: consider using: `x.sqrt()`
-
-error: cube-root of a number can be computed more accurately
-  --> $DIR/floating_point_arithmetic.rs:60:13
-   |
-LL |     let _ = x.powf(1.0 / 3.0);
-   |             ^^^^^^^^^^^^^^^^^ help: consider using: `x.cbrt()`
-
-error: exponentiation with integer powers can be computed more efficiently
-  --> $DIR/floating_point_arithmetic.rs:61:13
-   |
-LL |     let _ = x.powf(2.0);
-   |             ^^^^^^^^^^^ help: consider using: `x.powi(2)`
-
-error: exponentiation with integer powers can be computed more efficiently
-  --> $DIR/floating_point_arithmetic.rs:62:13
-   |
-LL |     let _ = x.powf(-2.0);
-   |             ^^^^^^^^^^^^ help: consider using: `x.powi(-2)`
-
-error: (e.pow(x) - 1) can be computed more accurately
-  --> $DIR/floating_point_arithmetic.rs:71:13
-   |
-LL |     let _ = x.exp() - 1.0;
-   |             ^^^^^^^^^^^^^ help: consider using: `x.exp_m1()`
-
-error: (e.pow(x) - 1) can be computed more accurately
-  --> $DIR/floating_point_arithmetic.rs:72:13
-   |
-LL |     let _ = x.exp() - 1.0 + 2.0;
-   |             ^^^^^^^^^^^^^ help: consider using: `x.exp_m1()`
-
-error: (e.pow(x) - 1) can be computed more accurately
-  --> $DIR/floating_point_arithmetic.rs:78:13
-   |
-LL |     let _ = x.exp() - 1.0;
-   |             ^^^^^^^^^^^^^ help: consider using: `x.exp_m1()`
-
-error: (e.pow(x) - 1) can be computed more accurately
-  --> $DIR/floating_point_arithmetic.rs:79:13
-   |
-LL |     let _ = x.exp() - 1.0 + 2.0;
-   |             ^^^^^^^^^^^^^ help: consider using: `x.exp_m1()`
-
-error: x.log(b) / y.log(b) can be reduced to x.log(y)
-  --> $DIR/floating_point_arithmetic.rs:90:13
-   |
-LL |     let _ = x.log2() / y.log2();
-   |             ^^^^^^^^^^^^^^^^^^^ help: consider using: `x.log(y)`
-
-error: x.log(b) / y.log(b) can be reduced to x.log(y)
-  --> $DIR/floating_point_arithmetic.rs:91:13
-   |
-LL |     let _ = x.log10() / y.log10();
-   |             ^^^^^^^^^^^^^^^^^^^^^ help: consider using: `x.log(y)`
-
-error: x.log(b) / y.log(b) can be reduced to x.log(y)
-  --> $DIR/floating_point_arithmetic.rs:92:13
-   |
-LL |     let _ = x.ln() / y.ln();
-   |             ^^^^^^^^^^^^^^^ help: consider using: `x.log(y)`
-
-error: x.log(b) / y.log(b) can be reduced to x.log(y)
-  --> $DIR/floating_point_arithmetic.rs:93:13
-   |
-LL |     let _ = x.log(4.0) / y.log(4.0);
-   |             ^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `x.log(y)`
-
-error: x.log(b) / y.log(b) can be reduced to x.log(y)
-  --> $DIR/floating_point_arithmetic.rs:94:13
-   |
-LL |     let _ = x.log(b) / y.log(b);
-   |             ^^^^^^^^^^^^^^^^^^^ help: consider using: `x.log(y)`
-
-error: x.log(b) / y.log(b) can be reduced to x.log(y)
-  --> $DIR/floating_point_arithmetic.rs:96:13
-   |
-LL |     let _ = x.log(b) / 2f32.log(b);
-   |             ^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `x.log2()`
-
-error: x.log(b) / y.log(b) can be reduced to x.log(y)
-  --> $DIR/floating_point_arithmetic.rs:102:13
-   |
-LL |     let _ = x.log2() / y.log2();
-   |             ^^^^^^^^^^^^^^^^^^^ help: consider using: `x.log(y)`
-
-error: x.log(b) / y.log(b) can be reduced to x.log(y)
-  --> $DIR/floating_point_arithmetic.rs:103:13
-   |
-LL |     let _ = x.log10() / y.log10();
-   |             ^^^^^^^^^^^^^^^^^^^^^ help: consider using: `x.log(y)`
-
-error: x.log(b) / y.log(b) can be reduced to x.log(y)
-  --> $DIR/floating_point_arithmetic.rs:104:13
-   |
-LL |     let _ = x.ln() / y.ln();
-   |             ^^^^^^^^^^^^^^^ help: consider using: `x.log(y)`
-
-error: x.log(b) / y.log(b) can be reduced to x.log(y)
-  --> $DIR/floating_point_arithmetic.rs:105:13
-   |
-LL |     let _ = x.log(4.0) / y.log(4.0);
-   |             ^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `x.log(y)`
-
-error: x.log(b) / y.log(b) can be reduced to x.log(y)
-  --> $DIR/floating_point_arithmetic.rs:106:13
-   |
-LL |     let _ = x.log(b) / y.log(b);
-   |             ^^^^^^^^^^^^^^^^^^^ help: consider using: `x.log(y)`
-
-error: x.log(b) / y.log(b) can be reduced to x.log(y)
-  --> $DIR/floating_point_arithmetic.rs:108:13
-   |
-LL |     let _ = x.log(b) / 2f64.log(b);
-   |             ^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `x.log2()`
-
-error: aborting due to 44 previous errors
-
diff --git a/tests/ui/floating_point_exp.rs b/tests/ui/floating_point_exp.rs
new file mode 100644 (file)
index 0000000..303c612
--- /dev/null
@@ -0,0 +1,17 @@
+#![warn(clippy::floating_point_improvements)]
+
+fn main() {
+    let x = 2f32;
+    let _ = x.exp() - 1.0;
+    let _ = x.exp() - 1.0 + 2.0;
+    // Cases where the lint shouldn't be applied
+    let _ = x.exp() - 2.0;
+    let _ = x.exp() - 1.0 * 2.0;
+
+    let x = 2f64;
+    let _ = x.exp() - 1.0;
+    let _ = x.exp() - 1.0 + 2.0;
+    // Cases where the lint shouldn't be applied
+    let _ = x.exp() - 2.0;
+    let _ = x.exp() - 1.0 * 2.0;
+}
diff --git a/tests/ui/floating_point_exp.stderr b/tests/ui/floating_point_exp.stderr
new file mode 100644 (file)
index 0000000..7832189
--- /dev/null
@@ -0,0 +1,28 @@
+error: (e.pow(x) - 1) can be computed more accurately
+  --> $DIR/floating_point_exp.rs:5:13
+   |
+LL |     let _ = x.exp() - 1.0;
+   |             ^^^^^^^^^^^^^ help: consider using: `x.exp_m1()`
+   |
+   = note: `-D clippy::floating-point-improvements` implied by `-D warnings`
+
+error: (e.pow(x) - 1) can be computed more accurately
+  --> $DIR/floating_point_exp.rs:6:13
+   |
+LL |     let _ = x.exp() - 1.0 + 2.0;
+   |             ^^^^^^^^^^^^^ help: consider using: `x.exp_m1()`
+
+error: (e.pow(x) - 1) can be computed more accurately
+  --> $DIR/floating_point_exp.rs:12:13
+   |
+LL |     let _ = x.exp() - 1.0;
+   |             ^^^^^^^^^^^^^ help: consider using: `x.exp_m1()`
+
+error: (e.pow(x) - 1) can be computed more accurately
+  --> $DIR/floating_point_exp.rs:13:13
+   |
+LL |     let _ = x.exp() - 1.0 + 2.0;
+   |             ^^^^^^^^^^^^^ help: consider using: `x.exp_m1()`
+
+error: aborting due to 4 previous errors
+
diff --git a/tests/ui/floating_point_log.rs b/tests/ui/floating_point_log.rs
new file mode 100644 (file)
index 0000000..4c01d5e
--- /dev/null
@@ -0,0 +1,69 @@
+#![allow(dead_code)]
+#![warn(clippy::floating_point_improvements)]
+
+const TWO: f32 = 2.0;
+const E: f32 = std::f32::consts::E;
+
+fn check_log_base() {
+    let x = 1f32;
+    let _ = x.log(2f32);
+    let _ = x.log(10f32);
+    let _ = x.log(std::f32::consts::E);
+    let _ = x.log(TWO);
+    let _ = x.log(E);
+
+    let x = 1f64;
+    let _ = x.log(2f64);
+    let _ = x.log(10f64);
+    let _ = x.log(std::f64::consts::E);
+}
+
+fn check_ln1p() {
+    let x = 1f32;
+    let _ = (1.0 + x).ln();
+    let _ = (1.0 + x * 2.0).ln();
+    let _ = (1.0 + x.powi(2)).ln();
+    let _ = (1.0 + x.powi(2) * 2.0).ln();
+    let _ = (1.0 + (std::f32::consts::E - 1.0)).ln();
+    // Cases where the lint shouldn't be applied
+    let _ = (x + 1.0).ln();
+    let _ = (1.0 + x + 2.0).ln();
+    let _ = (1.0 + x - 2.0).ln();
+
+    let x = 1f64;
+    let _ = (1.0 + x).ln();
+    let _ = (1.0 + x * 2.0).ln();
+    let _ = (1.0 + x.powi(2)).ln();
+    // Cases where the lint shouldn't be applied
+    let _ = (x + 1.0).ln();
+    let _ = (1.0 + x + 2.0).ln();
+    let _ = (1.0 + x - 2.0).ln();
+}
+
+fn check_log_division() {
+    let x = 3f32;
+    let y = 2f32;
+    let b = 4f32;
+
+    let _ = x.log2() / y.log2();
+    let _ = x.log10() / y.log10();
+    let _ = x.ln() / y.ln();
+    let _ = x.log(4.0) / y.log(4.0);
+    let _ = x.log(b) / y.log(b);
+    let _ = x.log(b) / y.log(x);
+    let _ = x.log(b) / 2f32.log(b);
+
+    let x = 3f64;
+    let y = 2f64;
+    let b = 4f64;
+
+    let _ = x.log2() / y.log2();
+    let _ = x.log10() / y.log10();
+    let _ = x.ln() / y.ln();
+    let _ = x.log(4.0) / y.log(4.0);
+    let _ = x.log(b) / y.log(b);
+    let _ = x.log(b) / y.log(x);
+    let _ = x.log(b) / 2f64.log(b);
+}
+
+fn main() {}
diff --git a/tests/ui/floating_point_log.stderr b/tests/ui/floating_point_log.stderr
new file mode 100644 (file)
index 0000000..0a36f8f
--- /dev/null
@@ -0,0 +1,172 @@
+error: logarithm for bases 2, 10 and e can be computed more accurately
+  --> $DIR/floating_point_log.rs:9:13
+   |
+LL |     let _ = x.log(2f32);
+   |             ^^^^^^^^^^^ help: consider using: `x.log2()`
+   |
+   = note: `-D clippy::floating-point-improvements` implied by `-D warnings`
+
+error: logarithm for bases 2, 10 and e can be computed more accurately
+  --> $DIR/floating_point_log.rs:10:13
+   |
+LL |     let _ = x.log(10f32);
+   |             ^^^^^^^^^^^^ help: consider using: `x.log10()`
+
+error: logarithm for bases 2, 10 and e can be computed more accurately
+  --> $DIR/floating_point_log.rs:11:13
+   |
+LL |     let _ = x.log(std::f32::consts::E);
+   |             ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `x.ln()`
+
+error: logarithm for bases 2, 10 and e can be computed more accurately
+  --> $DIR/floating_point_log.rs:12:13
+   |
+LL |     let _ = x.log(TWO);
+   |             ^^^^^^^^^^ help: consider using: `x.log2()`
+
+error: logarithm for bases 2, 10 and e can be computed more accurately
+  --> $DIR/floating_point_log.rs:13:13
+   |
+LL |     let _ = x.log(E);
+   |             ^^^^^^^^ help: consider using: `x.ln()`
+
+error: logarithm for bases 2, 10 and e can be computed more accurately
+  --> $DIR/floating_point_log.rs:16:13
+   |
+LL |     let _ = x.log(2f64);
+   |             ^^^^^^^^^^^ help: consider using: `x.log2()`
+
+error: logarithm for bases 2, 10 and e can be computed more accurately
+  --> $DIR/floating_point_log.rs:17:13
+   |
+LL |     let _ = x.log(10f64);
+   |             ^^^^^^^^^^^^ help: consider using: `x.log10()`
+
+error: logarithm for bases 2, 10 and e can be computed more accurately
+  --> $DIR/floating_point_log.rs:18:13
+   |
+LL |     let _ = x.log(std::f64::consts::E);
+   |             ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `x.ln()`
+
+error: ln(1 + x) can be computed more accurately
+  --> $DIR/floating_point_log.rs:23:13
+   |
+LL |     let _ = (1.0 + x).ln();
+   |             ^^^^^^^^^^^^^^ help: consider using: `x.ln_1p()`
+
+error: ln(1 + x) can be computed more accurately
+  --> $DIR/floating_point_log.rs:24:13
+   |
+LL |     let _ = (1.0 + x * 2.0).ln();
+   |             ^^^^^^^^^^^^^^^^^^^^ help: consider using: `(x * 2.0).ln_1p()`
+
+error: ln(1 + x) can be computed more accurately
+  --> $DIR/floating_point_log.rs:25:13
+   |
+LL |     let _ = (1.0 + x.powi(2)).ln();
+   |             ^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `x.powi(2).ln_1p()`
+
+error: ln(1 + x) can be computed more accurately
+  --> $DIR/floating_point_log.rs:26:13
+   |
+LL |     let _ = (1.0 + x.powi(2) * 2.0).ln();
+   |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `(x.powi(2) * 2.0).ln_1p()`
+
+error: ln(1 + x) can be computed more accurately
+  --> $DIR/floating_point_log.rs:27:13
+   |
+LL |     let _ = (1.0 + (std::f32::consts::E - 1.0)).ln();
+   |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `((std::f32::consts::E - 1.0)).ln_1p()`
+
+error: ln(1 + x) can be computed more accurately
+  --> $DIR/floating_point_log.rs:34:13
+   |
+LL |     let _ = (1.0 + x).ln();
+   |             ^^^^^^^^^^^^^^ help: consider using: `x.ln_1p()`
+
+error: ln(1 + x) can be computed more accurately
+  --> $DIR/floating_point_log.rs:35:13
+   |
+LL |     let _ = (1.0 + x * 2.0).ln();
+   |             ^^^^^^^^^^^^^^^^^^^^ help: consider using: `(x * 2.0).ln_1p()`
+
+error: ln(1 + x) can be computed more accurately
+  --> $DIR/floating_point_log.rs:36:13
+   |
+LL |     let _ = (1.0 + x.powi(2)).ln();
+   |             ^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `x.powi(2).ln_1p()`
+
+error: x.log(b) / y.log(b) can be reduced to x.log(y)
+  --> $DIR/floating_point_log.rs:48:13
+   |
+LL |     let _ = x.log2() / y.log2();
+   |             ^^^^^^^^^^^^^^^^^^^ help: consider using: `x.log(y)`
+
+error: x.log(b) / y.log(b) can be reduced to x.log(y)
+  --> $DIR/floating_point_log.rs:49:13
+   |
+LL |     let _ = x.log10() / y.log10();
+   |             ^^^^^^^^^^^^^^^^^^^^^ help: consider using: `x.log(y)`
+
+error: x.log(b) / y.log(b) can be reduced to x.log(y)
+  --> $DIR/floating_point_log.rs:50:13
+   |
+LL |     let _ = x.ln() / y.ln();
+   |             ^^^^^^^^^^^^^^^ help: consider using: `x.log(y)`
+
+error: x.log(b) / y.log(b) can be reduced to x.log(y)
+  --> $DIR/floating_point_log.rs:51:13
+   |
+LL |     let _ = x.log(4.0) / y.log(4.0);
+   |             ^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `x.log(y)`
+
+error: x.log(b) / y.log(b) can be reduced to x.log(y)
+  --> $DIR/floating_point_log.rs:52:13
+   |
+LL |     let _ = x.log(b) / y.log(b);
+   |             ^^^^^^^^^^^^^^^^^^^ help: consider using: `x.log(y)`
+
+error: x.log(b) / y.log(b) can be reduced to x.log(y)
+  --> $DIR/floating_point_log.rs:54:13
+   |
+LL |     let _ = x.log(b) / 2f32.log(b);
+   |             ^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `x.log2()`
+
+error: x.log(b) / y.log(b) can be reduced to x.log(y)
+  --> $DIR/floating_point_log.rs:60:13
+   |
+LL |     let _ = x.log2() / y.log2();
+   |             ^^^^^^^^^^^^^^^^^^^ help: consider using: `x.log(y)`
+
+error: x.log(b) / y.log(b) can be reduced to x.log(y)
+  --> $DIR/floating_point_log.rs:61:13
+   |
+LL |     let _ = x.log10() / y.log10();
+   |             ^^^^^^^^^^^^^^^^^^^^^ help: consider using: `x.log(y)`
+
+error: x.log(b) / y.log(b) can be reduced to x.log(y)
+  --> $DIR/floating_point_log.rs:62:13
+   |
+LL |     let _ = x.ln() / y.ln();
+   |             ^^^^^^^^^^^^^^^ help: consider using: `x.log(y)`
+
+error: x.log(b) / y.log(b) can be reduced to x.log(y)
+  --> $DIR/floating_point_log.rs:63:13
+   |
+LL |     let _ = x.log(4.0) / y.log(4.0);
+   |             ^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `x.log(y)`
+
+error: x.log(b) / y.log(b) can be reduced to x.log(y)
+  --> $DIR/floating_point_log.rs:64:13
+   |
+LL |     let _ = x.log(b) / y.log(b);
+   |             ^^^^^^^^^^^^^^^^^^^ help: consider using: `x.log(y)`
+
+error: x.log(b) / y.log(b) can be reduced to x.log(y)
+  --> $DIR/floating_point_log.rs:66:13
+   |
+LL |     let _ = x.log(b) / 2f64.log(b);
+   |             ^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `x.log2()`
+
+error: aborting due to 28 previous errors
+
diff --git a/tests/ui/floating_point_powf.rs b/tests/ui/floating_point_powf.rs
new file mode 100644 (file)
index 0000000..14f1f53
--- /dev/null
@@ -0,0 +1,27 @@
+#![warn(clippy::floating_point_improvements)]
+
+fn main() {
+    let x = 3f32;
+    let _ = 2f32.powf(x);
+    let _ = std::f32::consts::E.powf(x);
+    let _ = x.powf(1.0 / 2.0);
+    let _ = x.powf(1.0 / 3.0);
+    let _ = x.powf(2.0);
+    let _ = x.powf(-2.0);
+    let _ = x.powf(2.1);
+    let _ = x.powf(-2.1);
+    let _ = x.powf(16_777_217.0);
+    let _ = x.powf(-16_777_217.0);
+
+    let x = 3f64;
+    let _ = 2f64.powf(x);
+    let _ = std::f64::consts::E.powf(x);
+    let _ = x.powf(1.0 / 2.0);
+    let _ = x.powf(1.0 / 3.0);
+    let _ = x.powf(2.0);
+    let _ = x.powf(-2.0);
+    let _ = x.powf(2.1);
+    let _ = x.powf(-2.1);
+    let _ = x.powf(9_007_199_254_740_993.0);
+    let _ = x.powf(-9_007_199_254_740_993.0);
+}
diff --git a/tests/ui/floating_point_powf.stderr b/tests/ui/floating_point_powf.stderr
new file mode 100644 (file)
index 0000000..2be54af
--- /dev/null
@@ -0,0 +1,76 @@
+error: exponent for bases 2 and e can be computed more accurately
+  --> $DIR/floating_point_powf.rs:5:13
+   |
+LL |     let _ = 2f32.powf(x);
+   |             ^^^^^^^^^^^^ help: consider using: `x.exp2()`
+   |
+   = note: `-D clippy::floating-point-improvements` implied by `-D warnings`
+
+error: exponent for bases 2 and e can be computed more accurately
+  --> $DIR/floating_point_powf.rs:6:13
+   |
+LL |     let _ = std::f32::consts::E.powf(x);
+   |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `x.exp()`
+
+error: square-root of a number can be computed more efficiently and accurately
+  --> $DIR/floating_point_powf.rs:7:13
+   |
+LL |     let _ = x.powf(1.0 / 2.0);
+   |             ^^^^^^^^^^^^^^^^^ help: consider using: `x.sqrt()`
+
+error: cube-root of a number can be computed more accurately
+  --> $DIR/floating_point_powf.rs:8:13
+   |
+LL |     let _ = x.powf(1.0 / 3.0);
+   |             ^^^^^^^^^^^^^^^^^ help: consider using: `x.cbrt()`
+
+error: exponentiation with integer powers can be computed more efficiently
+  --> $DIR/floating_point_powf.rs:9:13
+   |
+LL |     let _ = x.powf(2.0);
+   |             ^^^^^^^^^^^ help: consider using: `x.powi(2)`
+
+error: exponentiation with integer powers can be computed more efficiently
+  --> $DIR/floating_point_powf.rs:10:13
+   |
+LL |     let _ = x.powf(-2.0);
+   |             ^^^^^^^^^^^^ help: consider using: `x.powi(-2)`
+
+error: exponent for bases 2 and e can be computed more accurately
+  --> $DIR/floating_point_powf.rs:17:13
+   |
+LL |     let _ = 2f64.powf(x);
+   |             ^^^^^^^^^^^^ help: consider using: `x.exp2()`
+
+error: exponent for bases 2 and e can be computed more accurately
+  --> $DIR/floating_point_powf.rs:18:13
+   |
+LL |     let _ = std::f64::consts::E.powf(x);
+   |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `x.exp()`
+
+error: square-root of a number can be computed more efficiently and accurately
+  --> $DIR/floating_point_powf.rs:19:13
+   |
+LL |     let _ = x.powf(1.0 / 2.0);
+   |             ^^^^^^^^^^^^^^^^^ help: consider using: `x.sqrt()`
+
+error: cube-root of a number can be computed more accurately
+  --> $DIR/floating_point_powf.rs:20:13
+   |
+LL |     let _ = x.powf(1.0 / 3.0);
+   |             ^^^^^^^^^^^^^^^^^ help: consider using: `x.cbrt()`
+
+error: exponentiation with integer powers can be computed more efficiently
+  --> $DIR/floating_point_powf.rs:21:13
+   |
+LL |     let _ = x.powf(2.0);
+   |             ^^^^^^^^^^^ help: consider using: `x.powi(2)`
+
+error: exponentiation with integer powers can be computed more efficiently
+  --> $DIR/floating_point_powf.rs:22:13
+   |
+LL |     let _ = x.powf(-2.0);
+   |             ^^^^^^^^^^^^ help: consider using: `x.powi(-2)`
+
+error: aborting due to 12 previous errors
+