3 <meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
5 <link rel="stylesheet" href="../../multiprecision.css" type="text/css">
6 <meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
7 <link rel="home" href="../../index.html" title="Chapter 1. Boost.Multiprecision">
8 <link rel="up" href="../map.html" title="Roadmap">
9 <link rel="prev" href="todo.html" title="TODO">
10 <link rel="next" href="ack.html" title="Acknowledgements">
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="todo.html"><img src="../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../map.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="ack.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a>
26 <div class="titlepage"><div><div><h3 class="title">
27 <a name="boost_multiprecision.map.faq"></a><a class="link" href="faq.html" title="FAQ">FAQ</a>
28 </h3></div></div></div>
29 <div class="variablelist">
30 <p class="title"><b></b></p>
31 <dl class="variablelist">
32 <dt><span class="term">Why do I get compiler errors when passing a <code class="computeroutput"><span class="identifier">number</span></code>
33 to a template function?</span></dt>
35 Most likely you are actually passing an expression template type to
36 the function and template-argument-deduction deduces the "wrong"
37 type. Try casting the arguments involving expressions to the actual
38 number type, or as a last resort turning off expression template support
39 in the number type you are using.
41 <dt><span class="term">When is expression template support a performance gain?</span></dt>
43 As a general rule, expression template support adds a small runtime
44 overhead creating and unpacking the expression templates, but greatly
45 reduces the number of temporaries created. So it's most effective in
46 improving performance when the cost of creating a temporary is high:
47 for example when creating a temporary involves a memory allocation.
48 It is least effective (and may even be a dis-optimisation) when temporaries
49 are cheap: for example if the number type is basically a thin wrapper
50 around a native arithmetic type. In addition, since the library makes
51 extensive use of thin inline wrapper functions, turning on compiler
52 optimization is essential to achieving high performance.
54 <dt><span class="term">Do expression templates reorder operations?</span></dt>
56 Yes they do, sometimes quite radically so, if this is a concern then
57 they should be turned off for the number type you are using.
59 <dt><span class="term">I can't construct my number type from <span class="emphasis"><em>some other type</em></span>,
60 but the docs indicate that the conversion should be allowed, what's up?</span></dt>
62 Some conversions are <span class="emphasis"><em>explicit</em></span>, that includes construction
63 from a string, or constructing from any type that may result in loss
64 of precision (for example constructing an integer type from a float).
66 <dt><span class="term">Why do I get an exception thrown (or the program crash due to an
67 uncaught exception) when using the bitwise operators on a checked <code class="computeroutput"><span class="identifier">cpp_int</span></code>?</span></dt>
69 Bitwise operations on negative values (or indeed any signed integer
70 type) are unspecified by the standard. As a result any attempt to carry
71 out a bitwise operation on a negative checked-integer will result in
72 a <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">range_error</span></code> being thrown.
74 <dt><span class="term">Why do I get compiler errors when trying to use the complement operator?</span></dt>
76 Use of the complement operator on signed types is problematic as the
77 result is unspecified by the standard, and is further complicated by
78 the fact that most extended precision integer types use a sign-magnitude
79 representation rather than the 2's complement one favored by most native
80 integer types. As a result the complement operator is deliberately
81 disabled for checked <code class="computeroutput"><span class="identifier">cpp_int</span></code>'s.
82 Unchecked <code class="computeroutput"><span class="identifier">cpp_int</span></code>'s
83 give the same valued result as a 2's complement type would, but not
86 <dt><span class="term">Why can't I negate an unsigned type?</span></dt>
88 The unary negation operator is deliberately disabled for unsigned integer
89 types as its use would almost always be a programming error.
91 <dt><span class="term">Why doesn't the library use proto?</span></dt>
93 A very early version of the library did use proto, but compile times
94 became too slow for the library to be usable. Since the library only
95 required a tiny fraction of what proto has to offer anyway, a lightweight
96 expression template mechanism was used instead. Compile times are still
99 <dt><span class="term">Why not abstract out addition/multiplication algorithms?</span></dt>
101 This was deemed not to be practical: these algorithms are intimately
102 tied to the actual data representation used.
104 <dt><span class="term">How do I choose between Boost.Multiprecision <code class="computeroutput"><span class="identifier">cpp_bin_50</span></code>
105 and <code class="computeroutput"><span class="identifier">cpp_dec_50</span></code>?</span></dt>
108 Unless you have a specific reason to choose <code class="computeroutput"><span class="identifier">cpp_dec_</span></code>,
109 then the default choice should be <code class="computeroutput"><span class="identifier">cpp_bin_</span></code>,
110 for example using the convenience <code class="computeroutput"><span class="identifier">typedefs</span></code>
111 like <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">multiprecision</span><span class="special">::</span><span class="identifier">cpp_bin_50</span></code> or <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">multiprecision</span><span class="special">::</span><span class="identifier">cpp_bin_100</span></code>.
114 In general, both work well and give the same results and at roughly
115 the same speed with <code class="computeroutput"><span class="identifier">cpp_dec_50</span></code>
119 <code class="computeroutput"><span class="identifier">cpp_dec_</span></code> was developed
120 first paving the way for <code class="computeroutput"><span class="identifier">cpp_bin_</span></code>.
121 <code class="computeroutput"><span class="identifier">cpp_dec_</span></code> has several
122 guard digits and is not rounded at all, using 'brute force' to get
123 the promised number of decimal digits correct, but making it difficult
124 to reason about precision and computational uncertainty, for example
125 see <span class="bold"><strong>https://svn.boost.org/trac10/ticket/12133</strong></span>.
126 It also has a fast but imprecise division operator giving surprising
127 results sometimes, see <span class="bold"><strong>https://svn.boost.org/trac10/ticket/11178</strong></span>.
130 <code class="computeroutput"><span class="identifier">cpp_bin_</span></code> is correctly/exactly
131 rounded making it possible to reason about both the precision and rounding
138 <table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
139 <td align="left"></td>
140 <td align="right"><div class="copyright-footer">Copyright © 2002-2019 John Maddock
141 and Christopher Kormanyos<p>
142 Distributed under the Boost Software License, Version 1.0. (See accompanying
143 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>)
148 <div class="spirit-nav">
149 <a accesskey="p" href="todo.html"><img src="../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../map.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="ack.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a>