2022-10-06 07:44:38 +00:00
|
|
|
#![allow(dead_code, clippy::double_parens, clippy::unnecessary_cast)]
|
2020-02-24 05:06:55 +00:00
|
|
|
#![warn(clippy::suboptimal_flops, clippy::imprecise_flops)]
|
2019-12-14 17:28:11 +00:00
|
|
|
|
2024-06-18 17:34:49 +00:00
|
|
|
// FIXME(f16_f128): add tests for these types once math functions are available
|
|
|
|
|
2019-12-14 17:28:11 +00:00
|
|
|
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);
|
2022-08-31 13:24:45 +00:00
|
|
|
let _ = (x as f32).log(2f32);
|
2019-12-14 17:28:11 +00:00
|
|
|
|
|
|
|
let x = 1f64;
|
|
|
|
let _ = x.log(2f64);
|
|
|
|
let _ = x.log(10f64);
|
|
|
|
let _ = x.log(std::f64::consts::E);
|
|
|
|
}
|
|
|
|
|
|
|
|
fn check_ln1p() {
|
|
|
|
let x = 1f32;
|
2020-01-04 06:19:13 +00:00
|
|
|
let _ = (1f32 + 2.).ln();
|
|
|
|
let _ = (1f32 + 2.0).ln();
|
2019-12-14 17:28:11 +00:00
|
|
|
let _ = (1.0 + x).ln();
|
2020-02-23 08:04:11 +00:00
|
|
|
let _ = (1.0 + x / 2.0).ln();
|
2020-07-14 12:59:59 +00:00
|
|
|
let _ = (1.0 + x.powi(3)).ln();
|
|
|
|
let _ = (1.0 + x.powi(3) / 2.0).ln();
|
2019-12-14 17:28:11 +00:00
|
|
|
let _ = (1.0 + (std::f32::consts::E - 1.0)).ln();
|
|
|
|
let _ = (x + 1.0).ln();
|
2020-07-14 12:59:59 +00:00
|
|
|
let _ = (x.powi(3) + 1.0).ln();
|
2019-12-21 04:07:03 +00:00
|
|
|
let _ = (x + 2.0 + 1.0).ln();
|
2020-02-23 08:04:11 +00:00
|
|
|
let _ = (x / 2.0 + 1.0).ln();
|
2019-12-21 04:07:03 +00:00
|
|
|
// Cases where the lint shouldn't be applied
|
2019-12-14 17:28:11 +00:00
|
|
|
let _ = (1.0 + x + 2.0).ln();
|
2019-12-21 04:07:03 +00:00
|
|
|
let _ = (x + 1.0 + 2.0).ln();
|
2020-02-23 08:04:11 +00:00
|
|
|
let _ = (x + 1.0 / 2.0).ln();
|
2019-12-14 17:28:11 +00:00
|
|
|
let _ = (1.0 + x - 2.0).ln();
|
|
|
|
|
|
|
|
let x = 1f64;
|
2020-01-04 06:19:13 +00:00
|
|
|
let _ = (1f64 + 2.).ln();
|
|
|
|
let _ = (1f64 + 2.0).ln();
|
2019-12-14 17:28:11 +00:00
|
|
|
let _ = (1.0 + x).ln();
|
2020-02-23 08:04:11 +00:00
|
|
|
let _ = (1.0 + x / 2.0).ln();
|
2020-07-14 12:59:59 +00:00
|
|
|
let _ = (1.0 + x.powi(3)).ln();
|
2019-12-14 17:28:11 +00:00
|
|
|
let _ = (x + 1.0).ln();
|
2020-07-14 12:59:59 +00:00
|
|
|
let _ = (x.powi(3) + 1.0).ln();
|
2019-12-21 04:07:03 +00:00
|
|
|
let _ = (x + 2.0 + 1.0).ln();
|
2020-02-23 08:04:11 +00:00
|
|
|
let _ = (x / 2.0 + 1.0).ln();
|
2019-12-21 04:07:03 +00:00
|
|
|
// Cases where the lint shouldn't be applied
|
2019-12-14 17:28:11 +00:00
|
|
|
let _ = (1.0 + x + 2.0).ln();
|
2019-12-21 04:07:03 +00:00
|
|
|
let _ = (x + 1.0 + 2.0).ln();
|
2020-02-23 08:04:11 +00:00
|
|
|
let _ = (x + 1.0 / 2.0).ln();
|
2019-12-14 17:28:11 +00:00
|
|
|
let _ = (1.0 + x - 2.0).ln();
|
|
|
|
}
|
|
|
|
|
2024-06-13 10:30:48 +00:00
|
|
|
fn issue12881() {
|
|
|
|
pub trait MyLog {
|
|
|
|
fn log(&self) -> Self;
|
|
|
|
}
|
|
|
|
|
|
|
|
impl MyLog for f32 {
|
|
|
|
fn log(&self) -> Self {
|
|
|
|
4.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
let x = 2.0;
|
|
|
|
x.log();
|
|
|
|
}
|
|
|
|
|
2019-12-14 17:28:11 +00:00
|
|
|
fn main() {}
|