From d7f3d60cdcdbde1aeb47061167819000da9b3a19 Mon Sep 17 00:00:00 2001 From: skramm Date: Mon, 7 Jun 2021 15:15:48 +0200 Subject: [PATCH] added long double support for printing values --- include/internal/catch_polyfills.cpp | 6 ++++++ include/internal/catch_polyfills.hpp | 1 + include/internal/catch_tostring.cpp | 10 +++++++++- include/internal/catch_tostring.h | 6 ++++++ 4 files changed, 22 insertions(+), 1 deletion(-) diff --git a/include/internal/catch_polyfills.cpp b/include/internal/catch_polyfills.cpp index 68a2c827..67b4c58a 100644 --- a/include/internal/catch_polyfills.cpp +++ b/include/internal/catch_polyfills.cpp @@ -18,6 +18,9 @@ namespace Catch { bool isnan(double d) { return std::isnan(d); } + bool isnan(long double d) { + return std::isnan(d); + } #else // For now we only use this for embarcadero bool isnan(float f) { @@ -26,6 +29,9 @@ namespace Catch { bool isnan(double d) { return std::_isnan(d); } + bool isnan(long double d) { + return std::_isnan(d); + } #endif } // end namespace Catch diff --git a/include/internal/catch_polyfills.hpp b/include/internal/catch_polyfills.hpp index ba4189ef..24656b3f 100644 --- a/include/internal/catch_polyfills.hpp +++ b/include/internal/catch_polyfills.hpp @@ -10,6 +10,7 @@ namespace Catch { bool isnan(float f); bool isnan(double d); + bool isnan(long double d); } #endif // TWOBLUECUBES_CATCH_POLYFILLS_HPP_INCLUDED diff --git a/include/internal/catch_tostring.cpp b/include/internal/catch_tostring.cpp index a289c341..5bd81310 100644 --- a/include/internal/catch_tostring.cpp +++ b/include/internal/catch_tostring.cpp @@ -73,7 +73,8 @@ std::string fpToString( T value, int precision ) { ReusableStringStream rss; rss << std::setprecision( precision ) - << std::fixed + << std::fixed +// << std::scientific // would be nice if we could switch between these two ! << value; std::string d = rss.str(); std::size_t i = d.find_last_not_of( '0' ); @@ -250,6 +251,13 @@ std::string StringMaker::convert(double value) { return fpToString(value, precision); } +int StringMaker::precision = 15; + +std::string StringMaker::convert(long double value) { + return fpToString(value, precision); +} + + std::string ratio_string::symbol() { return "a"; } std::string ratio_string::symbol() { return "f"; } std::string ratio_string::symbol() { return "p"; } diff --git a/include/internal/catch_tostring.h b/include/internal/catch_tostring.h index e650458f..44dd9ca4 100644 --- a/include/internal/catch_tostring.h +++ b/include/internal/catch_tostring.h @@ -276,6 +276,12 @@ namespace Catch { static int precision; }; + template<> + struct StringMaker { + static std::string convert(long double value); + static int precision; + }; + template struct StringMaker { template