wovo / hwlib

C++ OO micro-controller library for close-to-the-hardware programming
Boost Software License 1.0
57 stars 26 forks source link

Unable to print doubles #15

Closed MarcDirven closed 3 years ago

MarcDirven commented 6 years ago

When trying to cout doubles, the following message appears:

wovo commented 3 years ago

Correct, printing doubles is not implemented. It would be a considerable effort. In general, using float/double on small embedded systems (without hardware floating point support) is not a good idea (slow, code bloat).

MarcDirven commented 3 years ago

Then I'd suggest at least putting a static_assert message in there because at the time (Sept - 2018), I was very confused. This can be easily be done using:

template<class>
struct AlwaysFalse : std::false_type {};

template<class F = std::enable_if_t<std::is_floating_point<F>::value, int> = 0>
friend ostream & operator<< ( ostream & stream, F ) {
    static_assert(AlwaysFalse<F>::value, "hwlib doesn't support outputting floating point values");
}