diff --git a/limits_test.cpp b/limits_test.cpp index 37af9bc5..ee8f3cc3 100644 --- a/limits_test.cpp +++ b/limits_test.cpp @@ -14,6 +14,7 @@ */ #include +#include #include #include @@ -44,6 +45,20 @@ void test_integral_limits(const T &, const char * msg) std::cout << "min: " << lim::min() << ", max: " << lim::max() << '\n'; } +template +void print_hex_val(T t, const char* name) +{ + const unsigned char* p = (const unsigned char*)&t; + std::cout << "hex value of " << name << " is: "; + for (int i = 0; i < sizeof(T); ++i) + { + if(p[i] <= 0xF) + std::cout << "0"; + std:: cout << std::hex << (int)p[i]; + } + std::cout << endl; +} + template void test_float_limits(const T &, const char * msg) { @@ -74,10 +89,14 @@ void test_float_limits(const T &, const char * msg) << ", exact: " << lim::is_exact << '\n' << "min: " << lim::min() << ", max: " << lim::max() << '\n' << "infinity: " << infinity << ", QNaN: " << qnan << '\n'; + print_hex_val(lim::max(), "max"); + print_hex_val(infinity, "infinity"); + print_hex_val(qnan, "qnan"); + print_hex_val(snan, "snan"); // infinity is beyond the representable range assert(lim::max() > 1000); - assert(infinity > lim::max()); - assert(-infinity < -lim::max()); + assert(lim::infinity() > lim::max()); + assert(-lim::infinity() < -lim::max()); assert(lim::min() < 0.001); assert(lim::min() > 0); @@ -124,3 +143,4 @@ int main() // warning here if "return 0;" is omitted. return 0; } +