From 793d231025b75a497425a600a4ab40b9cbf55221 Mon Sep 17 00:00:00 2001 From: Chris Dyer Date: Thu, 3 Mar 2011 16:02:45 -0500 Subject: nasty overflow related bug when comparing prob_t's, which coerced them through double, causing sometimes bad results when weights were high --- utils/logval.h | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) (limited to 'utils') diff --git a/utils/logval.h b/utils/logval.h index da0aa2b0..6fdc2c42 100644 --- a/utils/logval.h +++ b/utils/logval.h @@ -200,6 +200,16 @@ LogVal pow(const LogVal& b, const T& e) { return b.pow(e); } +template +bool operator==(const LogVal& lhs, const LogVal& rhs) { + return (lhs.v_ == rhs.v_) && (lhs.s_ == rhs.s_); +} + +template +bool operator!=(const LogVal& lhs, const LogVal& rhs) { + return !(lhs == rhs); +} + template bool operator<(const LogVal& lhs, const LogVal& rhs) { if (lhs.s_ == rhs.s_) { @@ -209,35 +219,22 @@ bool operator<(const LogVal& lhs, const LogVal& rhs) { } } -#if 0 template bool operator<=(const LogVal& lhs, const LogVal& rhs) { - return (lhs.v_ <= rhs.v_); + return (lhs < rhs) || (lhs == rhs); } template bool operator>(const LogVal& lhs, const LogVal& rhs) { - return (lhs.v_ > rhs.v_); + return !(lhs <= rhs); } template bool operator>=(const LogVal& lhs, const LogVal& rhs) { - return (lhs.v_ >= rhs.v_); + return !(lhs < rhs); } -#endif - template std::size_t hash_value(const LogVal& x) { return x.hash_impl(); } -template -bool operator==(const LogVal& lhs, const LogVal& rhs) { - return (lhs.v_ == rhs.v_) && (lhs.s_ == rhs.s_); -} - -template -bool operator!=(const LogVal& lhs, const LogVal& rhs) { - return !(lhs == rhs); -} - #endif -- cgit v1.2.3