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

This is the documentation for an old version of boost. Click here for the latest Boost documentation.
PrevUpHomeNext

Using macros to Change the Policy Defaults

You can use the various macros below to change any (or all) of the policies.

You can make a local change by placing a macro definition before a function or distribution #include.

[Caution] Caution

There is a danger of One-Definition-Rule violations if you add ad-hoc macros to more than one source files: these must be set the same in every translation unit.

[Caution] Caution

If you place it after the #include it will have no effect, (and it will affect only any other following #includes). This is probably not what you intend!

If you want to alter the defaults for any or all of the policies for all functions and distributions, installation-wide, then you can do so by defining various macros in boost/math/tools/user.hpp.

BOOST_MATH_DOMAIN_ERROR_POLICY

Defines what happens when a domain error occurs, if not defined then defaults to throw_on_error, but can be set to any of the enumerated actions for error handing: throw_on_error, errno_on_error, ignore_error or user_error.

BOOST_MATH_POLE_ERROR_POLICY

Defines what happens when a pole error occurs, if not defined then defaults to throw_on_error, but can be set to any of the enumerated actions for error handing: throw_on_error, errno_on_error, ignore_error or user_error.

BOOST_MATH_OVERFLOW_ERROR_POLICY

Defines what happens when an overflow error occurs, if not defined then defaults to throw_on_error, but can be set to any of the enumerated actions for error handing: throw_on_error, errno_on_error, ignore_error or user_error.

BOOST_MATH_ROUNDING_ERROR_POLICY

Defines what happens when a rounding error occurs, if not defined then defaults to throw_on_error, but can be set to any of the enumerated actions for error handing: throw_on_error, errno_on_error, ignore_error or user_error.

BOOST_MATH_EVALUATION_ERROR_POLICY

Defines what happens when an internal evaluation error occurs, if not defined then defaults to throw_on_error, but can be set to any of the enumerated actions for error handing: throw_on_error, errno_on_error, ignore_error or user_error.

BOOST_MATH_UNDERFLOW_ERROR_POLICY

Defines what happens when an overflow error occurs, if not defined then defaults to ignore_error, but can be set to any of the enumerated actions for error handing: throw_on_error, errno_on_error, ignore_error or user_error.

BOOST_MATH_DENORM_ERROR_POLICY

Defines what happens when a denormalisation error occurs, if not defined then defaults to ignore_error, but can be set to any of the enumerated actions for error handing: throw_on_error, errno_on_error, ignore_error or user_error.

BOOST_MATH_INDETERMINATE_RESULT_ERROR_POLICY

Defines what happens when the result is indeterminate, but where there is none the less a convention for the result. If not defined then defaults to ignore_error, but can be set to any of the enumerated actions for error handing: throw_on_error, errno_on_error, ignore_error or user_error.

BOOST_MATH_DIGITS10_POLICY

Defines how many decimal digits to use in internal computations: defaults to 0 - meaning use all available digits - but can be set to some other decimal value. Since setting this is likely to have a substantial impact on accuracy, it's not generally recommended that you change this from the default.

BOOST_MATH_PROMOTE_FLOAT_POLICY

Determines whether float types get promoted to double internally to ensure maximum precision in the result, defaults to true, but can be set to false to turn promotion of float's off.

BOOST_MATH_PROMOTE_DOUBLE_POLICY

Determines whether double types get promoted to long double internally to ensure maximum precision in the result, defaults to true, but can be set to false to turn promotion of double's off.

BOOST_MATH_DISCRETE_QUANTILE_POLICY

Determines how discrete quantiles return their results: either as an integer, or as a real value, can be set to one of the enumerated values: real, integer_round_outwards, integer_round_inwards, integer_round_down, integer_round_up, integer_round_nearest. Defaults to integer_round_outwards.

BOOST_MATH_ASSERT_UNDEFINED_POLICY

Determines whether functions that are mathematically undefined for a specific distribution compile or raise a static (i.e. compile-time) assertion. Defaults to true: meaning that any mathematically undefined function will not compile. When set to false then the function will compile but return the result of a domain error: this can be useful for some generic code, that needs to work with all distributions and determine at runtime whether or not a particular property is well defined.

BOOST_MATH_MAX_SERIES_ITERATION_POLICY

Determines how many series iterations a special function is permitted to perform before it gives up and returns an evaluation_error: Defaults to 1000000.

BOOST_MATH_MAX_ROOT_ITERATION_POLICY

Determines how many root-finding iterations a special function is permitted to perform before it gives up and returns an evaluation_error: Defaults to 200.

Example

Suppose we want overflow errors to set ::errno and return an infinity, discrete quantiles to return a real-valued result (rather than round to integer), and for mathematically undefined functions to compile, but return a domain error. Then we could add the following to boost/math/tools/user.hpp:

#define BOOST_MATH_OVERFLOW_ERROR_POLICY errno_on_error
#define BOOST_MATH_DISCRETE_QUANTILE_POLICY real
#define BOOST_MATH_ASSERT_UNDEFINED_POLICY false

or we could place these definitions before

#include <boost/math/distributions/normal.hpp>
  using boost::math::normal_distribution;

in a source .cpp file.


PrevUpHomeNext