3 <meta http-equiv=
"Content-Type" content=
"text/html; charset=US-ASCII">
4 <title>float128
</title>
5 <link rel=
"stylesheet" href=
"../../../../../../../doc/src/boostbook.css" type=
"text/css">
6 <meta name=
"generator" content=
"DocBook XSL Stylesheets V1.77.1">
7 <link rel=
"home" href=
"../../../index.html" title=
"Chapter 1. Boost.Multiprecision">
8 <link rel=
"up" href=
"../floats.html" title=
"floating-point Numbers">
9 <link rel=
"prev" href=
"mpfr_float.html" title=
"mpfr_float">
10 <link rel=
"next" href=
"fp_eg.html" title=
"Examples">
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=
"mpfr_float.html"><img src=
"../../../../../../../doc/src/images/prev.png" alt=
"Prev"></a><a accesskey=
"u" href=
"../floats.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=
"fp_eg.html"><img src=
"../../../../../../../doc/src/images/next.png" alt=
"Next"></a>
26 <div class=
"titlepage"><div><div><h4 class=
"title">
27 <a name=
"boost_multiprecision.tut.floats.float128"></a><a class=
"link" href=
"float128.html" title=
"float128">float128
</a>
28 </h4></div></div></div>
30 <code class=
"computeroutput"><span class=
"preprocessor">#include
</span> <span class=
"special"><</span><span class=
"identifier">boost
</span><span class=
"special">/
</span><span class=
"identifier">multiprecision
</span><span class=
"special">/
</span><span class=
"identifier">float128
</span><span class=
"special">.
</span><span class=
"identifier">hpp
</span><span class=
"special">></span></code>
32 <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">multiprecision
</span><span class=
"special">{
</span>
34 <span class=
"keyword">class
</span> <span class=
"identifier">float128_backend
</span><span class=
"special">;
</span>
36 <span class=
"keyword">typedef
</span> <span class=
"identifier">number
</span><span class=
"special"><</span><span class=
"identifier">float128_backend
</span><span class=
"special">,
</span> <span class=
"identifier">et_off
</span><span class=
"special">></span> <span class=
"identifier">float128
</span><span class=
"special">;
</span>
38 <span class=
"special">}}
</span> <span class=
"comment">// namespaces
</span>
41 The
<code class=
"computeroutput"><span class=
"identifier">float128
</span></code> number type
42 is a very thin wrapper around GCC's
<code class=
"computeroutput"><a class=
"link" href=
"float128.html" title=
"float128">float128
</a></code>
43 or Intel's
<code class=
"computeroutput"><span class=
"identifier">_Quad
</span></code> data types
44 and provides an real-number type that is a drop-in replacement for the
45 native C++ floating-point types, but with a
113 bit mantissa, and compatible
46 with FORTRAN's
128-bit QUAD real.
49 All the usual standard library and
<code class=
"computeroutput"><span class=
"identifier">numeric_limits
</span></code>
50 support are available, performance should be equivalent to the underlying
51 native types: for example the LINPACK benchmarks for GCC's
<code class=
"computeroutput"><a class=
"link" href=
"float128.html" title=
"float128">float128
</a></code>
52 and
<code class=
"computeroutput"><span class=
"identifier">boost
</span><span class=
"special">::
</span><span class=
"identifier">multiprecision
</span><span class=
"special">::
</span><span class=
"identifier">float128
</span></code> both achieved
5.6 MFLOPS
<a href=
"#ftn.boost_multiprecision.tut.floats.float128.f0" class=
"footnote"><sup class=
"footnote"><a name=
"boost_multiprecision.tut.floats.float128.f0"></a>[
3]
</sup></a>.
55 As well as the usual conversions from arithmetic and string types, instances
56 of
<code class=
"computeroutput"><span class=
"identifier">float128
</span></code> are copy constructible
57 and assignable from GCC's
<code class=
"computeroutput"><a class=
"link" href=
"float128.html" title=
"float128">float128
</a></code>
58 and Intel's
<code class=
"computeroutput"><span class=
"identifier">_Quad
</span></code> data
62 It's also possible to access the underlying
<code class=
"computeroutput"><a class=
"link" href=
"float128.html" title=
"float128">float128
</a></code>
63 or
<code class=
"computeroutput"><span class=
"identifier">_Quad
</span></code> type via the
64 <code class=
"computeroutput"><span class=
"identifier">data
</span><span class=
"special">()
</span></code>
65 member function of
<code class=
"computeroutput"><span class=
"identifier">float128_backend
</span></code>.
68 Things you should know when using this type:
70 <div class=
"itemizedlist"><ul class=
"itemizedlist" style=
"list-style-type: disc; ">
72 Default constructed
<code class=
"computeroutput"><span class=
"identifier">float128
</span></code>s
76 This backend supports rvalue-references and is move-aware, making instantiations
77 of
<code class=
"computeroutput"><span class=
"identifier">number
</span></code> on this backend
81 It is not possible to round-trip objects of this type to and from a
82 string and get back exactly the same value when compiled with Intel's
83 C++ compiler and using
<code class=
"computeroutput"><span class=
"identifier">_Quad
</span></code>
84 as the underlying type: this is a current limitation of our code. Round
85 tripping when using
<code class=
"computeroutput"><a class=
"link" href=
"float128.html" title=
"float128">float128
</a></code>
86 as the underlying type is possible (both for GCC and Intel).
89 Conversion from a string results in a
<code class=
"computeroutput"><span class=
"identifier">std
</span><span class=
"special">::
</span><span class=
"identifier">runtime_error
</span></code>
90 being thrown if the string can not be interpreted as a valid floating-point
94 Division by zero results in an infinity being produced.
97 Type
<code class=
"computeroutput"><span class=
"identifier">float128
</span></code> can be
98 used as a literal type (constexpr support).
100 <li class=
"listitem">
101 When using the Intel compiler, the underlying type defaults to
<code class=
"computeroutput"><a class=
"link" href=
"float128.html" title=
"float128">float128
</a></code>
102 if it's available and
<code class=
"computeroutput"><span class=
"identifier">_Quad
</span></code>
103 if not. You can override the default by defining either
<code class=
"computeroutput"><span class=
"identifier">BOOST_MP_USE_FLOAT128
</span></code> or
<code class=
"computeroutput"><span class=
"identifier">BOOST_MP_USE_QUAD
</span></code>.
105 <li class=
"listitem">
106 When the underlying type is Intel's
<code class=
"computeroutput"><span class=
"identifier">_Quad
</span></code>
107 type, the code must be compiled with the compiler option
<code class=
"computeroutput"><span class=
"special">-
</span><span class=
"identifier">Qoption
</span><span class=
"special">,
</span><span class=
"identifier">cpp
</span><span class=
"special">,--
</span><span class=
"identifier">extended_float_type
</span></code>.
111 <a name=
"boost_multiprecision.tut.floats.float128.h0"></a>
112 <span class=
"phrase"><a name=
"boost_multiprecision.tut.floats.float128.float128_example"></a></span><a class=
"link" href=
"float128.html#boost_multiprecision.tut.floats.float128.float128_example">float128
115 <pre class=
"programlisting"><span class=
"preprocessor">#include
</span> <span class=
"special"><</span><span class=
"identifier">boost
</span><span class=
"special">/
</span><span class=
"identifier">multiprecision
</span><span class=
"special">/
</span><span class=
"identifier">float128
</span><span class=
"special">.
</span><span class=
"identifier">hpp
</span><span class=
"special">></span>
116 <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>
117 <span class=
"preprocessor">#include
</span> <span class=
"special"><</span><span class=
"identifier">iostream
</span><span class=
"special">></span>
119 <span class=
"keyword">int
</span> <span class=
"identifier">main
</span><span class=
"special">()
</span>
120 <span class=
"special">{
</span>
121 <span class=
"keyword">using
</span> <span class=
"keyword">namespace
</span> <span class=
"identifier">boost
</span><span class=
"special">::
</span><span class=
"identifier">multiprecision
</span><span class=
"special">;
</span>
123 <span class=
"comment">// Operations at
128-bit precision and full numeric_limits support:
</span>
124 <span class=
"identifier">float128
</span> <span class=
"identifier">b
</span> <span class=
"special">=
</span> <span class=
"number">2</span><span class=
"special">;
</span>
125 <span class=
"comment">// There are
113-bits of precision:
</span>
126 <span class=
"identifier">std
</span><span class=
"special">::
</span><span class=
"identifier">cout
</span> <span class=
"special"><<</span> <span class=
"identifier">std
</span><span class=
"special">::
</span><span class=
"identifier">numeric_limits
</span><span class=
"special"><</span><span class=
"identifier">float128
</span><span class=
"special">>::
</span><span class=
"identifier">digits
</span> <span class=
"special"><<</span> <span class=
"identifier">std
</span><span class=
"special">::
</span><span class=
"identifier">endl
</span><span class=
"special">;
</span>
127 <span class=
"comment">// Or
34 decimal places:
</span>
128 <span class=
"identifier">std
</span><span class=
"special">::
</span><span class=
"identifier">cout
</span> <span class=
"special"><<</span> <span class=
"identifier">std
</span><span class=
"special">::
</span><span class=
"identifier">numeric_limits
</span><span class=
"special"><</span><span class=
"identifier">float128
</span><span class=
"special">>::
</span><span class=
"identifier">digits10
</span> <span class=
"special"><<</span> <span class=
"identifier">std
</span><span class=
"special">::
</span><span class=
"identifier">endl
</span><span class=
"special">;
</span>
129 <span class=
"comment">// We can use any C++ std lib function, lets print all the digits as well:
</span>
130 <span class=
"identifier">std
</span><span class=
"special">::
</span><span class=
"identifier">cout
</span> <span class=
"special"><<</span> <span class=
"identifier">std
</span><span class=
"special">::
</span><span class=
"identifier">setprecision
</span><span class=
"special">(
</span><span class=
"identifier">std
</span><span class=
"special">::
</span><span class=
"identifier">numeric_limits
</span><span class=
"special"><</span><span class=
"identifier">float128
</span><span class=
"special">>::
</span><span class=
"identifier">max_digits10
</span><span class=
"special">)
</span>
131 <span class=
"special"><<</span> <span class=
"identifier">log
</span><span class=
"special">(
</span><span class=
"identifier">b
</span><span class=
"special">)
</span> <span class=
"special"><<</span> <span class=
"identifier">std
</span><span class=
"special">::
</span><span class=
"identifier">endl
</span><span class=
"special">;
</span> <span class=
"comment">// print log(
2) =
0.693147180559945309417232121458176575</span>
132 <span class=
"comment">// We can also use any function from Boost.Math:
</span>
133 <span class=
"identifier">std
</span><span class=
"special">::
</span><span class=
"identifier">cout
</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">tgamma
</span><span class=
"special">(
</span><span class=
"identifier">b
</span><span class=
"special">)
</span> <span class=
"special"><<</span> <span class=
"identifier">std
</span><span class=
"special">::
</span><span class=
"identifier">endl
</span><span class=
"special">;
</span>
134 <span class=
"comment">// And since we have an extended exponent range we can generate some really large
</span>
135 <span class=
"comment">// numbers here (
4.02387260077093773543702433923004111e+2564):
</span>
136 <span class=
"identifier">std
</span><span class=
"special">::
</span><span class=
"identifier">cout
</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">tgamma
</span><span class=
"special">(
</span><span class=
"identifier">float128
</span><span class=
"special">(
</span><span class=
"number">1000</span><span class=
"special">))
</span> <span class=
"special"><<</span> <span class=
"identifier">std
</span><span class=
"special">::
</span><span class=
"identifier">endl
</span><span class=
"special">;
</span>
137 <span class=
"comment">//
</span>
138 <span class=
"comment">// We can declare constants using GCC or Intel's native types, and the Q suffix,
</span>
139 <span class=
"comment">// these can be declared constexpr if required:
</span>
141 <span class=
"keyword">constexpr
</span> <span class=
"identifier">float128
</span> <span class=
"identifier">pi
</span> <span class=
"special">=
</span> <span class=
"number">3.1415926535897932384626433832795028841971693993751058</span><span class=
"identifier">Q
</span><span class=
"special">;
</span>
143 <span class=
"keyword">return
</span> <span class=
"number">0</span><span class=
"special">;
</span>
144 <span class=
"special">}
</span>
146 <div class=
"footnotes">
147 <br><hr style=
"width:100; align:left;">
148 <div id=
"ftn.boost_multiprecision.tut.floats.float128.f0" class=
"footnote"><p><a href=
"#boost_multiprecision.tut.floats.float128.f0" class=
"para"><sup class=
"para">[
3]
</sup></a>
149 On
64-bit Ubuntu
11.10, GCC-
4.8.0, Intel Core
2 Duo T5800.
153 <table xmlns:
rev=
"http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width=
"100%"><tr>
154 <td align=
"left"></td>
155 <td align=
"right"><div class=
"copyright-footer">Copyright
© 2002-
2013 John Maddock and Christopher Kormanyos
<p>
156 Distributed under the Boost Software License, Version
1.0. (See accompanying
157 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>)
162 <div class=
"spirit-nav">
163 <a accesskey=
"p" href=
"mpfr_float.html"><img src=
"../../../../../../../doc/src/images/prev.png" alt=
"Prev"></a><a accesskey=
"u" href=
"../floats.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=
"fp_eg.html"><img src=
"../../../../../../../doc/src/images/next.png" alt=
"Next"></a>