diff options
author | Chris Dyer <cdyer@cs.cmu.edu> | 2011-03-03 16:02:45 -0500 |
---|---|---|
committer | Chris Dyer <cdyer@cs.cmu.edu> | 2011-03-03 16:02:45 -0500 |
commit | 9bef5114bb2fc923ad02b3245517c97289f40f83 (patch) | |
tree | 803184680f1feceb5a1766400f13d1821bb60d84 | |
parent | f190b1fecf1f2ba891419a7cf9e4f9fb3a4c5b02 (diff) |
nasty overflow related bug when comparing prob_t's, which coerced them through double, causing sometimes bad results when weights were high
-rw-r--r-- | utils/logval.h | 29 |
1 files changed, 13 insertions, 16 deletions
diff --git a/utils/logval.h b/utils/logval.h index da0aa2b0..6fdc2c42 100644 --- a/utils/logval.h +++ b/utils/logval.h @@ -201,6 +201,16 @@ LogVal<T> pow(const LogVal<T>& b, const T& e) { } template <class T> +bool operator==(const LogVal<T>& lhs, const LogVal<T>& rhs) { + return (lhs.v_ == rhs.v_) && (lhs.s_ == rhs.s_); +} + +template <class T> +bool operator!=(const LogVal<T>& lhs, const LogVal<T>& rhs) { + return !(lhs == rhs); +} + +template <class T> bool operator<(const LogVal<T>& lhs, const LogVal<T>& rhs) { if (lhs.s_ == rhs.s_) { return (lhs.v_ < rhs.v_); @@ -209,35 +219,22 @@ bool operator<(const LogVal<T>& lhs, const LogVal<T>& rhs) { } } -#if 0 template <class T> bool operator<=(const LogVal<T>& lhs, const LogVal<T>& rhs) { - return (lhs.v_ <= rhs.v_); + return (lhs < rhs) || (lhs == rhs); } template <class T> bool operator>(const LogVal<T>& lhs, const LogVal<T>& rhs) { - return (lhs.v_ > rhs.v_); + return !(lhs <= rhs); } template <class T> bool operator>=(const LogVal<T>& lhs, const LogVal<T>& rhs) { - return (lhs.v_ >= rhs.v_); + return !(lhs < rhs); } -#endif - template <class T> std::size_t hash_value(const LogVal<T>& x) { return x.hash_impl(); } -template <class T> -bool operator==(const LogVal<T>& lhs, const LogVal<T>& rhs) { - return (lhs.v_ == rhs.v_) && (lhs.s_ == rhs.s_); -} - -template <class T> -bool operator!=(const LogVal<T>& lhs, const LogVal<T>& rhs) { - return !(lhs == rhs); -} - #endif |