
Hi,
I want to use the boost::test floating-point comparison algorithms (Boost 1.31.0) and wrote the following simple lines of code:
double d1 = 0.2; double d2 = 0.8; double d3 = d2-d1-d1-d1-d1; // d3 should be zero
bool b = boost::test_toolbox::check_is_closed( d3, 0., 1e-3 );
To my surprise, the return value b is FALSE, although d3 should be _very_ close to zero (and is 5.55112e-17 on my machine).
Am I missing something or is this a bug in the test library?
Thanks, Michael
-- Michael Kettner kettner@ive.uni-hannover.de
Read algorithm description. The algorithm compare "relative errors". In your case it's 1 and infinity. Definitely more then 1e-03. It you want to compare absolute values (which is not recommended in real life applications) you either could write you own predicate or wait a bit, while I am considering adding BOOST_IS_SMALL tool that will be responsible namely for this kind of test. Gennadiy.