3 <meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
4 <title>Policies Have Sensible Defaults</title>
5 <link rel="stylesheet" href="../../math.css" type="text/css">
6 <meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
7 <link rel="home" href="../../index.html" title="Math Toolkit 2.11.0">
8 <link rel="up" href="../pol_tutorial.html" title="Policy Tutorial">
9 <link rel="prev" href="what_is_a_policy.html" title="So Just What is a Policy Anyway?">
10 <link rel="next" href="policy_usage.html" title="So How are Policies Used Anyway?">
12 <body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
13 <table cellpadding="2" width="100%"><tr>
14 <td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../boost.png"></td>
15 <td align="center"><a href="../../../../../../index.html">Home</a></td>
16 <td align="center"><a href="../../../../../../libs/libraries.htm">Libraries</a></td>
17 <td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
18 <td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
19 <td align="center"><a href="../../../../../../more/index.htm">More</a></td>
22 <div class="spirit-nav">
23 <a accesskey="p" href="what_is_a_policy.html"><img src="../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../pol_tutorial.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="policy_usage.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a>
26 <div class="titlepage"><div><div><h3 class="title">
27 <a name="math_toolkit.pol_tutorial.policy_tut_defaults"></a><a class="link" href="policy_tut_defaults.html" title="Policies Have Sensible Defaults">Policies
28 Have Sensible Defaults</a>
29 </h3></div></div></div>
31 Most of the time you can just ignore the policy framework.
34 <span class="emphasis"><em>*The defaults for the various policies are as follows, if these
35 work OK for you then you can stop reading now!</em></span>
37 <div class="variablelist">
38 <p class="title"><b></b></p>
39 <dl class="variablelist">
40 <dt><span class="term">Domain Error</span></dt>
42 Throws a <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">domain_error</span></code> exception.
44 <dt><span class="term">Pole Error</span></dt>
46 Occurs when a function is evaluated at a pole: throws a <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">domain_error</span></code> exception.
48 <dt><span class="term">Overflow Error</span></dt>
50 Throws a <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">overflow_error</span></code> exception.
52 <dt><span class="term">Underflow</span></dt>
54 Ignores the underflow, and returns zero.
56 <dt><span class="term">Denormalised Result</span></dt>
58 Ignores the fact that the result is denormalised, and returns it.
60 <dt><span class="term">Rounding Error</span></dt>
62 Throws a <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">math</span><span class="special">::</span><span class="identifier">rounding_error</span></code> exception.
64 <dt><span class="term">Internal Evaluation Error</span></dt>
66 Throws a <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">math</span><span class="special">::</span><span class="identifier">evaluation_error</span></code> exception.
68 <dt><span class="term">Indeterminate Result Error</span></dt>
70 Returns a result that depends on the function where the error occurred.
72 <dt><span class="term">Promotion of float to double</span></dt>
74 Does occur by default - gives full float precision results.
76 <dt><span class="term">Promotion of double to long double</span></dt>
78 Does occur by default if long double offers more precision than double.
80 <dt><span class="term">Precision of Approximation Used</span></dt>
82 By default uses an approximation that will result in the lowest level
83 of error for the type of the result.
85 <dt><span class="term">Behaviour of Discrete Quantiles</span></dt>
88 The quantile function will by default return an integer result that
89 has been <span class="emphasis"><em>rounded outwards</em></span>. That is to say lower
90 quantiles (where the probability is less than 0.5) are rounded downward,
91 and upper quantiles (where the probability is greater than 0.5) are
92 rounded upwards. This behaviour ensures that if an X% quantile is requested,
93 then <span class="emphasis"><em>at least</em></span> the requested coverage will be present
94 in the central region, and <span class="emphasis"><em>no more than</em></span> the requested
95 coverage will be present in the tails.
98 This behaviour can be changed so that the quantile functions are rounded
99 differently, or even return a real-valued result using <a class="link" href="../pol_overview.html" title="Policy Overview">Policies</a>.
100 It is strongly recommended that you read the tutorial <a class="link" href="understand_dis_quant.html" title="Understanding Quantiles of Discrete Distributions">Understanding
101 Quantiles of Discrete Distributions</a> before using the quantile
102 function on a discrete distribution. The <a class="link" href="../pol_ref/discrete_quant_ref.html" title="Discrete Quantile Policies">reference
103 docs</a> describe how to change the rounding policy for these distributions.
109 What's more, if you define your own policy type, then it automatically inherits
110 the defaults for any policies not explicitly set, so given:
112 <pre class="programlisting"><span class="keyword">using</span> <span class="keyword">namespace</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">math</span><span class="special">::</span><span class="identifier">policies</span><span class="special">;</span>
113 <span class="comment">//</span>
114 <span class="comment">// Define a policy that sets ::errno on overflow, and does</span>
115 <span class="comment">// not promote double to long double internally:</span>
117 <span class="keyword">typedef</span> <span class="identifier">policy</span>
118 <span class="special"><</span>
119 <span class="identifier">domain_error</span><span class="special"><</span><span class="identifier">errno_on_error</span><span class="special">>,</span>
120 <span class="identifier">promote_double</span><span class="special"><</span><span class="keyword">false</span><span class="special">></span>
121 <span class="special">></span> <span class="identifier">my_policy</span><span class="special">;</span>
124 then <code class="computeroutput"><span class="identifier">my_policy</span></code> defines a
125 policy where only the overflow error handling and <code class="computeroutput"><span class="keyword">double</span></code>-promotion
126 policies differ from the defaults.
129 We can also add a desired precision, for example, 9 bits or 3 decimal digits,
130 to an error-handling policy, usually to trade precision for speed:
132 <pre class="programlisting"><span class="keyword">typedef</span> <span class="identifier">policy</span><span class="special"><</span><span class="identifier">domain_error</span><span class="special"><</span><span class="identifier">errno_on_error</span><span class="special">>,</span> <span class="identifier">digit2</span><span class="special"><</span><span class="number">9</span><span class="special">></span> <span class="special">></span> <span class="identifier">my_policy</span><span class="special">;</span>
135 Or if you want to further modify an existing user policy, use <code class="computeroutput"><span class="identifier">normalise</span></code>:
137 <pre class="programlisting"><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">policies</span><span class="special">::</span><span class="identifier">normalise</span><span class="special">;</span>
139 <span class="keyword">typedef</span> <span class="identifier">normalise</span><span class="special"><</span><span class="identifier">my_policy</span><span class="special">,</span> <span class="identifier">digits2</span><span class="special"><</span><span class="number">9</span><span class="special">>>::</span><span class="identifier">type</span> <span class="identifier">my_policy_9</span><span class="special">;</span> <span class="comment">// errno on error, and limited precision.</span>
142 <table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
143 <td align="left"></td>
144 <td align="right"><div class="copyright-footer">Copyright © 2006-2019 Nikhar
145 Agrawal, Anton Bikineev, Paul A. Bristow, Marco Guazzone, Christopher Kormanyos,
146 Hubert Holin, Bruno Lalande, John Maddock, Jeremy Murphy, Matthew Pulver, Johan
147 Råde, Gautam Sewani, Benjamin Sobotta, Nicholas Thompson, Thijs van den Berg,
148 Daryle Walker and Xiaogang Zhang<p>
149 Distributed under the Boost Software License, Version 1.0. (See accompanying
150 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>)
155 <div class="spirit-nav">
156 <a accesskey="p" href="what_is_a_policy.html"><img src="../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../pol_tutorial.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="policy_usage.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a>