<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=US-ASCII"> <title>Using macros to Change the Policy Defaults</title> <link rel="stylesheet" href="../../../../../../../../doc/src/boostbook.css" type="text/css"> <meta name="generator" content="DocBook XSL Stylesheets V1.74.0"> <link rel="home" href="../../../index.html" title="Math Toolkit"> <link rel="up" href="../pol_ref.html" title="Policy Reference"> <link rel="prev" href="iteration_pol.html" title="Iteration Limits Policies"> <link rel="next" href="namespace_pol.html" title="Setting Polices at Namespace Scope"> </head> <body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"> <table cellpadding="2" width="100%"><tr> <td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../../../boost.png"></td> <td align="center"><a href="../../../../../../../../index.html">Home</a></td> <td align="center"><a href="../../../../../../../../libs/libraries.htm">Libraries</a></td> <td align="center"><a href="http://www.boost.org/users/people.html">People</a></td> <td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td> <td align="center"><a href="../../../../../../../../more/index.htm">More</a></td> </tr></table> <hr> <div class="spirit-nav"> <a accesskey="p" href="iteration_pol.html"><img src="../../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../pol_ref.html"><img src="../../../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../../index.html"><img src="../../../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="namespace_pol.html"><img src="../../../../../../../../doc/src/images/next.png" alt="Next"></a> </div> <div class="section" lang="en"> <div class="titlepage"><div><div><h4 class="title"> <a name="math_toolkit.policy.pol_ref.policy_defaults"></a><a class="link" href="policy_defaults.html" title="Using macros to Change the Policy Defaults"> Using macros to Change the Policy Defaults</a> </h4></div></div></div> <p> You can use the various macros below to change any (or all) of the policies. </p> <p> You can make a local change by placing a macro definition <span class="bold"><strong>before</strong></span> a function or distribution #include. </p> <div class="caution"><table border="0" summary="Caution"> <tr> <td rowspan="2" align="center" valign="top" width="25"><img alt="[Caution]" src="../../../../../../../../doc/src/images/caution.png"></td> <th align="left">Caution</th> </tr> <tr><td align="left" valign="top"><p> 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 <span class="bold"><strong>every translation unit</strong></span>. </p></td></tr> </table></div> <div class="caution"><table border="0" summary="Caution"> <tr> <td rowspan="2" align="center" valign="top" width="25"><img alt="[Caution]" src="../../../../../../../../doc/src/images/caution.png"></td> <th align="left">Caution</th> </tr> <tr><td align="left" valign="top"><p> 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! </p></td></tr> </table></div> <p> If you want to alter the defaults for any or all of the policies for <span class="bold"><strong>all</strong></span> functions and distributions, installation-wide, then you can do so by defining various macros in <a href="../../../../../../../../boost/math/tools/user.hpp" target="_top">boost/math/tools/user.hpp</a>. </p> <a name="math_toolkit.policy.pol_ref.policy_defaults.boost_math_domain_error_policy"></a><h6> <a name="id1270171"></a> <a class="link" href="policy_defaults.html#math_toolkit.policy.pol_ref.policy_defaults.boost_math_domain_error_policy">BOOST_MATH_DOMAIN_ERROR_POLICY</a> </h6> <p> Defines what happens when a domain error occurs, if not defined then defaults to <code class="computeroutput"><span class="identifier">throw_on_error</span></code>, but can be set to any of the enumerated actions for error handing: <code class="computeroutput"><span class="identifier">throw_on_error</span></code>, <code class="computeroutput"><span class="identifier">errno_on_error</span></code>, <code class="computeroutput"><span class="identifier">ignore_error</span></code> or <code class="computeroutput"><span class="identifier">user_error</span></code>. </p> <a name="math_toolkit.policy.pol_ref.policy_defaults.boost_math_pole_error_policy"></a><h6> <a name="id1270224"></a> <a class="link" href="policy_defaults.html#math_toolkit.policy.pol_ref.policy_defaults.boost_math_pole_error_policy">BOOST_MATH_POLE_ERROR_POLICY</a> </h6> <p> Defines what happens when a pole error occurs, if not defined then defaults to <code class="computeroutput"><span class="identifier">throw_on_error</span></code>, but can be set to any of the enumerated actions for error handing: <code class="computeroutput"><span class="identifier">throw_on_error</span></code>, <code class="computeroutput"><span class="identifier">errno_on_error</span></code>, <code class="computeroutput"><span class="identifier">ignore_error</span></code> or <code class="computeroutput"><span class="identifier">user_error</span></code>. </p> <a name="math_toolkit.policy.pol_ref.policy_defaults.boost_math_overflow_error_policy"></a><h6> <a name="id1270277"></a> <a class="link" href="policy_defaults.html#math_toolkit.policy.pol_ref.policy_defaults.boost_math_overflow_error_policy">BOOST_MATH_OVERFLOW_ERROR_POLICY</a> </h6> <p> Defines what happens when an overflow error occurs, if not defined then defaults to <code class="computeroutput"><span class="identifier">throw_on_error</span></code>, but can be set to any of the enumerated actions for error handing: <code class="computeroutput"><span class="identifier">throw_on_error</span></code>, <code class="computeroutput"><span class="identifier">errno_on_error</span></code>, <code class="computeroutput"><span class="identifier">ignore_error</span></code> or <code class="computeroutput"><span class="identifier">user_error</span></code>. </p> <a name="math_toolkit.policy.pol_ref.policy_defaults.boost_math_rounding_error_policy"></a><h6> <a name="id1270330"></a> <a class="link" href="policy_defaults.html#math_toolkit.policy.pol_ref.policy_defaults.boost_math_rounding_error_policy">BOOST_MATH_ROUNDING_ERROR_POLICY</a> </h6> <p> Defines what happens when a rounding error occurs, if not defined then defaults to <code class="computeroutput"><span class="identifier">throw_on_error</span></code>, but can be set to any of the enumerated actions for error handing: <code class="computeroutput"><span class="identifier">throw_on_error</span></code>, <code class="computeroutput"><span class="identifier">errno_on_error</span></code>, <code class="computeroutput"><span class="identifier">ignore_error</span></code> or <code class="computeroutput"><span class="identifier">user_error</span></code>. </p> <a name="math_toolkit.policy.pol_ref.policy_defaults.boost_math_evaluation_error_policy"></a><h6> <a name="id1270382"></a> <a class="link" href="policy_defaults.html#math_toolkit.policy.pol_ref.policy_defaults.boost_math_evaluation_error_policy">BOOST_MATH_EVALUATION_ERROR_POLICY</a> </h6> <p> Defines what happens when an internal evaluation error occurs, if not defined then defaults to <code class="computeroutput"><span class="identifier">throw_on_error</span></code>, but can be set to any of the enumerated actions for error handing: <code class="computeroutput"><span class="identifier">throw_on_error</span></code>, <code class="computeroutput"><span class="identifier">errno_on_error</span></code>, <code class="computeroutput"><span class="identifier">ignore_error</span></code> or <code class="computeroutput"><span class="identifier">user_error</span></code>. </p> <a name="math_toolkit.policy.pol_ref.policy_defaults.boost_math_underflow_error_policy"></a><h6> <a name="id1270435"></a> <a class="link" href="policy_defaults.html#math_toolkit.policy.pol_ref.policy_defaults.boost_math_underflow_error_policy">BOOST_MATH_UNDERFLOW_ERROR_POLICY</a> </h6> <p> Defines what happens when an overflow error occurs, if not defined then defaults to <code class="computeroutput"><span class="identifier">ignore_error</span></code>, but can be set to any of the enumerated actions for error handing: <code class="computeroutput"><span class="identifier">throw_on_error</span></code>, <code class="computeroutput"><span class="identifier">errno_on_error</span></code>, <code class="computeroutput"><span class="identifier">ignore_error</span></code> or <code class="computeroutput"><span class="identifier">user_error</span></code>. </p> <a name="math_toolkit.policy.pol_ref.policy_defaults.boost_math_denorm_error_policy"></a><h6> <a name="id1270488"></a> <a class="link" href="policy_defaults.html#math_toolkit.policy.pol_ref.policy_defaults.boost_math_denorm_error_policy">BOOST_MATH_DENORM_ERROR_POLICY</a> </h6> <p> Defines what happens when a denormalisation error occurs, if not defined then defaults to <code class="computeroutput"><span class="identifier">ignore_error</span></code>, but can be set to any of the enumerated actions for error handing: <code class="computeroutput"><span class="identifier">throw_on_error</span></code>, <code class="computeroutput"><span class="identifier">errno_on_error</span></code>, <code class="computeroutput"><span class="identifier">ignore_error</span></code> or <code class="computeroutput"><span class="identifier">user_error</span></code>. </p> <a name="math_toolkit.policy.pol_ref.policy_defaults.boost_math_indeterminate_result_error_policy"></a><h6> <a name="id1270541"></a> <a class="link" href="policy_defaults.html#math_toolkit.policy.pol_ref.policy_defaults.boost_math_indeterminate_result_error_policy">BOOST_MATH_INDETERMINATE_RESULT_ERROR_POLICY</a> </h6> <p> 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 <code class="computeroutput"><span class="identifier">ignore_error</span></code>, but can be set to any of the enumerated actions for error handing: <code class="computeroutput"><span class="identifier">throw_on_error</span></code>, <code class="computeroutput"><span class="identifier">errno_on_error</span></code>, <code class="computeroutput"><span class="identifier">ignore_error</span></code> or <code class="computeroutput"><span class="identifier">user_error</span></code>. </p> <a name="math_toolkit.policy.pol_ref.policy_defaults.boost_math_digits10_policy"></a><h6> <a name="id1270594"></a> <a class="link" href="policy_defaults.html#math_toolkit.policy.pol_ref.policy_defaults.boost_math_digits10_policy">BOOST_MATH_DIGITS10_POLICY</a> </h6> <p> Defines how many decimal digits to use in internal computations: defaults to <code class="computeroutput"><span class="number">0</span></code> - 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. </p> <a name="math_toolkit.policy.pol_ref.policy_defaults.boost_math_promote_float_policy"></a><h6> <a name="id1270618"></a> <a class="link" href="policy_defaults.html#math_toolkit.policy.pol_ref.policy_defaults.boost_math_promote_float_policy">BOOST_MATH_PROMOTE_FLOAT_POLICY</a> </h6> <p> Determines whether <code class="computeroutput"><span class="keyword">float</span></code> types get promoted to <code class="computeroutput"><span class="keyword">double</span></code> internally to ensure maximum precision in the result, defaults to <code class="computeroutput"><span class="keyword">true</span></code>, but can be set to <code class="computeroutput"><span class="keyword">false</span></code> to turn promotion of <code class="computeroutput"><span class="keyword">float</span></code>'s off. </p> <a name="math_toolkit.policy.pol_ref.policy_defaults.boost_math_promote_double_policy"></a><h6> <a name="id1270670"></a> <a class="link" href="policy_defaults.html#math_toolkit.policy.pol_ref.policy_defaults.boost_math_promote_double_policy">BOOST_MATH_PROMOTE_DOUBLE_POLICY</a> </h6> <p> Determines whether <code class="computeroutput"><span class="keyword">double</span></code> types get promoted to <code class="computeroutput"><span class="keyword">long</span> <span class="keyword">double</span></code> internally to ensure maximum precision in the result, defaults to <code class="computeroutput"><span class="keyword">true</span></code>, but can be set to <code class="computeroutput"><span class="keyword">false</span></code> to turn promotion of <code class="computeroutput"><span class="keyword">double</span></code>'s off. </p> <a name="math_toolkit.policy.pol_ref.policy_defaults.boost_math_discrete_quantile_policy"></a><h6> <a name="id1270728"></a> <a class="link" href="policy_defaults.html#math_toolkit.policy.pol_ref.policy_defaults.boost_math_discrete_quantile_policy">BOOST_MATH_DISCRETE_QUANTILE_POLICY</a> </h6> <p> 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: <code class="computeroutput"><span class="identifier">real</span></code>, <code class="computeroutput"><span class="identifier">integer_round_outwards</span></code>, <code class="computeroutput"><span class="identifier">integer_round_inwards</span></code>, <code class="computeroutput"><span class="identifier">integer_round_down</span></code>, <code class="computeroutput"><span class="identifier">integer_round_up</span></code>, <code class="computeroutput"><span class="identifier">integer_round_nearest</span></code>. Defaults to <code class="computeroutput"><span class="identifier">integer_round_outwards</span></code>. </p> <a name="math_toolkit.policy.pol_ref.policy_defaults.boost_math_assert_undefined_policy"></a><h6> <a name="id1270795"></a> <a class="link" href="policy_defaults.html#math_toolkit.policy.pol_ref.policy_defaults.boost_math_assert_undefined_policy">BOOST_MATH_ASSERT_UNDEFINED_POLICY</a> </h6> <p> Determines whether functions that are mathematically undefined for a specific distribution compile or raise a static (i.e. compile-time) assertion. Defaults to <code class="computeroutput"><span class="keyword">true</span></code>: meaning that any mathematically undefined function will not compile. When set to <code class="computeroutput"><span class="keyword">false</span></code> 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. </p> <a name="math_toolkit.policy.pol_ref.policy_defaults.boost_math_max_series_iteration_policy"></a><h6> <a name="id1270826"></a> <a class="link" href="policy_defaults.html#math_toolkit.policy.pol_ref.policy_defaults.boost_math_max_series_iteration_policy">BOOST_MATH_MAX_SERIES_ITERATION_POLICY</a> </h6> <p> Determines how many series iterations a special function is permitted to perform before it gives up and returns an <a class="link" href="../../main_overview/error_handling.html#evaluation_error">evaluation_error</a>: Defaults to 1000000. </p> <a name="math_toolkit.policy.pol_ref.policy_defaults.boost_math_max_root_iteration_policy"></a><h6> <a name="id1270848"></a> <a class="link" href="policy_defaults.html#math_toolkit.policy.pol_ref.policy_defaults.boost_math_max_root_iteration_policy">BOOST_MATH_MAX_ROOT_ITERATION_POLICY</a> </h6> <p> Determines how many root-finding iterations a special function is permitted to perform before it gives up and returns an <a class="link" href="../../main_overview/error_handling.html#evaluation_error">evaluation_error</a>: Defaults to 200. </p> <a name="math_toolkit.policy.pol_ref.policy_defaults.example"></a><h6> <a name="id1270870"></a> <a class="link" href="policy_defaults.html#math_toolkit.policy.pol_ref.policy_defaults.example">Example</a> </h6> <p> Suppose we want overflow errors to set <code class="computeroutput"><span class="special">::</span><span class="identifier">errno</span></code> 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: </p> <pre class="programlisting"><span class="preprocessor">#define</span> <span class="identifier">BOOST_MATH_OVERFLOW_ERROR_POLICY</span> <span class="identifier">errno_on_error</span> <span class="preprocessor">#define</span> <span class="identifier">BOOST_MATH_DISCRETE_QUANTILE_POLICY</span> <span class="identifier">real</span> <span class="preprocessor">#define</span> <span class="identifier">BOOST_MATH_ASSERT_UNDEFINED_POLICY</span> <span class="keyword">false</span> </pre> <p> or we could place these definitions <span class="bold"><strong>before</strong></span> </p> <pre class="programlisting"><span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">math</span><span class="special">/</span><span class="identifier">distributions</span><span class="special">/</span><span class="identifier">normal</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span> <span class="keyword">using</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">math</span><span class="special">::</span><span class="identifier">normal_distribution</span><span class="special">;</span> </pre> <p> in a source .cpp file. </p> </div> <table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr> <td align="left"></td> <td align="right"><div class="copyright-footer">Copyright © 2006 , 2007, 2008, 2009 John Maddock, Paul A. Bristow, Hubert Holin, Xiaogang Zhang, Bruno Lalande, Johan Råde, Gautam Sewani and Thijs van den Berg<p> Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>) </p> </div></td> </tr></table> <hr> <div class="spirit-nav"> <a accesskey="p" href="iteration_pol.html"><img src="../../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../pol_ref.html"><img src="../../../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../../index.html"><img src="../../../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="namespace_pol.html"><img src="../../../../../../../../doc/src/images/next.png" alt="Next"></a> </div> </body> </html>