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 {
24 if x.is_nan() { y.is_nan() } else { x == y } // no error, inside "eq" fn
27 fn fl_eq(x: f32, y: f32) -> bool {
28 if x.is_nan() { y.is_nan() } else { x == y } // no error, inside "eq" fn
35 impl PartialEq for X {
36 fn eq(&self, o: &X) -> bool {
37 if self.val.is_nan() {
40 self.val == o.val // no error, inside "eq" fn
46 ZERO == 0f32; //no error, comparison with zero is ok
47 1.0f32 != f32::INFINITY; // also comparison with infinity
48 1.0f32 != f32::NEG_INFINITY; // and negative infinity
49 ZERO == 0.0; //no error, comparison with zero is ok
50 ZERO + ZERO != 1.0; //no error, comparison with zero is ok
54 ONE + ONE == ZERO + ONE + ONE;
56 ONE != 0.0; // no error, comparison with zero is ok
59 ONE as f64 != 0.0; // no error, comparison with zero is ok
64 x != 0f64; // no error, comparison with zero is ok
66 twice(x) != twice(ONE as f64);
68 x < 0.0; // no errors, lower or greater comparisons need no fuzzyness
73 let xs: [f32; 1] = [0.0];
74 let a: *const f32 = xs.as_ptr();
75 let b: *const f32 = xs.as_ptr();
77 assert_eq!(a, b); // no errors
79 const ZERO_ARRAY: [f32; 2] = [0.0, 0.0];
80 const NON_ZERO_ARRAY: [f32; 2] = [0.0, 0.1];
85 ZERO_ARRAY[i] == NON_ZERO_ARRAY[j]; // ok, because lhs is zero regardless of i
86 NON_ZERO_ARRAY[i] == NON_ZERO_ARRAY[j];
88 let a1: [f32; 1] = [0.0];
89 let a2: [f32; 1] = [1.1];
94 // no errors - comparing signums is ok
96 1.23f32.signum() == x32.signum();
97 1.23f32.signum() == -(x32.signum());
98 1.23f32.signum() == 3.21f32.signum();
100 1.23f32.signum() != x32.signum();
101 1.23f32.signum() != -(x32.signum());
102 1.23f32.signum() != 3.21f32.signum();
105 1.23f64.signum() == x64.signum();
106 1.23f64.signum() == -(x64.signum());
107 1.23f64.signum() == 3.21f64.signum();
109 1.23f64.signum() != x64.signum();
110 1.23f64.signum() != -(x64.signum());
111 1.23f64.signum() != 3.21f64.signum();
113 // the comparison should also look through references