diff --git a/fixed.cpp b/fixed.cpp index d4483666..e2dd788e 100644 --- a/fixed.cpp +++ b/fixed.cpp @@ -172,7 +172,38 @@ fixed::operator /(uint_t val) const } -//----------------------------------------------------------------------------- -template class util::fixed<16,16>; -template class util::fixed<32,32>; -template class util::fixed<26, 6>; +/////////////////////////////////////////////////////////////////////////////// +// logical operators + +#define LOGIC_OP(OP) \ +template \ +bool \ +util::operator OP (util::fixed a, \ + util::fixed b) \ +{ \ + return a.to_native () OP b.to_native (); \ +} + +LOGIC_OP(==) +LOGIC_OP(!=) +LOGIC_OP(<) +LOGIC_OP(<=) +LOGIC_OP(>) +LOGIC_OP(>=) + + +/////////////////////////////////////////////////////////////////////////////// +// Instantiations + +#define INSTANTIATE(I,E) \ +template class util::fixed<(I),(E)>; \ +template bool util::operator== (util::fixed<(I),(E)>, util::fixed<(I),(E)>); \ +template bool util::operator!= (util::fixed<(I),(E)>, util::fixed<(I),(E)>); \ +template bool util::operator< (util::fixed<(I),(E)>, util::fixed<(I),(E)>); \ +template bool util::operator<= (util::fixed<(I),(E)>, util::fixed<(I),(E)>); \ +template bool util::operator> (util::fixed<(I),(E)>, util::fixed<(I),(E)>); \ +template bool util::operator>= (util::fixed<(I),(E)>, util::fixed<(I),(E)>); + +INSTANTIATE(16,16) +INSTANTIATE(26, 6) +INSTANTIATE(32,32) diff --git a/fixed.hpp b/fixed.hpp index c2a4fdeb..a7e542f4 100644 --- a/fixed.hpp +++ b/fixed.hpp @@ -66,6 +66,15 @@ namespace util { private: uint_t m_value; }; + + + template bool operator== (util::fixed, util::fixed); + template bool operator!= (util::fixed, util::fixed); + + template bool operator< (util::fixed, util::fixed); + template bool operator<= (util::fixed, util::fixed); + template bool operator> (util::fixed, util::fixed); + template bool operator>= (util::fixed, util::fixed); } #endif // __UTIL_FIXED_HPP