added long double support for printing values

This commit is contained in:
skramm 2021-06-07 15:15:48 +02:00
parent 531a149ae7
commit d7f3d60cdc
4 changed files with 22 additions and 1 deletions

View File

@ -18,6 +18,9 @@ namespace Catch {
bool isnan(double d) { bool isnan(double d) {
return std::isnan(d); return std::isnan(d);
} }
bool isnan(long double d) {
return std::isnan(d);
}
#else #else
// For now we only use this for embarcadero // For now we only use this for embarcadero
bool isnan(float f) { bool isnan(float f) {
@ -26,6 +29,9 @@ namespace Catch {
bool isnan(double d) { bool isnan(double d) {
return std::_isnan(d); return std::_isnan(d);
} }
bool isnan(long double d) {
return std::_isnan(d);
}
#endif #endif
} // end namespace Catch } // end namespace Catch

View File

@ -10,6 +10,7 @@
namespace Catch { namespace Catch {
bool isnan(float f); bool isnan(float f);
bool isnan(double d); bool isnan(double d);
bool isnan(long double d);
} }
#endif // TWOBLUECUBES_CATCH_POLYFILLS_HPP_INCLUDED #endif // TWOBLUECUBES_CATCH_POLYFILLS_HPP_INCLUDED

View File

@ -73,7 +73,8 @@ std::string fpToString( T value, int precision ) {
ReusableStringStream rss; ReusableStringStream rss;
rss << std::setprecision( precision ) rss << std::setprecision( precision )
<< std::fixed << std::fixed
// << std::scientific // would be nice if we could switch between these two !
<< value; << value;
std::string d = rss.str(); std::string d = rss.str();
std::size_t i = d.find_last_not_of( '0' ); std::size_t i = d.find_last_not_of( '0' );
@ -250,6 +251,13 @@ std::string StringMaker<double>::convert(double value) {
return fpToString(value, precision); return fpToString(value, precision);
} }
int StringMaker<long double>::precision = 15;
std::string StringMaker<long double>::convert(long double value) {
return fpToString(value, precision);
}
std::string ratio_string<std::atto>::symbol() { return "a"; } std::string ratio_string<std::atto>::symbol() { return "a"; }
std::string ratio_string<std::femto>::symbol() { return "f"; } std::string ratio_string<std::femto>::symbol() { return "f"; }
std::string ratio_string<std::pico>::symbol() { return "p"; } std::string ratio_string<std::pico>::symbol() { return "p"; }

View File

@ -276,6 +276,12 @@ namespace Catch {
static int precision; static int precision;
}; };
template<>
struct StringMaker<long double> {
static std::string convert(long double value);
static int precision;
};
template <typename T> template <typename T>
struct StringMaker<T*> { struct StringMaker<T*> {
template <typename U> template <typename U>