Boost logo

Boost :

From: Fernando Cacciola (fcacciola_at_[hidden])
Date: 2001-12-06 15:31:45


----- Original Message -----
From: Ullrich Koethe <u.koethe_at_[hidden]>
To: <boost_at_[hidden]>
Sent: Thursday, December 06, 2001 5:07 PM
Subject: Re: [boost] RE: Formal review: New Boost.Test Library

> Dave Gomboc wrote:
> >
> > > What I suggest is to provide something like:
> > >
> > > template<class T> bool fp_equal(T const& l,T const& r) ;
> > > template<class T> bool fp_equal2(T const& l,T const& r, T const& tol)
> > ;
> > > template<class T> bool fp_equal32(T const& l,T const& r, T const& tol)
> > ;
> >
> > Using a fixed epsilon is bogus for the numerical applications that I am
> > familiar with. What we really need to do is make the third argument a
> > binary predicate returning bool whose operator() is called with the
> > first two arguments. That wasn't a great explanation, but I hope you
> > get what I mean.
> >
>
Actually, the fp_equal() family are *exactly* those predicates. They are
binary predicates taking *at least* two fp values and returning bool.
A particular application could have any additional predicate with whatever
tolerance it requires.
In other words, the above 'fp_equal' was there only to show precisely that
what we need is a true 'predicate'.
We can have an 'object' with bool operator() as well. Such an object could
even have the tolerance as a member.

> So you mean there should be
>
> BOOST_CHECK_PREDICATE1( arg, unary_predicate)
> and
> BOOST_CHECK_PREDICATE2( left, right, binary_predicate)
>
> along with their relatives? Good idea. The float comparisions could then
> be written
>
> BOOST_CHECK_PREDICATE2(left, right, close_at_tolerance(1.0e-5));
> BOOST_CHECK_PREDICATE2(left, right, weak_close_at_tolerance(1.0e-5));
> BOOST_CHECK_PREDICATE2(left, right,
> close_at_estimated_tolerance(left, right, number_of_operations));
> etc.
>

This sounds good.

The macro you are proposing is of the form BOOST_CHECK_PREDICATE(X,Y,PRED).

It evaluates PRED(X,Y),
and the X and Y macro parameters are there only to let them being shown in
the output.

I like this better than a BOOST_CHECK_CLOSE,etc.. macro family.

Fernando Cacciola
Sierra s.r.l.
fcacciola_at_[hidden]
www.gosierra.com


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