1 #![warn(clippy::float_cmp)]
6 clippy::unnecessary_operation,
8 clippy::many_single_char_names
13 const ZERO: f32 = 0.0;
14 const ONE: f32 = ZERO + 1.0;
16 fn twice<T>(x: T) -> T
18 T: Add<T, Output = T> + Copy,
23 fn eq_fl(x: f32, y: f32) -> bool {
28 } // no error, inside "eq" fn
31 fn fl_eq(x: f32, y: f32) -> bool {
36 } // no error, inside "eq" fn
43 impl PartialEq for X {
44 fn eq(&self, o: &X) -> bool {
45 if self.val.is_nan() {
48 self.val == o.val // no error, inside "eq" fn
54 ZERO == 0f32; //no error, comparison with zero is ok
55 1.0f32 != f32::INFINITY; // also comparison with infinity
56 1.0f32 != f32::NEG_INFINITY; // and negative infinity
57 ZERO == 0.0; //no error, comparison with zero is ok
58 ZERO + ZERO != 1.0; //no error, comparison with zero is ok
62 ONE + ONE == ZERO + ONE + ONE;
64 ONE != 0.0; // no error, comparison with zero is ok
67 ONE as f64 != 0.0; // no error, comparison with zero is ok
72 x != 0f64; // no error, comparison with zero is ok
74 twice(x) != twice(ONE as f64);
76 x < 0.0; // no errors, lower or greater comparisons need no fuzzyness
81 let xs: [f32; 1] = [0.0];
82 let a: *const f32 = xs.as_ptr();
83 let b: *const f32 = xs.as_ptr();
85 assert_eq!(a, b); // no errors
87 const ZERO_ARRAY: [f32; 2] = [0.0, 0.0];
88 const NON_ZERO_ARRAY: [f32; 2] = [0.0, 0.1];
93 ZERO_ARRAY[i] == NON_ZERO_ARRAY[j]; // ok, because lhs is zero regardless of i
94 NON_ZERO_ARRAY[i] == NON_ZERO_ARRAY[j];
96 let a1: [f32; 1] = [0.0];
97 let a2: [f32; 1] = [1.1];
102 // no errors - comparing signums is ok
104 1.23f32.signum() == x32.signum();
105 1.23f32.signum() == -(x32.signum());
106 1.23f32.signum() == 3.21f32.signum();
108 1.23f32.signum() != x32.signum();
109 1.23f32.signum() != -(x32.signum());
110 1.23f32.signum() != 3.21f32.signum();
113 1.23f64.signum() == x64.signum();
114 1.23f64.signum() == -(x64.signum());
115 1.23f64.signum() == 3.21f64.signum();
117 1.23f64.signum() != x64.signum();
118 1.23f64.signum() != -(x64.signum());
119 1.23f64.signum() != 3.21f64.signum();
121 // the comparison should also look through references