fixed: add ostream operators

This commit is contained in:
Danny Robson 2015-02-06 16:35:23 +11:00
parent e3cba6b473
commit f0021afc71
2 changed files with 15 additions and 0 deletions

View File

@ -191,12 +191,22 @@ LOGIC_OP(<=)
LOGIC_OP(>)
LOGIC_OP(>=)
///////////////////////////////////////////////////////////////////////////////
// iostream operators
template <unsigned I, unsigned E>
std::ostream&
util::operator<< (std::ostream &os, fixed<I,E> v)
{
return os << v.to_double ();
}
///////////////////////////////////////////////////////////////////////////////
// Instantiations
#define INSTANTIATE(I,E) \
template class util::fixed<(I),(E)>; \
template std::ostream& util::operator<< (std::ostream&, 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)>); \

View File

@ -23,6 +23,7 @@
#include "types/bits.hpp"
#include <cstdint>
#include <iostream>
namespace util {
template <unsigned I, unsigned E>
@ -75,6 +76,10 @@ namespace util {
template <unsigned I, unsigned E> bool operator<= (util::fixed<I,E>, util::fixed<I,E>);
template <unsigned I, unsigned E> bool operator> (util::fixed<I,E>, util::fixed<I,E>);
template <unsigned I, unsigned E> bool operator>= (util::fixed<I,E>, util::fixed<I,E>);
template <unsigned I, unsigned E>
std::ostream& operator<< (std::ostream&, fixed<I,E>);
}
#endif // __UTIL_FIXED_HPP