diff options
| author | Oliver Schneider <git-spam-no-reply9815368754983@oli-obk.de> | 2018-04-24 14:42:30 +0200 |
|---|---|---|
| committer | Oliver Schneider <git-no-reply-9879165716479413131@oli-obk.de> | 2018-04-30 18:18:32 +0200 |
| commit | 7d982fdcf439799efbcc9f0cfcda99fa87b07460 (patch) | |
| tree | 76f20bd4c608cf62102aab106122713678635f8e /src/librustc_const_math/float.rs | |
| parent | 7def638e42b70ee204cc84458b3d3775bbeba055 (diff) | |
Implement `PartialCmp` for `ConstFloat`
Diffstat (limited to 'src/librustc_const_math/float.rs')
| -rw-r--r-- | src/librustc_const_math/float.rs | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/src/librustc_const_math/float.rs b/src/librustc_const_math/float.rs index 9d820ea8cbe..61e9b34f06a 100644 --- a/src/librustc_const_math/float.rs +++ b/src/librustc_const_math/float.rs @@ -31,6 +31,12 @@ pub struct ConstFloat { pub bits: u128, } +impl PartialOrd<ConstFloat> for ConstFloat { + fn partial_cmp(&self, other: &Self) -> Option<Ordering> { + self.try_cmp(*other) + } +} + impl ConstFloat { /// Description of the type, not the value pub fn description(&self) -> &'static str { @@ -38,22 +44,22 @@ impl ConstFloat { } /// Compares the values if they are of the same type - pub fn try_cmp(self, rhs: Self) -> Result<Ordering, ConstMathErr> { + fn try_cmp(self, rhs: Self) -> Option<Ordering> { match (self.ty, rhs.ty) { (ast::FloatTy::F64, ast::FloatTy::F64) => { let a = Double::from_bits(self.bits); let b = Double::from_bits(rhs.bits); // This is pretty bad but it is the existing behavior. - Ok(a.partial_cmp(&b).unwrap_or(Ordering::Greater)) + Some(a.partial_cmp(&b).unwrap_or(Ordering::Greater)) } (ast::FloatTy::F32, ast::FloatTy::F32) => { let a = Single::from_bits(self.bits); let b = Single::from_bits(rhs.bits); - Ok(a.partial_cmp(&b).unwrap_or(Ordering::Greater)) + Some(a.partial_cmp(&b).unwrap_or(Ordering::Greater)) } - _ => Err(CmpBetweenUnequalTypes), + _ => None, } } |
