ManaPlus
Public Member Functions | Static Public Member Functions | Private Attributes | Friends
Catch::Detail::Approx Class Reference

#include <catch.hpp>

Public Member Functions

 Approx (double value)
 
 Approx (Approx const &other)
 
Approx operator() (double value)
 
Approxepsilon (double newEpsilon)
 
Approxscale (double newScale)
 
std::string toString () const
 

Static Public Member Functions

static Approx custom ()
 

Private Attributes

double m_epsilon
 
double m_scale
 
double m_value
 

Friends

bool operator== (double lhs, Approx const &rhs)
 
bool operator== (Approx const &lhs, double rhs)
 
bool operator!= (double lhs, Approx const &rhs)
 
bool operator!= (Approx const &lhs, double rhs)
 

Detailed Description

Definition at line 2627 of file catch.hpp.

Constructor & Destructor Documentation

◆ Approx() [1/2]

Catch::Detail::Approx::Approx ( double  value)
inlineexplicit

Definition at line 2629 of file catch.hpp.

2630  : m_epsilon( std::numeric_limits<float>::epsilon()*100 ),
2631  m_scale( 1.0 ),
2632  m_value( value )
2633  {}

◆ Approx() [2/2]

Catch::Detail::Approx::Approx ( Approx const &  other)
inline

Definition at line 2635 of file catch.hpp.

2636  : m_epsilon( other.m_epsilon ),
2637  m_scale( other.m_scale ),
2638  m_value( other.m_value )
2639  {}

Member Function Documentation

◆ custom()

static Approx Catch::Detail::Approx::custom ( )
inlinestatic

Definition at line 2641 of file catch.hpp.

2641  {
2642  return Approx( 0 );
2643  }
Approx(double value)
Definition: catch.hpp:2629

◆ epsilon()

Approx& Catch::Detail::Approx::epsilon ( double  newEpsilon)
inline

Definition at line 2669 of file catch.hpp.

2669  {
2670  m_epsilon = newEpsilon;
2671  return *this;
2672  }

Referenced by operator()().

◆ operator()()

Approx Catch::Detail::Approx::operator() ( double  value)
inline

Definition at line 2645 of file catch.hpp.

2645  {
2646  Approx approx( value );
2647  approx.epsilon( m_epsilon );
2648  approx.scale( m_scale );
2649  return approx;
2650  }

References epsilon(), and scale().

◆ scale()

Approx& Catch::Detail::Approx::scale ( double  newScale)
inline

Definition at line 2674 of file catch.hpp.

2674  {
2675  m_scale = newScale;
2676  return *this;
2677  }

Referenced by operator()().

◆ toString()

std::string Catch::Detail::Approx::toString ( ) const
inline

Definition at line 2679 of file catch.hpp.

2679  {
2680  std::ostringstream oss;
2681  oss << "Approx( " << Catch::toString( m_value ) << " )";
2682  return oss.str();
2683  }
std::string toString(T const &value)
converts any type to a string
Definition: catch.hpp:1774

References Catch::toString().

Referenced by Catch::toString< Detail::Approx >().

Friends And Related Function Documentation

◆ operator!= [1/2]

bool operator!= ( Approx const &  lhs,
double  rhs 
)
friend

Definition at line 2665 of file catch.hpp.

2665  {
2666  return !operator==( rhs, lhs );
2667  }
friend bool operator==(double lhs, Approx const &rhs)
Definition: catch.hpp:2652

◆ operator!= [2/2]

bool operator!= ( double  lhs,
Approx const &  rhs 
)
friend

Definition at line 2661 of file catch.hpp.

2661  {
2662  return !operator==( lhs, rhs );
2663  }

◆ operator== [1/2]

bool operator== ( Approx const &  lhs,
double  rhs 
)
friend

Definition at line 2657 of file catch.hpp.

2657  {
2658  return operator==( rhs, lhs );
2659  }

◆ operator== [2/2]

bool operator== ( double  lhs,
Approx const &  rhs 
)
friend

Definition at line 2652 of file catch.hpp.

2652  {
2653  // Thanks to Richard Harris for his help refining this formula
2654  return fabs( lhs - rhs.m_value ) < rhs.m_epsilon * (rhs.m_scale + (std::max)( fabs(lhs), fabs(rhs.m_value) ) );
2655  }

Field Documentation

◆ m_epsilon

double Catch::Detail::Approx::m_epsilon
private

Definition at line 2686 of file catch.hpp.

◆ m_scale

double Catch::Detail::Approx::m_scale
private

Definition at line 2687 of file catch.hpp.

◆ m_value

double Catch::Detail::Approx::m_value
private

Definition at line 2688 of file catch.hpp.


The documentation for this class was generated from the following file: