]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | <html> |
2 | <head> | |
3 | <meta http-equiv="Content-Type" content="text/html; charset=US-ASCII"> | |
4 | <title>Implementation of Float128 type</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="../cstdfloat.html" title="Chapter 3. Specified-width floating-point typedefs"> | |
9 | <link rel="prev" href="float128_hints.html" title="Hints on using float128 (and __float128)"> | |
10 | <link rel="next" href="float128/overloading.html" title="Overloading template functions with float128_t"> | |
11 | </head> | |
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> | |
20 | </tr></table> | |
21 | <hr> | |
22 | <div class="spirit-nav"> | |
23 | <a accesskey="p" href="float128_hints.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../cstdfloat.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="float128/overloading.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a> | |
24 | </div> | |
25 | <div class="section"> | |
26 | <div class="titlepage"><div><div><h2 class="title" style="clear: both"> | |
27 | <a name="math_toolkit.float128"></a><a class="link" href="float128.html" title="Implementation of Float128 type">Implementation of Float128 type</a> | |
28 | </h2></div></div></div> | |
29 | <div class="toc"><dl> | |
30 | <dt><span class="section"><a href="float128/overloading.html">Overloading template | |
31 | functions with float128_t</a></span></dt> | |
32 | <dt><span class="section"><a href="float128/exp_function.html">Exponential function</a></span></dt> | |
33 | <dt><span class="section"><a href="float128/typeinfo.html"><code class="computeroutput"><span class="identifier">typeinfo</span></code></a></span></dt> | |
34 | </dl></div> | |
35 | <p> | |
36 | Since few compilers implement a true 128-bit floating-point, and language features | |
37 | like the suffix Q (which may need an option <code class="computeroutput"><span class="special">-</span><span class="identifier">fext</span><span class="special">-</span><span class="identifier">numeric</span><span class="special">-</span><span class="identifier">literals</span></code> | |
38 | to enable), and C++ Standard library functions are as-yet missing or incomplete | |
39 | in C++11, this Boost.Math implementation wraps <code class="computeroutput"><span class="identifier">__float128</span></code> | |
40 | provided by the GCC compiler <a href="https://gcc.gnu.org/onlinedocs/gcc/Floating-Types.html" target="_top">GCC | |
41 | floating-point types</a> or the <code class="computeroutput"><span class="identifier">_Quad</span></code> | |
42 | type provided by the Intel compiler. | |
43 | </p> | |
44 | <p> | |
45 | This is provided to in order to demonstrate, and users to evaluate, the feasibility | |
46 | and benefits of higher-precision floating-point, especially to allow use of | |
47 | the full <cmath> and Boost.Math library of functions and distributions | |
48 | at high precision. | |
49 | </p> | |
50 | <p> | |
51 | (It is also possible to use Boost.Math with Boost.Multiprecision decimal and | |
52 | binary, but since these are entirely software solutions, allowing much higher | |
53 | precision or arbitrary precision, they are likely to be slower). | |
54 | </p> | |
55 | <p> | |
56 | We also provide (we believe full) support for <code class="computeroutput"><span class="special"><</span><span class="identifier">limits</span><span class="special">>,</span> <span class="special"><</span><span class="identifier">cmath</span><span class="special">></span></code>, I/O stream operations in <code class="computeroutput"><span class="special"><</span><span class="identifier">iostream</span><span class="special">></span></code>, and <code class="computeroutput"><span class="special"><</span><span class="identifier">complex</span><span class="special">></span></code>. | |
57 | </p> | |
58 | <p> | |
59 | As a prototype for a future C++ standard, we place all these in <code class="computeroutput"><span class="keyword">namespace</span> <span class="identifier">std</span></code>. | |
60 | This contravenes the existing C++ standard of course, so selecting any compiler | |
61 | that promises to check conformance will fail. | |
62 | </p> | |
63 | <div class="tip"><table border="0" summary="Tip"> | |
64 | <tr> | |
65 | <td rowspan="2" align="center" valign="top" width="25"><img alt="[Tip]" src="../../../../../doc/src/images/tip.png"></td> | |
66 | <th align="left">Tip</th> | |
67 | </tr> | |
68 | <tr><td align="left" valign="top"><p> | |
69 | For GCC, compile with <code class="computeroutput"><span class="special">-</span><span class="identifier">std</span><span class="special">=</span><span class="identifier">gnu</span><span class="special">++</span><span class="number">11</span></code> or <code class="computeroutput"><span class="special">-</span><span class="identifier">std</span><span class="special">=</span><span class="identifier">gnu</span><span class="special">++</span><span class="number">03</span></code> and do | |
70 | not use <code class="computeroutput"><span class="special">-</span><span class="identifier">std</span><span class="special">=</span><span class="identifier">stdc</span><span class="special">++</span><span class="number">11</span></code> or any 'strict' options, as these turn off | |
71 | full support for <code class="computeroutput"><span class="identifier">__float128</span></code>. | |
72 | These requirements also apply to the Intel compiler on Linux, for Intel on | |
73 | Windows you need to compile with <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> <span class="special">-</span><span class="identifier">DBOOST_MATH_USE_FLOAT128</span></code> in order to activate | |
74 | 128-bit floating point support. | |
75 | </p></td></tr> | |
76 | </table></div> | |
77 | <p> | |
78 | The <code class="computeroutput"><span class="identifier">__float128</span></code> type is provided | |
79 | by the <a href="http://gcc.gnu.org/onlinedocs/libquadmath/" target="_top">libquadmath | |
80 | library</a> on GCC or by Intel's FORTRAN library with Intel C++. THey also | |
81 | provide a full set of <code class="computeroutput"><span class="special"><</span><span class="identifier">cmath</span><span class="special">></span></code> functions in <code class="computeroutput"><span class="keyword">namespace</span> | |
82 | <span class="identifier">std</span></code>. | |
83 | </p> | |
84 | <h5> | |
85 | <a name="math_toolkit.float128.h0"></a> | |
86 | <span class="phrase"><a name="math_toolkit.float128.using_c_float128_quadmath_type"></a></span><a class="link" href="float128.html#math_toolkit.float128.using_c_float128_quadmath_type">Using | |
87 | C __float128 quadmath type</a> | |
88 | </h5> | |
89 | <p> | |
90 | [quadmath_snprintf_1] | |
91 | </p> | |
92 | <p> | |
93 | The source code is at <a href="../../../example/quadmath_snprintf.c" target="_top">quadmath_snprintf.c</a>. | |
94 | </p> | |
95 | <h5> | |
96 | <a name="math_toolkit.float128.h1"></a> | |
97 | <span class="phrase"><a name="math_toolkit.float128.using_c_float128_quadmath_type0"></a></span><a class="link" href="float128.html#math_toolkit.float128.using_c_float128_quadmath_type0">Using | |
98 | C++ <code class="computeroutput"><span class="identifier">float128</span></code> quadmath type</a> | |
99 | </h5> | |
100 | <p> | |
101 | For C++ programs, you will want to use the C++ type <code class="computeroutput"><span class="identifier">float128</span></code> | |
102 | </p> | |
103 | <p> | |
104 | See example at <a href="../../../example/cstdfloat_example.cpp" target="_top">cstdfloat_example.cpp</a>. | |
105 | </p> | |
106 | <p> | |
107 | A typical invocation of the compiler is | |
108 | </p> | |
109 | <pre class="programlisting"><span class="identifier">g</span><span class="special">++</span> <span class="special">-</span><span class="identifier">O3</span> <span class="special">-</span><span class="identifier">std</span><span class="special">=</span><span class="identifier">gnu</span><span class="special">++</span><span class="number">11</span> <span class="identifier">test</span><span class="special">.</span><span class="identifier">cpp</span> <span class="special">-</span><span class="identifier">I</span><span class="special">/</span><span class="identifier">c</span><span class="special">/</span><span class="identifier">modular</span><span class="special">-</span><span class="identifier">boost</span> <span class="special">-</span><span class="identifier">lquadmath</span> <span class="special">-</span><span class="identifier">o</span> <span class="identifier">test</span><span class="special">.</span><span class="identifier">exe</span> | |
110 | </pre> | |
111 | <div class="tip"><table border="0" summary="Tip"> | |
112 | <tr> | |
113 | <td rowspan="2" align="center" valign="top" width="25"><img alt="[Tip]" src="../../../../../doc/src/images/tip.png"></td> | |
114 | <th align="left">Tip</th> | |
115 | </tr> | |
116 | <tr><td align="left" valign="top"><p> | |
117 | If you are trying to use the develop branch of Boost.Math, then make <code class="computeroutput"><span class="special">-</span><span class="identifier">I</span><span class="special">/</span><span class="identifier">c</span><span class="special">/</span><span class="identifier">modular</span><span class="special">-</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">libs</span><span class="special">/</span><span class="identifier">math</span><span class="special">/</span><span class="identifier">include</span></code> | |
118 | the <span class="bold"><strong>first</strong></span> include directory. | |
119 | </p></td></tr> | |
120 | </table></div> | |
121 | <pre class="programlisting"><span class="identifier">g</span><span class="special">++</span> <span class="special">-</span><span class="identifier">O3</span> <span class="special">-</span><span class="identifier">std</span><span class="special">=</span><span class="identifier">gnu</span><span class="special">++</span><span class="number">11</span> <span class="identifier">test</span><span class="special">.</span><span class="identifier">cpp</span> <span class="special">-</span><span class="identifier">I</span><span class="special">/</span><span class="identifier">c</span><span class="special">/</span><span class="identifier">modular</span><span class="special">-</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">libs</span><span class="special">/</span><span class="identifier">math</span><span class="special">/</span><span class="identifier">include</span> <span class="special">-</span><span class="identifier">I</span><span class="special">/</span><span class="identifier">c</span><span class="special">/</span><span class="identifier">modular</span><span class="special">-</span><span class="identifier">boost</span> <span class="special">-</span><span class="identifier">lquadmath</span> <span class="special">-</span><span class="identifier">o</span> <span class="identifier">test</span><span class="special">.</span><span class="identifier">exe</span> | |
122 | </pre> | |
123 | <div class="note"><table border="0" summary="Note"> | |
124 | <tr> | |
125 | <td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../../doc/src/images/note.png"></td> | |
126 | <th align="left">Note</th> | |
127 | </tr> | |
128 | <tr><td align="left" valign="top"> | |
129 | <p> | |
130 | So far, the only missing detail that we had noted was in trying to use <code class="computeroutput"><span class="special"><</span><span class="identifier">typeinfo</span><span class="special">></span></code>, for example for <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="keyword">typeid</span><span class="special"><</span><span class="identifier">__float_128</span><span class="special">>.</span><span class="identifier">name</span><span class="special">();</span></code>. | |
131 | </p> | |
132 | <pre class="programlisting"><span class="identifier">Link</span> <span class="identifier">fails</span><span class="special">:</span> <span class="identifier">undefined</span> <span class="identifier">reference</span> <span class="identifier">to</span> <span class="identifier">typeinfo</span> <span class="keyword">for</span> <span class="identifier">__float128</span><span class="special">.</span> | |
133 | </pre> | |
134 | <p> | |
135 | See <a href="http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43622" target="_top">GCC Bug | |
136 | 43622 - no C++ typeinfo for __float128</a>. But this is reported (Marc | |
137 | Glisse 2015-04-04 ) fixed in GCC 5 (and above). | |
138 | </p> | |
139 | <p> | |
140 | For example, with GCC6.1.1 this works as expected to a <span class="bold"><strong>mangled</strong></span> | |
141 | string name, and output (if possible - not always). | |
142 | </p> | |
143 | <pre class="programlisting"><span class="keyword">const</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">type_info</span><span class="special">&</span> <span class="identifier">tifu128</span> <span class="special">=</span> <span class="keyword">typeid</span><span class="special">(</span><span class="identifier">__float128</span><span class="special">);</span> <span class="comment">// OK.</span> | |
144 | <span class="comment">//std::cout << tifu128.name() << std::endl; // On GCC, aborts (because not printable string).</span> | |
145 | <span class="comment">//std::cout << typeid(__float128).name() << std::endl; // Aborts - string name cannot be output.</span> | |
146 | ||
147 | <span class="keyword">const</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">type_info</span><span class="special">&</span> <span class="identifier">tif128</span> <span class="special">=</span> <span class="keyword">typeid</span><span class="special">(</span><span class="identifier">float128</span><span class="special">);</span> <span class="comment">// OK.</span> | |
148 | <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="identifier">tif128</span><span class="special">.</span><span class="identifier">name</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">// OK.</span> | |
149 | <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="keyword">typeid</span><span class="special">(</span><span class="identifier">float128</span><span class="special">).</span><span class="identifier">name</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">// OK.</span> | |
150 | ||
151 | <span class="keyword">const</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">type_info</span><span class="special">&</span> <span class="identifier">tpi</span> <span class="special">=</span> <span class="keyword">typeid</span><span class="special">(</span><span class="identifier">pi1</span><span class="special">);</span> <span class="comment">// OK GCC 6.1.1 (from GCC 5 according to http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43622)</span> | |
152 | <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="identifier">tpi</span><span class="special">.</span><span class="identifier">name</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">// Output mangled name:</span> | |
153 | ||
154 | <span class="comment">// N5boost14multiprecision6numberINS0_8backends16float128_backendELNS0_26expression_template_optionE0EEE</span> | |
155 | </pre> | |
156 | </td></tr> | |
157 | </table></div> | |
158 | </div> | |
159 | <table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr> | |
160 | <td align="left"></td> | |
161 | <td align="right"><div class="copyright-footer">Copyright © 2006-2010, 2012-2014 Nikhar Agrawal, | |
162 | Anton Bikineev, Paul A. Bristow, Marco Guazzone, Christopher Kormanyos, Hubert | |
163 | Holin, Bruno Lalande, John Maddock, Jeremy Murphy, Johan Råde, Gautam Sewani, | |
164 | Benjamin Sobotta, Thijs van den Berg, Daryle Walker and Xiaogang Zhang<p> | |
165 | Distributed under the Boost Software License, Version 1.0. (See accompanying | |
166 | 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>) | |
167 | </p> | |
168 | </div></td> | |
169 | </tr></table> | |
170 | <hr> | |
171 | <div class="spirit-nav"> | |
172 | <a accesskey="p" href="float128_hints.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../cstdfloat.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="float128/overloading.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a> | |
173 | </div> | |
174 | </body> | |
175 | </html> |