3 <meta http-equiv=
"Content-Type" content=
"text/html; charset=US-ASCII">
4 <title>Internal Floating-point Promotion 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=
"error_handling_policies.html" title=
"Error Handling Policies">
10 <link rel=
"next" href=
"assert_undefined.html" title=
"Mathematically Undefined Function 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=
"error_handling_policies.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=
"assert_undefined.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.internal_promotion"></a><a class=
"link" href=
"internal_promotion.html" title=
"Internal Floating-point Promotion Policies">Internal Floating-point
28 Promotion Policies
</a>
29 </h3></div></div></div>
31 Normally when evaluating a function at say
<code class=
"computeroutput"><span class=
"keyword">float
</span></code>
32 precision, maximal accuracy is assured by conducting the calculation at
33 <code class=
"computeroutput"><span class=
"keyword">double
</span></code> precision internally,
34 and then rounding the result. There are two policies that control whether
35 internal promotion to a higher precision floating-point type takes place,
38 <div class=
"informaltable"><table class=
"table">
59 <code class=
"computeroutput"><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">promote_float
</span><span class=
"special"><</span><span class=
"identifier">B
</span><span class=
"special">></span></code>
64 Indicates whether
<code class=
"computeroutput"><span class=
"keyword">float
</span></code>
65 arguments should be promoted to
<code class=
"computeroutput"><span class=
"keyword">double
</span></code>
66 precision internally: defaults to
<code class=
"computeroutput"><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">promote_float
</span><span class=
"special"><</span><span class=
"keyword">true
</span><span class=
"special">></span></code>
73 <code class=
"computeroutput"><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">promote_double
</span><span class=
"special"><</span><span class=
"identifier">B
</span><span class=
"special">></span></code>
78 Indicates whether
<code class=
"computeroutput"><span class=
"keyword">double
</span></code>
79 arguments should be promoted to
<code class=
"computeroutput"><span class=
"keyword">long
</span>
80 <span class=
"keyword">double
</span></code> precision internally:
81 defaults to
<code class=
"computeroutput"><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">promote_double
</span><span class=
"special"><</span><span class=
"keyword">true
</span><span class=
"special">></span></code>
88 <a name=
"math_toolkit.pol_ref.internal_promotion.h0"></a>
89 <span class=
"phrase"><a name=
"math_toolkit.pol_ref.internal_promotion.examples"></a></span><a class=
"link" href=
"internal_promotion.html#math_toolkit.pol_ref.internal_promotion.examples">Examples
</a>
92 Suppose we want
<code class=
"computeroutput"><span class=
"identifier">tgamma
</span></code> to
93 be evaluated without internal promotion to
<code class=
"computeroutput"><span class=
"keyword">long
</span>
94 <span class=
"keyword">double
</span></code>, then we could use:
96 <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>
98 <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>
99 <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>
101 <span class=
"comment">// Define a new policy *not* internally promoting RealType to double:
</span>
102 <span class=
"keyword">typedef
</span> <span class=
"identifier">policy
</span><span class=
"special"><</span>
103 <span class=
"identifier">promote_double
</span><span class=
"special"><</span><span class=
"keyword">false
</span><span class=
"special">></span>
104 <span class=
"special">></span> <span class=
"identifier">my_policy
</span><span class=
"special">;
</span>
106 <span class=
"comment">// Call the function, applying the new policy:
</span>
107 <span class=
"keyword">double
</span> <span class=
"identifier">t1
</span> <span class=
"special">=
</span> <span class=
"identifier">tgamma
</span><span class=
"special">(
</span><span class=
"identifier">some_value
</span><span class=
"special">,
</span> <span class=
"identifier">my_policy
</span><span class=
"special">());
</span>
109 <span class=
"comment">// Alternatively we could use helper function make_policy,
</span>
110 <span class=
"comment">// and concisely define everything at the call site:
</span>
111 <span class=
"keyword">double
</span> <span class=
"identifier">t2
</span> <span class=
"special">=
</span> <span class=
"identifier">tgamma
</span><span class=
"special">(
</span><span class=
"identifier">some_value
</span><span class=
"special">,
</span> <span class=
"identifier">make_policy
</span><span class=
"special">(
</span><span class=
"identifier">promote_double
</span><span class=
"special"><</span><span class=
"keyword">false
</span><span class=
"special">>()));
</span>
114 Alternatively, suppose we want a distribution to perform calculations without
115 promoting
<code class=
"computeroutput"><span class=
"keyword">float
</span></code> to
<code class=
"computeroutput"><span class=
"keyword">double
</span></code>, then we could use:
117 <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>
118 <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>
120 <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>
122 <span class=
"comment">// Define a policy:
</span>
123 <span class=
"keyword">typedef
</span> <span class=
"identifier">policy
</span><span class=
"special"><</span>
124 <span class=
"identifier">promote_float
</span><span class=
"special"><</span><span class=
"keyword">false
</span><span class=
"special">></span>
125 <span class=
"special">></span> <span class=
"identifier">my_policy
</span><span class=
"special">;
</span>
127 <span class=
"comment">// Define the new normal distribution using my_policy:
</span>
128 <span class=
"keyword">typedef
</span> <span class=
"identifier">normal_distribution
</span><span class=
"special"><</span><span class=
"keyword">float
</span><span class=
"special">,
</span> <span class=
"identifier">my_policy
</span><span class=
"special">></span> <span class=
"identifier">my_norm
</span><span class=
"special">;
</span>
130 <span class=
"comment">// Get a quantile:
</span>
131 <span class=
"keyword">float
</span> <span class=
"identifier">q
</span> <span class=
"special">=
</span> <span class=
"identifier">quantile
</span><span class=
"special">(
</span><span class=
"identifier">my_norm
</span><span class=
"special">(),
</span> <span class=
"number">0.05f
</span><span class=
"special">);
</span>
134 <table xmlns:
rev=
"http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width=
"100%"><tr>
135 <td align=
"left"></td>
136 <td align=
"right"><div class=
"copyright-footer">Copyright
© 2006-
2010,
2012-
2014 Nikhar Agrawal,
137 Anton Bikineev, Paul A. Bristow, Marco Guazzone, Christopher Kormanyos, Hubert
138 Holin, Bruno Lalande, John Maddock, Jeremy Murphy, Johan R
åde, Gautam Sewani,
139 Benjamin Sobotta, Thijs van den Berg, Daryle Walker and Xiaogang Zhang
<p>
140 Distributed under the Boost Software License, Version
1.0. (See accompanying
141 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>)
146 <div class=
"spirit-nav">
147 <a accesskey=
"p" href=
"error_handling_policies.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=
"assert_undefined.html"><img src=
"../../../../../../doc/src/images/next.png" alt=
"Next"></a>