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 | 793d231025b75a497425a600a4ab40b9cbf55221 (patch) | |
tree | ea8e732a3c1d9f1137bc8b26d0c7f28d3944e212 /utils | |
parent | 4ffb06ee501d9806542c34a9aac8e6406416d35b (diff) |
nasty overflow related bug when comparing prob_t's, which coerced them through double, causing sometimes bad results when weights were high
Diffstat (limited to 'utils')
-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 |