Boost logo

Boost :

From: Rozental, Gennadiy (gennadiy.rozental_at_[hidden])
Date: 2003-07-16 16:54:07


> | > Do I understand correctly that
> | >
> | > BOOST_CHECK_CLOSE(v1, v2, 2. * std::numeric_limits::epsilon() );
> | >
> | > would check that the absolute difference between v1 and v2 is not
> | > more than two eps?
> | >
> | > Paul
> |
> | No. BOOST_CHECK_CLOSE performs relative errors comparison. See
> | http://www.boost.org/libs/test/doc/floating_point_comparison.htm
> |
> | (Ignore part that tries to calculate the tolerance based on
> number of
> | rounding errors)
> |
> | Gennadiy.
>
> Yes of course - sorry. So how would I achieve the above test?

Something about these lines:

bool
struct my_fpt_compare
{
    explicit my_fpt_compare( float t ) : m_tolerance( t ) {}

    bool operator( float a, float b )
    {
        return std::fabs( a - b ) < m_tolerance;
    }

    float m_tolerance;
}
// Instead you could write free function and use boost::bind to bind the
tolerance

...

BOOST_CHECK_PREDICATE( my_fpt_compare( 2. * std::numeric_limits::epsilon()
), 2, ( v1, v2 ) );

Gennadiy.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk