List of all members | Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes
utl::CloseTo Class Reference

Predicate for approximate equality (for floating point) More...

#include <Test.h>

Inheritance diagram for utl::CloseTo:
Inheritance graph
[legend]

Public Member Functions

 CloseTo (const double eps=1e-6)
 
boost::format Name () const
 
template<typename T >
bool operator() (const T &lhs, const T &rhs) const
 

Protected Member Functions

template<typename T >
bool IsCloseAbs (const T &lhs, const T &rhs) const
 
bool IsCloseAbs (const utl::Triple &lhs, const utl::Triple &rhs) const
 
template<typename T >
bool IsCloseRel (const T &lhs, const T &rhs) const
 
else return IsCloseRel (lhs, rhs)
 

Static Protected Member Functions

template<typename Head , typename Tail >
static double TupleDist2 (const boost::tuples::cons< Head, Tail > &lhs, const boost::tuples::cons< Head, Tail > &rhs)
 
static double TupleDist2 (const boost::tuples::null_type &, const boost::tuples::null_type &)
 

Protected Attributes

bool const
 
double fEpsilon
 

Detailed Description

Predicate for approximate equality (for floating point)

The default precision is 1e-6, but it can be changed at construction time.

Definition at line 91 of file Test.h.

Constructor & Destructor Documentation

utl::CloseTo::CloseTo ( const double  eps = 1e-6)
inline

Definition at line 93 of file Test.h.

Member Function Documentation

template<typename T >
bool utl::CloseTo::IsCloseAbs ( const T &  lhs,
const T &  rhs 
) const
inlineprotected

Definition at line 104 of file Test.h.

References utl::abs(), and fEpsilon.

Referenced by utl::CloseAbs::operator()().

bool utl::CloseTo::IsCloseAbs ( const utl::Triple lhs,
const utl::Triple rhs 
) const
inlineprotected

Definition at line 107 of file Test.h.

References fEpsilon, sqrt(), and TupleDist2().

template<typename T >
bool utl::CloseTo::IsCloseRel ( const T &  lhs,
const T &  rhs 
) const
inlineprotected

Definition at line 111 of file Test.h.

References utl::abs(), and fEpsilon.

Referenced by utl::CloseRel::operator()().

else return utl::CloseTo::IsCloseRel ( lhs  ,
rhs   
)
protected
boost::format utl::CloseTo::Name ( ) const
inline

Definition at line 99 of file Test.h.

References fEpsilon.

Referenced by tst::Verify().

template<typename T >
bool utl::CloseTo::operator() ( const T &  lhs,
const T &  rhs 
) const
inline

Definition at line 96 of file Test.h.

template<typename Head , typename Tail >
static double utl::CloseTo::TupleDist2 ( const boost::tuples::cons< Head, Tail > &  lhs,
const boost::tuples::cons< Head, Tail > &  rhs 
)
inlinestaticprotected

Definition at line 138 of file Test.h.

Referenced by IsCloseAbs().

static double utl::CloseTo::TupleDist2 ( const boost::tuples::null_type &  ,
const boost::tuples::null_type &   
)
inlinestaticprotected

Definition at line 145 of file Test.h.

Member Data Documentation

bool utl::CloseTo::const
protected
Initial value:
{
return (2*sqrt(TupleDist2(lhs, rhs)) /
(sqrt(TupleDist2(lhs, utl::Triple(0,0,0))) +
sqrt(TupleDist2(rhs, utl::Triple(0,0,0))))) < fEpsilon

Definition at line 117 of file Test.h.

double utl::CloseTo::fEpsilon
protected

Definition at line 149 of file Test.h.

Referenced by IsCloseAbs(), IsCloseRel(), Name(), utl::CloseAbs::Name(), and utl::CloseRel::Name().


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

, generated on Tue Sep 26 2023.