mirror of
https://github.com/catchorg/Catch2.git
synced 2025-05-24 21:49:24 +00:00
parent
503d5d0c8e
commit
f3d1f08c3b
62 changed files with 527 additions and 527 deletions
|
@ -23,7 +23,7 @@ namespace Detail {
|
|||
m_scale( 1.0 ),
|
||||
m_value( value )
|
||||
{}
|
||||
|
||||
|
||||
Approx( Approx const& other )
|
||||
: m_epsilon( other.m_epsilon ),
|
||||
m_scale( other.m_scale ),
|
||||
|
@ -33,23 +33,23 @@ namespace Detail {
|
|||
static Approx custom() {
|
||||
return Approx( 0 );
|
||||
}
|
||||
|
||||
|
||||
Approx operator()( double value ) {
|
||||
Approx approx( value );
|
||||
approx.epsilon( m_epsilon );
|
||||
approx.scale( m_scale );
|
||||
return approx;
|
||||
}
|
||||
|
||||
|
||||
friend bool operator == ( double lhs, Approx const& rhs ) {
|
||||
// Thanks to Richard Harris for his help refining this formula
|
||||
return fabs( lhs - rhs.m_value ) < rhs.m_epsilon * (rhs.m_scale + (std::max)( fabs(lhs), fabs(rhs.m_value) ) );
|
||||
}
|
||||
|
||||
|
||||
friend bool operator == ( Approx const& lhs, double rhs ) {
|
||||
return operator==( rhs, lhs );
|
||||
}
|
||||
|
||||
|
||||
friend bool operator != ( double lhs, Approx const& rhs ) {
|
||||
return !operator==( lhs, rhs );
|
||||
}
|
||||
|
@ -57,23 +57,23 @@ namespace Detail {
|
|||
friend bool operator != ( Approx const& lhs, double rhs ) {
|
||||
return !operator==( rhs, lhs );
|
||||
}
|
||||
|
||||
|
||||
Approx& epsilon( double newEpsilon ) {
|
||||
m_epsilon = newEpsilon;
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
Approx& scale( double newScale ) {
|
||||
m_scale = newScale;
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
std::string toString() const {
|
||||
std::ostringstream oss;
|
||||
oss << "Approx( " << m_value << " )";
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
double m_epsilon;
|
||||
double m_scale;
|
||||
|
@ -85,7 +85,7 @@ template<>
|
|||
inline std::string toString<Detail::Approx>( Detail::Approx const& value ) {
|
||||
return value.toString();
|
||||
}
|
||||
|
||||
|
||||
} // end namespace Catch
|
||||
|
||||
#endif // TWOBLUECUBES_CATCH_APPROX_HPP_INCLUDED
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue