[test] floating point comparison

Hello all,
I've the following test program:
#define BOOST_TEST_DYN_LINK
#define BOOST_TEST_MAIN
#define BOOST_TEST_MODULE Master test suite
#include

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. -- Pekka

On 10/30/13, 3:00 PM, Pekka Seppänen wrote:
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.
Hi, What's then the difference between those two macro's: BOOST_<level>_CLOSE and BOOST_<level>_CLOSE_FRACTION ? The documentation indicates that the third parameter is indeed 'percentage units' but according to the output of both testcases in the documentation it suggests something else. See http://www.boost.org/doc/libs/1_54_0/libs/test/doc/html/utf/testing-tools/re... Do you have some explanation for that maybe? Regards, Matthijs Möhlmann

-----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

Matthijs Möhlmann
Why does it say that the difference is 0.00376352 and not 0.17....... ?
I means relative difference. Maybe I should have spell it out, but the error message is already long as is. BTW, new tool for floating point comparison in fact says "relative difference". BOOST_TEST( fp1 != fp2, tolerance ); HTH, Gennadiy
participants (4)
-
Gennadiy Rozental
-
Matthijs Möhlmann
-
Paul A. Bristow
-
Pekka Seppänen