1 // Copyright 2014-2018 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution.
4 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
5 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
6 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
7 // option. This file may not be copied, modified, or distributed
8 // except according to those terms.
10 #![warn(clippy::float_cmp)]
11 #![allow(unused, clippy::no_effect, clippy::unnecessary_operation, clippy::cast_lossless)]
15 const ZERO: f32 = 0.0;
16 const ONE: f32 = ZERO + 1.0;
18 fn twice<T>(x: T) -> T
20 T: Add<T, Output = T>,
26 fn eq_fl(x: f32, y: f32) -> bool {
31 } // no error, inside "eq" fn
34 fn fl_eq(x: f32, y: f32) -> bool {
39 } // no error, inside "eq" fn
46 impl PartialEq for X {
47 fn eq(&self, o: &X) -> bool {
48 if self.val.is_nan() {
51 self.val == o.val // no error, inside "eq" fn
57 ZERO == 0f32; //no error, comparison with zero is ok
58 1.0f32 != ::std::f32::INFINITY; // also comparison with infinity
59 1.0f32 != ::std::f32::NEG_INFINITY; // and negative infinity
60 ZERO == 0.0; //no error, comparison with zero is ok
61 ZERO + ZERO != 1.0; //no error, comparison with zero is ok
65 ONE + ONE == ZERO + ONE + ONE;
67 ONE != 0.0; // no error, comparison with zero is ok
70 ONE as f64 != 0.0; // no error, comparison with zero is ok
75 x != 0f64; // no error, comparison with zero is ok
77 twice(x) != twice(ONE as f64);
79 x < 0.0; // no errors, lower or greater comparisons need no fuzzyness
84 let xs: [f32; 1] = [0.0];
85 let a: *const f32 = xs.as_ptr();
86 let b: *const f32 = xs.as_ptr();
88 assert_eq!(a, b); // no errors