3 <meta http-equiv=
"Content-Type" content=
"text/html; charset=US-ASCII">
4 <title>Precision Policies
</title>
5 <link rel=
"stylesheet" href=
"../../math.css" type=
"text/css">
6 <meta name=
"generator" content=
"DocBook XSL Stylesheets V1.77.1">
7 <link rel=
"home" href=
"../../index.html" title=
"Math Toolkit 2.5.1">
8 <link rel=
"up" href=
"../pol_ref.html" title=
"Policy Reference">
9 <link rel=
"prev" href=
"discrete_quant_ref.html" title=
"Discrete Quantile Policies">
10 <link rel=
"next" href=
"iteration_pol.html" title=
"Iteration Limits Policies">
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=
"discrete_quant_ref.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=
"iteration_pol.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_ref.precision_pol"></a><a class=
"link" href=
"precision_pol.html" title=
"Precision Policies">Precision Policies
</a>
28 </h3></div></div></div>
30 There are two equivalent policies that effect the
<span class=
"emphasis"><em>working precision
</em></span>
31 used to calculate results, these policies both default to
0 - meaning calculate
32 to the maximum precision available in the type being used - but can be set
33 to other values to cause lower levels of precision to be used. One might
34 want to trade precision for evaluation speed.
36 <pre class=
"programlisting"><span class=
"keyword">namespace
</span> <span class=
"identifier">boost
</span><span class=
"special">{
</span> <span class=
"keyword">namespace
</span> <span class=
"identifier">math
</span><span class=
"special">{
</span> <span class=
"keyword">namespace
</span> <span class=
"identifier">policies
</span><span class=
"special">{
</span>
38 <span class=
"keyword">template
</span> <span class=
"special"><</span><span class=
"keyword">int
</span> <span class=
"identifier">N
</span><span class=
"special">></span>
39 <span class=
"identifier">digits10
</span><span class=
"special">;
</span>
41 <span class=
"keyword">template
</span> <span class=
"special"><</span><span class=
"keyword">int
</span> <span class=
"identifier">N
</span><span class=
"special">></span>
42 <span class=
"identifier">digits2
</span><span class=
"special">;
</span>
44 <span class=
"special">}}}
</span> <span class=
"comment">// namespaces
</span>
47 As you would expect,
<span class=
"emphasis"><em>digits10
</em></span> specifies the number of
48 decimal digits to use, and
<span class=
"emphasis"><em>digits2
</em></span> the number of binary
49 digits. Internally, whichever is used, the precision is always converted
50 to
<span class=
"emphasis"><em>binary digits
</em></span>.
53 These policies are specified at compile-time, because many of the special
54 functions use compile-time-dispatch to select which approximation to use
55 based on the precision requested and the numeric type being used.
58 For example we could calculate
<code class=
"computeroutput"><span class=
"identifier">tgamma
</span></code>
59 to approximately
5 decimal digits using:
61 <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">special_functions
</span><span class=
"special">/
</span><span class=
"identifier">gamma
</span><span class=
"special">.
</span><span class=
"identifier">hpp
</span><span class=
"special">></span>
62 <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">tgamma
</span><span class=
"special">;
</span>
63 <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">policy
</span><span class=
"special">;
</span>
64 <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">digits10
</span><span class=
"special">;
</span>
66 <span class=
"keyword">typedef
</span> <span class=
"identifier">policy
</span><span class=
"special"><</span><span class=
"identifier">digits10
</span><span class=
"special"><</span><span class=
"number">5</span><span class=
"special">></span> <span class=
"special">></span> <span class=
"identifier">my_pol_5
</span><span class=
"special">;
</span> <span class=
"comment">// Define a new, non-default, policy
</span>
67 <span class=
"comment">// to calculate tgamma to accuracy of approximately
5 decimal digits.
</span>
70 Or again using helper function
<code class=
"computeroutput"><span class=
"identifier">make_policy
</span></code>:
72 <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">special_functions
</span><span class=
"special">/
</span><span class=
"identifier">gamma
</span><span class=
"special">.
</span><span class=
"identifier">hpp
</span><span class=
"special">></span>
73 <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">tgamma
</span><span class=
"special">;
</span>
75 <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>
77 <span class=
"keyword">double
</span> <span class=
"identifier">t
</span> <span class=
"special">=
</span> <span class=
"identifier">tgamma
</span><span class=
"special">(
</span><span class=
"number">12</span><span class=
"special">,
</span> <span class=
"identifier">policy
</span><span class=
"special"><</span><span class=
"identifier">digits10
</span><span class=
"special"><</span><span class=
"number">5</span><span class=
"special">></span> <span class=
"special">>());
</span> <span class=
"comment">// Concise make_policy.
</span>
80 And for a quantile of a distribution to approximately
25-bit precision:
82 <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>
83 <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>
85 <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>
87 <span class=
"keyword">const
</span> <span class=
"keyword">int
</span> <span class=
"identifier">bits
</span> <span class=
"special">=
</span> <span class=
"number">25</span><span class=
"special">;
</span> <span class=
"comment">// approximate precision.
</span>
89 <span class=
"keyword">double
</span> <span class=
"identifier">q
</span> <span class=
"special">=
</span> <span class=
"identifier">quantile
</span><span class=
"special">(
</span>
90 <span class=
"identifier">normal_distribution
</span><span class=
"special"><</span><span class=
"keyword">double
</span><span class=
"special">,
</span> <span class=
"identifier">policy
</span><span class=
"special"><</span><span class=
"identifier">digits2
</span><span class=
"special"><</span><span class=
"identifier">bits
</span><span class=
"special">></span> <span class=
"special">></span> <span class=
"special">>(),
</span>
91 <span class=
"number">0.05</span><span class=
"special">);
</span> <span class=
"comment">//
5% quantile.
</span>
94 <table xmlns:
rev=
"http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width=
"100%"><tr>
95 <td align=
"left"></td>
96 <td align=
"right"><div class=
"copyright-footer">Copyright
© 2006-
2010,
2012-
2014 Nikhar Agrawal,
97 Anton Bikineev, Paul A. Bristow, Marco Guazzone, Christopher Kormanyos, Hubert
98 Holin, Bruno Lalande, John Maddock, Jeremy Murphy, Johan R
åde, Gautam Sewani,
99 Benjamin Sobotta, Thijs van den Berg, Daryle Walker and Xiaogang Zhang
<p>
100 Distributed under the Boost Software License, Version
1.0. (See accompanying
101 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>)
106 <div class=
"spirit-nav">
107 <a accesskey=
"p" href=
"discrete_quant_ref.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=
"iteration_pol.html"><img src=
"../../../../../../doc/src/images/next.png" alt=
"Next"></a>