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



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

Note that to use these tools you need to include additional header floating_point_comparison.hpp.

Example: BOOST_<level>_SMALL usage


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

  double v = -1.23456e-3;
  BOOST_CHECK_SMALL( v, 0.000001 );


> 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: