1 #![warn(clippy::float_cmp)]
6 clippy::unnecessary_operation,
12 const ZERO: f32 = 0.0;
13 const ONE: f32 = ZERO + 1.0;
15 fn twice<T>(x: T) -> T
17 T: Add<T, Output = T> + Copy,
22 fn eq_fl(x: f32, y: f32) -> bool {
23 if x.is_nan() { y.is_nan() } else { x == y } // no error, inside "eq" fn
26 fn fl_eq(x: f32, y: f32) -> bool {
27 if x.is_nan() { y.is_nan() } else { x == y } // no error, inside "eq" fn
34 impl PartialEq for X {
35 fn eq(&self, o: &X) -> bool {
36 if self.val.is_nan() {
39 self.val == o.val // no error, inside "eq" fn
45 ZERO == 0f32; //no error, comparison with zero is ok
46 1.0f32 != f32::INFINITY; // also comparison with infinity
47 1.0f32 != f32::NEG_INFINITY; // and negative infinity
48 ZERO == 0.0; //no error, comparison with zero is ok
49 ZERO + ZERO != 1.0; //no error, comparison with zero is ok
53 ONE + ONE == ZERO + ONE + ONE;
55 ONE != 0.0; // no error, comparison with zero is ok
58 ONE as f64 != 0.0; // no error, comparison with zero is ok
63 x != 0f64; // no error, comparison with zero is ok
65 twice(x) != twice(ONE as f64);
67 x < 0.0; // no errors, lower or greater comparisons need no fuzzyness
72 let xs: [f32; 1] = [0.0];
73 let a: *const f32 = xs.as_ptr();
74 let b: *const f32 = xs.as_ptr();
76 assert_eq!(a, b); // no errors
78 const ZERO_ARRAY: [f32; 2] = [0.0, 0.0];
79 const NON_ZERO_ARRAY: [f32; 2] = [0.0, 0.1];
84 ZERO_ARRAY[i] == NON_ZERO_ARRAY[j]; // ok, because lhs is zero regardless of i
85 NON_ZERO_ARRAY[i] == NON_ZERO_ARRAY[j];
87 let a1: [f32; 1] = [0.0];
88 let a2: [f32; 1] = [1.1];
93 // no errors - comparing signums is ok
95 1.23f32.signum() == x32.signum();
96 1.23f32.signum() == -(x32.signum());
97 1.23f32.signum() == 3.21f32.signum();
99 1.23f32.signum() != x32.signum();
100 1.23f32.signum() != -(x32.signum());
101 1.23f32.signum() != 3.21f32.signum();
104 1.23f64.signum() == x64.signum();
105 1.23f64.signum() == -(x64.signum());
106 1.23f64.signum() == 3.21f64.signum();
108 1.23f64.signum() != x64.signum();
109 1.23f64.signum() != -(x64.signum());
110 1.23f64.signum() != 3.21f64.signum();
112 // the comparison should also look through references