Beman Dawes <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> At 02:22 PM 7/7/2003, Rozental, Gennadiy wrote:
>
>  >I could probably prohibit usage of CHECK_CLOSE with number of rounding
>  >errors provided.
>  >Is there any other general recommendations how to choose the tolerance
to
>
>  >FP computation correctness checking?
>
> There has been some recent discussion on comp.lang.c++.moderated, subject
> "equality of two doubles". The last post was from Andrei Alexandrescu:
>
>  >What's most of the time needed is relative precision.
>  >
>  >So, numerical gurus: how can one express "a equals b within 0.1%" over
>  >the whole range of floating point numbers? If that can be done, it would
>  >be a nice useful routine.
>  >
>  >bool approximately_equal(double lhs, double rhs, double relative_prec)
>  >{
>  >    // fill in here please :o)
>  >}
>
> But it really doesn't seem that a test library is the right home for such
> functions. I think all the fp stuff should be removed from Boost.Test, and
> passed on as a challenge to the numerics experts.
>
> After all, the user can always write:
>
>    BOOST_CHECK( approximately_equal(...) );
>
> --Beman
>
A half-way solution is to have something like:

BOOST_CHECK_EQUAL_NUMBERS(x,y,IsEqual)

and let users specify their own Preciates.

By default, the Test library could provide
a straight-forward ABSOLUTE-ERROR comparator:

template<class N>
struct IsNearlyEqual
{
  IsNearlyEqual ( N a_tol = N(1e-6) ) : m_tol(a_tol) {}

  bool operator() ( N x, N y ) const
    {
      return x >= y ? ( x - y ) <= m_tol
                    : ( y - x ) <= m_tol ;
    }

  N m_tol ;
} ;

Which would be used as follows:

double n = ..., m = ... ;
BOOST_CHECK_EQUAL_NUMBERS(n,m,IsNearlyEqual<double>());

Fernando Cacciola




_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

Reply via email to