RE: [boost] Boost Test Library: Bug in floating-point comparison?

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.

BOOST_IS_SMALL would be useful - I've wanted it recently. I'd still like to be able to specify in terms of number of abs eps, with one or two say, as default? However, having said that, I suspect your 'complainant' probably doesn't want really this. Paul Paul A Bristow Prizet Farmhouse, Kendal, Cumbria UK LA8 8AB +44 1539 561830 +44 7714 330204 mailto: pbristow@hetp.u-net.com | -----Original Message----- | From: boost-bounces@lists.boost.org | [mailto:boost-bounces@lists.boost.org] On Behalf Of Rozental, Gennadiy | Sent: 27 July 2004 21:30 | To: 'boost@lists.boost.org' | Subject: RE: [boost] Boost Test Library: Bug in | floating-point comparison? | | > 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_close( 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. | _______________________________________________ | Unsubscribe & other changes: | http://lists.boost.org/mailman/listinfo.cgi/boost | |
participants (2)
-
Paul A Bristow
-
Rozental, Gennadiy