Boost logo

Boost Users :

Subject: Re: [Boost-users] [test] floating point comparison
From: Pekka Seppänen (pekka.seppanen_at_[hidden])
Date: 2013-10-30 10:00:53


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


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net