WSJT-X/boost/libs/math/doc/html/math_toolkit/float128.html

176 lines
18 KiB
HTML

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>Implementation of Float128 type</title>
<link rel="stylesheet" href="../math.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="../index.html" title="Math Toolkit 2.5.1">
<link rel="up" href="../cstdfloat.html" title="Chapter&#160;3.&#160;Specified-width floating-point typedefs">
<link rel="prev" href="float128_hints.html" title="Hints on using float128 (and __float128)">
<link rel="next" href="float128/overloading.html" title="Overloading template functions with float128_t">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr>
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../boost.png"></td>
<td align="center"><a href="../../../../../index.html">Home</a></td>
<td align="center"><a href="../../../../../libs/libraries.htm">Libraries</a></td>
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
<td align="center"><a href="../../../../../more/index.htm">More</a></td>
</tr></table>
<hr>
<div class="spirit-nav">
<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>
</div>
<div class="section">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="math_toolkit.float128"></a><a class="link" href="float128.html" title="Implementation of Float128 type">Implementation of Float128 type</a>
</h2></div></div></div>
<div class="toc"><dl class="toc">
<dt><span class="section"><a href="float128/overloading.html">Overloading template
functions with float128_t</a></span></dt>
<dt><span class="section"><a href="float128/exp_function.html">Exponential function</a></span></dt>
<dt><span class="section"><a href="float128/typeinfo.html"><code class="computeroutput"><span class="identifier">typeinfo</span></code></a></span></dt>
</dl></div>
<p>
Since few compilers implement a true 128-bit floating-point, and language features
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>
to enable), and C++ Standard library functions are as-yet missing or incomplete
in C++11, this Boost.Math implementation wraps <code class="computeroutput"><span class="identifier">__float128</span></code>
provided by the GCC compiler <a href="https://gcc.gnu.org/onlinedocs/gcc/Floating-Types.html" target="_top">GCC
floating-point types</a> or the <code class="computeroutput"><span class="identifier">_Quad</span></code>
type provided by the Intel compiler.
</p>
<p>
This is provided to in order to demonstrate, and users to evaluate, the feasibility
and benefits of higher-precision floating-point, especially to allow use of
the full &lt;cmath&gt; and Boost.Math library of functions and distributions
at high precision.
</p>
<p>
(It is also possible to use Boost.Math with Boost.Multiprecision decimal and
binary, but since these are entirely software solutions, allowing much higher
precision or arbitrary precision, they are likely to be slower).
</p>
<p>
We also provide (we believe full) support for <code class="computeroutput"><span class="special">&lt;</span><span class="identifier">limits</span><span class="special">&gt;,</span> <span class="special">&lt;</span><span class="identifier">cmath</span><span class="special">&gt;</span></code>, I/O stream operations in <code class="computeroutput"><span class="special">&lt;</span><span class="identifier">iostream</span><span class="special">&gt;</span></code>, and <code class="computeroutput"><span class="special">&lt;</span><span class="identifier">complex</span><span class="special">&gt;</span></code>.
</p>
<p>
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>.
This contravenes the existing C++ standard of course, so selecting any compiler
that promises to check conformance will fail.
</p>
<div class="tip"><table border="0" summary="Tip">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Tip]" src="../../../../../doc/src/images/tip.png"></td>
<th align="left">Tip</th>
</tr>
<tr><td align="left" valign="top"><p>
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
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
full support for <code class="computeroutput"><span class="identifier">__float128</span></code>.
These requirements also apply to the Intel compiler on Linux, for Intel on
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
128-bit floating point support.
</p></td></tr>
</table></div>
<p>
The <code class="computeroutput"><span class="identifier">__float128</span></code> type is provided
by the <a href="http://gcc.gnu.org/onlinedocs/libquadmath/" target="_top">libquadmath
library</a> on GCC or by Intel's FORTRAN library with Intel C++. THey also
provide a full set of <code class="computeroutput"><span class="special">&lt;</span><span class="identifier">cmath</span><span class="special">&gt;</span></code> functions in <code class="computeroutput"><span class="keyword">namespace</span>
<span class="identifier">std</span></code>.
</p>
<h5>
<a name="math_toolkit.float128.h0"></a>
<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
C __float128 quadmath type</a>
</h5>
<p>
[quadmath_snprintf_1]
</p>
<p>
The source code is at <a href="../../../example/quadmath_snprintf.c" target="_top">quadmath_snprintf.c</a>.
</p>
<h5>
<a name="math_toolkit.float128.h1"></a>
<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
C++ <code class="computeroutput"><span class="identifier">float128</span></code> quadmath type</a>
</h5>
<p>
For C++ programs, you will want to use the C++ type <code class="computeroutput"><span class="identifier">float128</span></code>
</p>
<p>
See example at <a href="../../../example/cstdfloat_example.cpp" target="_top">cstdfloat_example.cpp</a>.
</p>
<p>
A typical invocation of the compiler is
</p>
<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>
</pre>
<div class="tip"><table border="0" summary="Tip">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Tip]" src="../../../../../doc/src/images/tip.png"></td>
<th align="left">Tip</th>
</tr>
<tr><td align="left" valign="top"><p>
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>
the <span class="bold"><strong>first</strong></span> include directory.
</p></td></tr>
</table></div>
<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>
</pre>
<div class="note"><table border="0" summary="Note">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../../doc/src/images/note.png"></td>
<th align="left">Note</th>
</tr>
<tr><td align="left" valign="top">
<p>
So far, the only missing detail that we had noted was in trying to use <code class="computeroutput"><span class="special">&lt;</span><span class="identifier">typeinfo</span><span class="special">&gt;</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">&lt;&lt;</span> <span class="keyword">typeid</span><span class="special">&lt;</span><span class="identifier">__float_128</span><span class="special">&gt;.</span><span class="identifier">name</span><span class="special">();</span></code>.
</p>
<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>
</pre>
<p>
See <a href="http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43622" target="_top">GCC Bug
43622 - no C++ typeinfo for __float128</a>. But this is reported (Marc
Glisse 2015-04-04 ) fixed in GCC 5 (and above).
</p>
<p>
For example, with GCC6.1.1 this works as expected to a <span class="bold"><strong>mangled</strong></span>
string name, and output (if possible - not always).
</p>
<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">&amp;</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>
<span class="comment">//std::cout &lt;&lt; tifu128.name() &lt;&lt; std::endl; // On GCC, aborts (because not printable string).</span>
<span class="comment">//std::cout &lt;&lt; typeid(__float128).name() &lt;&lt; std::endl; // Aborts - string name cannot be output.</span>
<span class="keyword">const</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">type_info</span><span class="special">&amp;</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>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="identifier">tif128</span><span class="special">.</span><span class="identifier">name</span><span class="special">()</span> <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span> <span class="comment">// OK.</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</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">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span> <span class="comment">// OK.</span>
<span class="keyword">const</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">type_info</span><span class="special">&amp;</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>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="identifier">tpi</span><span class="special">.</span><span class="identifier">name</span><span class="special">()</span> <span class="special">&lt;&lt;</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>
<span class="comment">// N5boost14multiprecision6numberINS0_8backends16float128_backendELNS0_26expression_template_optionE0EEE</span>
</pre>
</td></tr>
</table></div>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright &#169; 2006-2010, 2012-2014 Nikhar Agrawal,
Anton Bikineev, Paul A. Bristow, Marco Guazzone, Christopher Kormanyos, Hubert
Holin, Bruno Lalande, John Maddock, Jeremy Murphy, Johan R&#229;de, Gautam Sewani,
Benjamin Sobotta, Thijs van den Berg, Daryle Walker and Xiaogang Zhang<p>
Distributed under the Boost Software License, Version 1.0. (See accompanying
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>)
</p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<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>
</div>
</body>
</html>