Boost logo

Boost :

Subject: [boost] Fwd: [Boost-users] [test] floating point comparison
From: Matthijs Möhlmann (matthijs_at_[hidden])
Date: 2013-10-31 09:18:14

Hello all,

I already posted this to the boost users list, because I thought it was a
problem in my code, but I think its a bug in boost test (unit tests)

Boost: 1.54
GCC: 4.8.1

Does someone have an answer to this?

-------- Original Message --------
Subject: [Boost-users] [test] floating point comparison
Date: Wed, 30 Oct 2013 14:40:07 +0100
From: Matthijs Möhlmann <matthijs_at_[hidden]>
Reply-To: boost-users_at_[hidden]
To: boost-users_at_[hidden]

Hello all,

I've the following test program:

#define BOOST_TEST_MODULE Master test suite
#include <boost/test/unit_test.hpp>


     BOOST_REQUIRE_CLOSE_FRACTION(45.00f, 45.17f, 0.004f);

When I compile it with the following line:
g++ -o main.o -c -Werror -Wall -std=c++11 -fvisibility=hidden
-fvisibility-inlines-hidden -DBOOST_SPIRIT_USE_PHOENIX_V3 -DUTEST -g
g++ -o main main.o -lboost_unit_test_framework

I get the following output:
Running 1 test case...

*** No errors detected

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


Matthijs Möhlmann

Boost-users mailing list

Boost list run by bdawes at, gregod at, cpdaniel at, john at