-----Original Message----- From: Boost-users [mailto:boost-users-bounces@lists.boost.org] On Behalf Of Pekka Seppänen Sent: Wednesday, October 30, 2013 2:01 PM To: boost-users@lists.boost.org Subject: Re: [Boost-users] [test] floating point comparison
On 30.10.2013 15:40, Matthijs Möhlmann wrote:
Hello all,
I've the following test program:
BOOST_AUTO_TEST_CASE(TestCase) {
BOOST_REQUIRE_CLOSE_FRACTION(45.00f, 45.17f, 0.004f); }
If I lower the tolerance to 0.0004f then I'll get the following: Running 1 test case... main.cpp(8): fatal error in "TestCase": difference{0.00376352} between 45.00f{45} and 45.17f{45.1699982} exceeds 0.00039999999
*** 1 failure detected in test suite "Master test suite"
Why does it say that the difference is 0.00376352 and not 0.17....... ?
Hi,
it's because the tolerence is given in *percentage units*. Thus, it naturally reports thats the difference (again, in percentage units is 0.0038%) exceeds the given limit (that was now 0.0004%).
Not sure if your terminal just ommits the percentage signs. Maybe that was leading you off.
You probably will find BOOST_CHECK_CLOSE_FRACTION less confusing. No messing with % ;-) Bafflingly, BOOST_CHECK_CLOSE uses a percentage :-( Paul --- Paul A. Bristow, Prizet Farmhouse, Kendal LA8 8AB UK +44 1539 561830 07714330204 pbristow@hetp.u-net.com