Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

PrevUpHomeNext

BOOST_<level>_SMALL

BOOST_WARN_SMALL(value, tolerance);
BOOST_CHECK_SMALL(value, tolerance);
BOOST_REQUIRE_SMALL(value, tolerance);

These tools are used to check that supplied value is small enough. The "smallness" is defined by absolute value of the tolerance supplied as a second argument. Use these tools with caution. To compare to values on closeness it's preferable to use BOOST_<level>_CLOSE tools instead.

The first parameter is the value to check. The second parameter is the tolerance.

[Note] Note

The floating point comparison tools are automatically added if the Unit Test Framework is included as indicated in the previous sections. The tools are implemented is in the header boost/test/tools/floating_point_comparison.hpp.

Example: BOOST_<level>_SMALL usage

Code

#define BOOST_TEST_MODULE example
#include <boost/test/included/unit_test.hpp>
#include <boost/test/tools/floating_point_comparison.hpp>

BOOST_AUTO_TEST_CASE( test )
{
  double v = -1.23456e-3;
  BOOST_CHECK_SMALL( v, 0.000001 );
}

Output

> example
Running 1 test case...
test.cpp(11): error in "test": absolute value of v{-0.00123456} exceeds 1e-006

*** 1 failures is detected in test suite "example"

See also:


PrevUpHomeNext