Check for comparison of -0.0 and 0.0 in PartialOrd for Constant
This commit is contained in:
parent
0c21a6b0c4
commit
61d1a9b030
@ -162,7 +162,11 @@ fn partial_cmp(&self, other: &Constant) -> Option<Ordering> {
|
||||
(&Constant::Int(l), &Constant::Int(r)) => Some(l.cmp(&r)),
|
||||
(&Constant::Float(ref ls, _), &Constant::Float(ref rs, _)) => {
|
||||
match (ls.parse::<f64>(), rs.parse::<f64>()) {
|
||||
(Ok(ref l), Ok(ref r)) => l.partial_cmp(r),
|
||||
(Ok(ref l), Ok(ref r)) => match (l.partial_cmp(r), l.is_sign_positive() == r.is_sign_positive()) {
|
||||
// Check for comparison of -0.0 and 0.0
|
||||
(Some(Ordering::Equal), false) => None,
|
||||
(x, _) => x
|
||||
},
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
@ -82,6 +82,12 @@ fn test_ops() {
|
||||
let half_any = Constant::Float("0.5".into(), FloatWidth::Any);
|
||||
let half32 = Constant::Float("0.5".into(), FloatWidth::F32);
|
||||
let half64 = Constant::Float("0.5".into(), FloatWidth::F64);
|
||||
let pos_zero = Constant::Float("0.0".into(), FloatWidth::F64);
|
||||
let neg_zero = Constant::Float("-0.0".into(), FloatWidth::F64);
|
||||
|
||||
assert_eq!(pos_zero, pos_zero);
|
||||
assert_eq!(neg_zero, neg_zero);
|
||||
assert_eq!(None, pos_zero.partial_cmp(&neg_zero));
|
||||
|
||||
assert_eq!(half_any, half32);
|
||||
assert_eq!(half_any, half64);
|
||||
|
Loading…
Reference in New Issue
Block a user