Boost logo

Boost Users :

From: Gennadiy Rozental (gennadiy.rozental_at_[hidden])
Date: 2007-03-13 18:12:33


"Pierre-Jules Tremblay" <iamtrep_at_[hidden]> wrote in message
news:4590bfef0703130709k4f70ad78ldc4d1c00c598ec53_at_mail.gmail.com...
> I've been having some problems using BOOST_CHECK_CLOSE() (1.33.1) in
> cases where one of the two arguments is exactly equal to zero: the
> tolerance check fails in this case (d'oh). I know that I can use
> BOOST_CHECK_SMALL() in those cases, but it's a real drag to have to
> write the boilerplate code to handle specific cases where one operand
> is zero. So this is what I've done:
>
> #define MY_CHECK_CLOSE(a,b,c) \
> if (a == 0) { BOOST_CHECK_SMALL(b,c); } \
> else if (b == 0) { BOOST_CHECK_SMALL(a,c); } \
> else { BOOST_CHECK_CLOSE(a,b,c); }
>
> I wonder: did I miss something, is there a better way? If not,
> perhaps this logic could be integrated in the _CLOSE tools.

BOOST_CHECK_CLOSE and BOOST_CHECK_SMALL are two very different tools. Former
is based on comparisons of relative values using percentage tolerance. Later
is based on comparison of absolute value against the actual tolerance.
Combining them into one is simply wrong. You couldn't use the same tolerance
value for both of them. Also there is a reason why BOOST_CHECK_CLOSE behaves
the way it behaves with zero value: in general no value is close to zero.
  Now if you need to follow above logic for your purposes you are free to do
this. But this could not be a part of Boost.Test.

Gennadiy


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net