Boost logo

Boost Users :

Subject: Re: [Boost-users] [Boost.Test] Understanding the correct use of BOOST_CHECK_CLOSE and BOOST_CHECK_CLOSE_FRACTION
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2010-09-09 11:01:17


AMDG

Torri, Stephen CIV NSWCDD, W15 wrote:
> I am trying to understand how to be use BOOST_CHECK_CLOSE and BOOST_CHECK_CLOSE_FRACTION for my problem. My problem is being able to check that two floating point values agree within 12 decimal digits. That is the difference between the two values is smaller than 1e-12. I see from the documentation that BOOST_CHECK_CLOSE requires a percent of agreement while BOOST_CHECK_CLOSE_FRACTION requires a fraction value. So when I used BOOST_CHECK_CLOSE_FRACTION to compare two value I got output that I didn't know how to read:
>
> /test_sgp4_orbit_data.cpp(52): error in "default_calculate_semi_major_test": difference{1e-12} between result{1.1219271770198256} and 1.1219271773271688{1.1219271773271688} exceeds 9.9999999999999998e-13
>
>
> I used BOOST_CHECK_CLOSE_FRACTION as:
>
> BOOST_CHECK_CLOSE_FRACTION ( result, 1.1219271773271688, 1e-12 );
>
> What I am intending is if 'result' and the value differ by more than 1e-12 then I have an error. If the difference is smaller than 1e-12 I wish to have the comparison succeed. From the output I don't know why the exceeds value is not written as '1e-12' since that is what I used.
>
> Where am I going wrong in my use of BOOST_CHECK_CLOSE_FRACTION?
>

Nowhere. 1e-12 cannot be represented exactly in floating point.
It gets rounded to the nearest representable value which is
printed as 9.9999999999999998e-13

In Christ,
Steven Watanabe


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