1<html> 2<head> 3<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 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.79.1"> 7<link rel="home" href="../index.html" title="Math Toolkit 2.12.0"> 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 class="toc"> 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 The source code is at <a href="https://gcc.gnu.org/onlinedocs/gcc-9.1.0/libquadmath/quadmath_005fsnprintf.html#quadmath_005fsnprintf" target="_top">quadmath_snprintf.c</a>. 91 </p> 92<h5> 93<a name="math_toolkit.float128.h1"></a> 94 <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 95 C++ <code class="computeroutput"><span class="identifier">float128</span></code> quadmath type</a> 96 </h5> 97<p> 98 For C++ programs, you will want to use the C++ type <code class="computeroutput"><span class="identifier">float128</span></code> 99 </p> 100<p> 101 See example at <a href="../../../example/cstdfloat_example.cpp" target="_top">cstdfloat_example.cpp</a>. 102 </p> 103<p> 104 A typical invocation of the compiler is 105 </p> 106<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> 107</pre> 108<div class="tip"><table border="0" summary="Tip"> 109<tr> 110<td rowspan="2" align="center" valign="top" width="25"><img alt="[Tip]" src="../../../../../doc/src/images/tip.png"></td> 111<th align="left">Tip</th> 112</tr> 113<tr><td align="left" valign="top"><p> 114 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> 115 the <span class="bold"><strong>first</strong></span> include directory. 116 </p></td></tr> 117</table></div> 118<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> 119</pre> 120<div class="note"><table border="0" summary="Note"> 121<tr> 122<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../../doc/src/images/note.png"></td> 123<th align="left">Note</th> 124</tr> 125<tr><td align="left" valign="top"> 126<p> 127 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>. 128 </p> 129<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> 130</pre> 131<p> 132 See <a href="http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43622" target="_top">GCC Bug 133 43622 - no C++ typeinfo for __float128</a>. But this is reported (Marc 134 Glisse 2015-04-04 ) fixed in GCC 5 (and above). 135 </p> 136<p> 137 For example, with GCC6.1.1 this works as expected to a <span class="bold"><strong>mangled</strong></span> 138 string name, and output (if possible - not always). 139 </p> 140<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> 141<span class="comment">//std::cout << tifu128.name() << std::endl; // On GCC, aborts (because not printable string).</span> 142<span class="comment">//std::cout << typeid(__float128).name() << std::endl; // Aborts - string name cannot be output.</span> 143 144<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> 145<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> 146<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> 147 148<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> 149<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> 150 151<span class="comment">// N5boost14multiprecision6numberINS0_8backends16float128_backendELNS0_26expression_template_optionE0EEE</span> 152</pre> 153</td></tr> 154</table></div> 155</div> 156<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr> 157<td align="left"></td> 158<td align="right"><div class="copyright-footer">Copyright © 2006-2019 Nikhar 159 Agrawal, Anton Bikineev, Paul A. Bristow, Marco Guazzone, Christopher Kormanyos, 160 Hubert Holin, Bruno Lalande, John Maddock, Jeremy Murphy, Matthew Pulver, Johan 161 Råde, Gautam Sewani, Benjamin Sobotta, Nicholas Thompson, Thijs van den Berg, 162 Daryle Walker and Xiaogang Zhang<p> 163 Distributed under the Boost Software License, Version 1.0. (See accompanying 164 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>) 165 </p> 166</div></td> 167</tr></table> 168<hr> 169<div class="spirit-nav"> 170<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> 171</div> 172</body> 173</html> 174