diff --git a/include/internal/catch_approx.cpp b/include/internal/catch_approx.cpp index ca3ac94a..826a1049 100644 --- a/include/internal/catch_approx.cpp +++ b/include/internal/catch_approx.cpp @@ -23,7 +23,7 @@ namespace Detail { Approx::Approx ( double value ) : m_epsilon( std::numeric_limits::epsilon()*100 ), m_margin( 0.0 ), - m_scale( 1.0 ), + m_scale( 0.0 ), m_value( value ) {} diff --git a/include/internal/catch_approx.h b/include/internal/catch_approx.h index 69428c8a..8ca7f315 100644 --- a/include/internal/catch_approx.h +++ b/include/internal/catch_approx.h @@ -44,8 +44,9 @@ namespace Detail { friend bool operator == ( const T& lhs, Approx const& rhs ) { // Thanks to Richard Harris for his help refining this formula auto lhs_v = static_cast(lhs); - bool relativeOK = std::fabs(lhs_v - rhs.m_value) < rhs.m_epsilon * (rhs.m_scale + - dmax(std::fabs(lhs_v), std::fabs(rhs.m_value))); + + bool relativeOK = std::fabs( lhs_v - rhs.m_value ) < rhs.m_epsilon * (rhs.m_scale + std::fabs(rhs.m_value) ); + if (relativeOK) { return true; } @@ -89,7 +90,11 @@ namespace Detail { template ::value>::type> Approx& epsilon( T const& newEpsilon ) { - m_epsilon = static_cast(newEpsilon); + double asDouble = static_cast(newEpsilon); + CATCH_ENFORCE(asDouble >= 0 && asDouble <= 1.0, + "Invalid Approx::epsilon: " << m_epsilon << + ", Approx::epsilon has to be between 0 and 1"); + m_epsilon = asDouble; return *this; }