diff --git a/include/internal/catch_approx.hpp b/include/internal/catch_approx.hpp index 940b641..fc68143 100644 --- a/include/internal/catch_approx.hpp +++ b/include/internal/catch_approx.hpp @@ -40,16 +40,17 @@ namespace Detail { return Approx( 0 ); } - Approx operator()( double value ) { - Approx approx( value ); +#if defined(CATCH_CONFIG_CPP11_TYPE_TRAITS) + + template ::value>::type> + Approx operator()( T value ) { + Approx approx( static_cast(value) ); approx.epsilon( m_epsilon ); approx.margin( m_margin ); approx.scale( m_scale ); return approx; } -#if defined(CATCH_CONFIG_CPP11_TYPE_TRAITS) - template ::value>::type> explicit Approx( T value ): Approx(static_cast(value)) {} @@ -100,7 +101,36 @@ namespace Detail { friend bool operator >= ( Approx const& lhs, T rhs ) { return lhs.m_value > double(rhs) || lhs == rhs; } + + template ::value>::type> + Approx& epsilon( T newEpsilon ) { + m_epsilon = double(newEpsilon); + return *this; + } + + template ::value>::type> + Approx& margin( T newMargin ) { + m_margin = double(newMargin); + return *this; + } + + template ::value>::type> + Approx& scale( T newScale ) { + m_scale = double(newScale); + return *this; + } + #else + + Approx operator()( double value ) { + Approx approx( value ); + approx.epsilon( m_epsilon ); + approx.margin( m_margin ); + approx.scale( m_scale ); + return approx; + } + + friend bool operator == ( double lhs, Approx const& rhs ) { // Thanks to Richard Harris for his help refining this formula bool relativeOK = std::fabs( lhs - rhs.m_value ) < rhs.m_epsilon * (rhs.m_scale + (std::max)( std::fabs(lhs), std::fabs(rhs.m_value) ) ); @@ -137,7 +167,6 @@ namespace Detail { friend bool operator >= ( Approx const& lhs, double rhs ) { return lhs.m_value > rhs || lhs == rhs; } -#endif Approx& epsilon( double newEpsilon ) { m_epsilon = newEpsilon; @@ -153,6 +182,7 @@ namespace Detail { m_scale = newScale; return *this; } +#endif std::string toString() const { std::ostringstream oss;