Boost logo

Boost Users :

Subject: Re: [Boost-users] [Boost.Test] Understanding the correct use of BOOST_CHECK_CLOSE and BOOST_CHECK_CLOSE_FRACTION
From: Torri, Stephen CIV NSWCDD, W15 (stephen.torri_at_[hidden])
Date: 2010-09-09 11:54:00


In retrospect I think I am using BOOST_CHECK_CLOSE_FRACTION incorrectly. What I want to do is take two values and compute their absolute variance. I want to then take that variance and determine if it is greater than (failure) or less than or equal a tolerance (success). I think I need to use BOOST_CHECK _LE instead as follows:
 
double a = 1.0e-12;
double b = 1.0e-13;
double tolerance = 1.0e-12;
 
BOOST_CHECK_LE ( fabs ( a - b ), tolerance );
 
So I could make a macro called:
 
/*!
 * \brief Check the absolute variance between two floating point or double values
 * \param L left float/double value
 * \param R right float/double value
 * \param T tolerance of comparison
 */
#define BOOST_CHECK_VARIANCE( L, R, T ) BOOST_CHECK_LE ( fabs ( L - R ), T )

Stephen
 
Stephen Torri, PhD
NAVAL SURFACE WARFARE CENTER DAHLGREN
17214 Ave B Suite 121
Dahlgren, Va. 22448
540-653-1082
I am not a contracting officer. I cannot modify or initiate contracts, nor do I have the authority to financially commit the government in any way.

 


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