]> git.lizzy.rs Git - rust.git/commitdiff
Change floating point constant to mem::transmute u64 comparison
authorTaylor Cramer <cramertaylorj@gmail.com>
Wed, 13 Jul 2016 07:59:35 +0000 (00:59 -0700)
committerTaylor Cramer <cramertaylorj@gmail.com>
Wed, 13 Jul 2016 07:59:35 +0000 (00:59 -0700)
clippy_lints/src/consts.rs

index d4ee76590561666cb73fd873248d1bce0c46c5e7..9ed37e70a01de76e76535f71166cb6aefbb96f4f 100644 (file)
@@ -92,8 +92,10 @@ fn eq(&self, other: &Constant) -> bool {
                 // we want `Fw32 == FwAny` and `FwAny == Fw64`, by transitivity we must have
                 // `Fw32 == Fw64` so don’t compare them
                 match (ls.parse::<f64>(), rs.parse::<f64>()) {
-                    (Ok(l), Ok(r)) => l.eq(&r) &&
-                        (l.is_sign_positive() == r.is_sign_positive()), // needed for 0.0 != -0.0
+                    // mem::transmute is required to catch non-matching 0.0, -0.0, and NaNs
+                    (Ok(l), Ok(r)) => unsafe {
+                        mem::transmute::<f64, u64>(l) == mem::transmute::<f64, u64>(r)
+                    },
                     _ => false,
                 }
             }