mirror of
https://github.com/catchorg/Catch2.git
synced 2025-08-01 12:55:40 +02:00
Format floats like doubles when printing - but add ‘f’ suffix (a lá #291)
This commit is contained in:
@@ -158,6 +158,7 @@ std::string toString( int value );
|
||||
std::string toString( unsigned long value );
|
||||
std::string toString( unsigned int value );
|
||||
std::string toString( const double value );
|
||||
std::string toString( const float value );
|
||||
std::string toString( bool value );
|
||||
std::string toString( char value );
|
||||
std::string toString( signed char value );
|
||||
|
@@ -103,9 +103,10 @@ std::string toString( unsigned int value ) {
|
||||
return toString( static_cast<unsigned long>( value ) );
|
||||
}
|
||||
|
||||
std::string toString( const double value ) {
|
||||
template<typename T>
|
||||
std::string fpToString( T value, int precision ) {
|
||||
std::ostringstream oss;
|
||||
oss << std::setprecision( 10 )
|
||||
oss << std::setprecision( precision )
|
||||
<< std::fixed
|
||||
<< value;
|
||||
std::string d = oss.str();
|
||||
@@ -118,6 +119,13 @@ std::string toString( const double value ) {
|
||||
return d;
|
||||
}
|
||||
|
||||
std::string toString( const double value ) {
|
||||
return fpToString( value, 10 );
|
||||
}
|
||||
std::string toString( const float value ) {
|
||||
return fpToString( value, 5 ) + "f";
|
||||
}
|
||||
|
||||
std::string toString( bool value ) {
|
||||
return value ? "true" : "false";
|
||||
}
|
||||
|
Reference in New Issue
Block a user