Added sign check on Constant f64 PartialEq implementation

This commit is contained in:
Taylor Cramer 2016-07-13 00:43:33 -07:00
parent f1a0ddf31b
commit 8907cbc0b8
2 changed files with 27 additions and 1 deletions

View file

@ -92,7 +92,8 @@ impl PartialEq for Constant {
// we want `Fw32 == FwAny` and `FwAny == Fw64`, by transitivity we must have
// `Fw32 == Fw64` so dont compare them
match (ls.parse::<f64>(), rs.parse::<f64>()) {
(Ok(l), Ok(r)) => l.eq(&r),
(Ok(l), Ok(r)) => l.eq(&r) &&
(l.is_sign_positive() == r.is_sign_positive()), // needed for 0.0 != -0.0
_ => false,
}
}

View file

@ -229,6 +229,31 @@ fn if_same_then_else() -> Result<&'static str, ()> {
_ => 0,
};
let _ = if true {
//~^NOTE same as this
0.0
} else { //~ERROR this `if` has identical blocks
0.0
};
let _ = if true {
//~^NOTE same as this
-0.0
} else { //~ERROR this `if` has identical blocks
-0.0
};
let _ = if true {
0.0
} else {
-0.0
};
let _ = match Some(()) {
Some(()) => 0.0,
None => -0.0
};
match (Some(42), Some("")) {
(Some(a), None) => bar(a),
(None, Some(a)) => bar(a), // bindings have different types