Boost logo

Boost Users :

From: Chris Fairles (chris.fairles_at_[hidden])
Date: 2007-05-31 10:34:06


After wondering why my BOOST_CHECK_CLOSE(some_number_close_to_zero,
0.0) hadn't been working, I found that the default comparison type is
FPC_STRONG which means the ration between the abs val of the
difference and BOTH values must be < tolerance but this doesn't turn
out to be true (running through what safe_fpt_division outputs atm ...

difference between 0.0{0} and 0.0
std::numeric_limits<double>::epsilon(){-2.2204460492503131e-16}
exceeds 0.01%

It should work using FPC_WEAK but I can't find a way through the
test_tools to easily change this. I have three solutions at this time.

1) Use BOOST_CHECK_SMALL. However, I have code that loops through
matrix indicies like:

for (int j = 0; j < matrix.col; j++)
  for (int i = 0; i < matrix.row; i++)
    BOOST_CHECK_CLOSE(matrix(i,j), data(i,j), tolerance);

I'm going to have to use an if statement for the special case where
I'm testing against 0 and it doesn't use the tolerance anyway so the
test is completely different. Theres another number to determine "how
small" the number should be.

2) Use check_is_close explicitly and change the default comparison
type to FPC_WEAK. This means going outside the nice auto-unit-test and
test-tools framework which although I'm fine with, other programmers
writing test cases on my team might not be.

3) Define my own macro to simplify solution 2.

Something along the lines of:
CHECK_IS_CLOSE_WEAK(x,y,t) {
  check_is_close(x ,y,t, FPC_WEAK);
}

Are there any other recommended solutions?


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