Resolved conflicts from pull from origin/develop

This commit is contained in:
pabristow
2020-01-29 11:45:41 +00:00
parent e783d1e300
commit 0fe173730d
41 changed files with 529 additions and 200 deletions
+10
View File
@@ -3,6 +3,13 @@
# (See accompanying file LICENSE_1_0.txt or copy at
# http://www.boost.org/LICENSE_1_0.txt.
# Several tests to check configuration of multiprecision configuration.
# Note all are explicit, so much each or all be specified to actually check a specific configuration.
# Examples:
# \boost\libs\multiprecision\config>b2 toolset=clang-win-9.0.0 cxxstd=2a release address-model=64 has_float128 has_constexpr_limits has_is_constant_evaluated > MP_config_clangwin900.log
# \boost\libs\multiprecision\config>b2 -a --debug-configuration toolset=gcc-8.1.0 cxxstd=2a release address-model=64 has_float128 has_constexpr_limits has_is_constant_evaluated >MP_config_gcc810.log
# \boost\libs\multiprecision\config>b2 toolset=msvc-14.2 cxxstd=latest release address-model=64 has_float128 has_constexpr_limits has_is_constant_evaluated >MP_config_msvc142.log
import modules ;
import path ;
@@ -34,6 +41,7 @@ project : requirements
<toolset>msvc:<warnings>all
<toolset>gcc:<cxxflags>-Wall
<toolset>gcc:<cxxflags>-Wextra
<toolset>gcc:<cxxflags>-fext-numeric-literals # enable suffix Q for float128.
;
lib gmp ;
@@ -74,6 +82,8 @@ exe has_eigen : has_eigen.cpp ;
exe has_f2c : has_f2c.cpp f2c ;
obj has_is_constant_evaluated : has_is_constant_evaluated.cpp ;
obj has_constexpr_limits : has_constexpr_limits_cmd.cpp : <cxxflags>-fconstexpr-ops-limit=268435456 ;
# gcc8.1 g++.exe: error: unrecognized command line option '-fconstexpr-ops-limit=268435456'; did you mean '-fconstexpr-loop-limit='?
explicit has_gmp ;
explicit has_mpfr ;
+4 -2
View File
@@ -3,11 +3,13 @@
// Boost Software License, Version 1.0. (See accompanying file
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
// This determines if std::numeric_limits can be constexpr for the compiler/configuration.
#ifndef __GNUC__
#error "Compiler is not GCC"
# error "Compiler is not GCC."
#endif
#if __GNUC__ < 9
#error "Older GCC versions don't support -fconstexpr-ops-limit"
# error "Older GCC versions don't support -fconstexpr-ops-limit (aka -fconstexpr-loop-limit=n) ."
#endif
int main()
+3 -1
View File
@@ -3,10 +3,12 @@
// Boost Software License, Version 1.0. (See accompanying file
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
// This program tests if a configuration can use type __float128.
#include <boost/config.hpp>
#ifndef BOOST_HAS_FLOAT128
#error "This doesn't work unless Boost.Config enables __float128 support"
# error "This doesn't work unless Boost.Config enables __float128 support. Requires GCC using GNU C++compiler and option -fext-numeric-literals. For example: b2/bjam command "b2 float128_snips toolset=gcc-8.1.0 cxxstd=17 cxxstd-dialect=gnu address-model=64 release "
#endif
extern "C" {
+38 -2
View File
@@ -3,8 +3,44 @@
// Boost Software License, Version 1.0. (See accompanying file
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
// This program determines if std::is_constant_evaluated is available to switch within a function to use compile-time constexp calculations.
// See https://en.cppreference.com/w/cpp/types/is_constant_evaluated
// and https://en.cppreference.com/w/cpp/compiler_support
// Currently only GCC 9 and Clang 9 and <cxxflags>-std=c++2a or b2 cxxstd=2a
// https://clang.llvm.org/docs/LanguageExtensions.html#builtin-macros
// From Clang 10 onwards, __has_builtin(__X) can be used. but also works for Clang 9
// boost\libs\multiprecision\config>b2 has_is_constant_evaluated toolset=clang-win-9.0.0 cxxstd=2a address-model=64 release > mp_is_const_eval_30Sep2019.log
#include <boost/config.hpp>
#include <boost/multiprecision/number.hpp>
#ifdef BOOST_MP_NO_CONSTEXPR_DETECTION
#error 1
#ifdef __has_builtin
# warning " __has_builtin is defined."
# if __has_builtin(__builtin_is_constant_evaluated)
# warning " __has_builtin(__builtin_is_constant_evaluated), so BOOST_MP_NO_CONSTEXPR_DETECTION should NOT be defined."
# endif // __has_builtin(__builtin_is_constant_evaluated)
#endif // __has_builtin
#ifdef BOOST_MP_HAS_IS_CONSTANT_EVALUATED
# warning "BOOST_MP_HAS_IS_CONSTANT_EVALUATED defined."
#else
# warning "BOOST_MP_HAS_IS_CONSTANT_EVALUATED is NOT defined, so no std::is_constant_evaluated() from std library."
#endif
#ifdef BOOST_NO_CXX14_CONSTEXPR
# warning "BOOST_NO_CXX14_CONSTEXPR is defined."
#endif
#ifdef BOOST_NO_CXX17_CONSTEXPR
# warning "BOOST_NO_CXX17_CONSTEXPR is defined."
#endif
#ifdef BOOST_MP_NO_CONSTEXPR_DETECTION
# error 1 "std::is_constant_evaluated is NOT available to determine if a calculation can use constexpr."
#endif
+13 -7
View File
@@ -36,7 +36,7 @@
<div class="index"><ul class="index" style="list-style-type: none; ">
<li class="listitem" style="list-style-type: none"><p><a class="link" href="../intro.html" title="Introduction"><span class="index-entry-level-1">Introduction</span></a></p></li>
<li class="listitem" style="list-style-type: none"><p><a class="link" href="../tut/mixed.html" title="Mixed Precision Arithmetic"><span class="index-entry-level-1">Mixed Precision Arithmetic</span></a></p></li>
<li class="listitem" style="list-style-type: none"><p><a class="link" href="../tut/floats/fp_eg/variable_precision.html" title="Variable Precision Newton Evaluation"><span class="index-entry-level-1">Variable Precision Newton Evaluation</span></a></p></li>
<li class="listitem" style="list-style-type: none"><p><a class="link" href="../tut/floats/fp_eg/variable_precision.html" title="Variable-Precision Newton Evaluation"><span class="index-entry-level-1">Variable-Precision Newton Evaluation</span></a></p></li>
</ul></div>
</li>
<li class="listitem" style="list-style-type: none">
@@ -540,7 +540,7 @@
<p><span class="index-entry-level-0">exp</span></p>
<div class="index"><ul class="index" style="list-style-type: none; ">
<li class="listitem" style="list-style-type: none"><p><a class="link" href="../ref/number.html" title="number"><span class="index-entry-level-1">number</span></a></p></li>
<li class="listitem" style="list-style-type: none"><p><a class="link" href="../tut/floats/fp_eg/variable_precision.html" title="Variable Precision Newton Evaluation"><span class="index-entry-level-1">Variable Precision Newton Evaluation</span></a></p></li>
<li class="listitem" style="list-style-type: none"><p><a class="link" href="../tut/floats/fp_eg/variable_precision.html" title="Variable-Precision Newton Evaluation"><span class="index-entry-level-1">Variable-Precision Newton Evaluation</span></a></p></li>
</ul></div>
</li>
<li class="listitem" style="list-style-type: none">
@@ -567,7 +567,7 @@
<p><span class="index-entry-level-0">f</span></p>
<div class="index"><ul class="index" style="list-style-type: none; ">
<li class="listitem" style="list-style-type: none"><p><a class="link" href="../tut/import_export.html" title="Importing and Exporting Data to and from cpp_int and cpp_bin_float"><span class="index-entry-level-1">Importing and Exporting Data to and from cpp_int and cpp_bin_float</span></a></p></li>
<li class="listitem" style="list-style-type: none"><p><a class="link" href="../tut/floats/fp_eg/variable_precision.html" title="Variable Precision Newton Evaluation"><span class="index-entry-level-1">Variable Precision Newton Evaluation</span></a></p></li>
<li class="listitem" style="list-style-type: none"><p><a class="link" href="../tut/floats/fp_eg/variable_precision.html" title="Variable-Precision Newton Evaluation"><span class="index-entry-level-1">Variable-Precision Newton Evaluation</span></a></p></li>
</ul></div>
</li>
<li class="listitem" style="list-style-type: none">
@@ -588,7 +588,7 @@
</dt>
<dd><div class="index"><ul class="index" style="list-style-type: none; "><li class="listitem" style="list-style-type: none">
<p><span class="index-entry-level-0">half</span></p>
<div class="index"><ul class="index" style="list-style-type: none; "><li class="listitem" style="list-style-type: none"><p><a class="link" href="../tut/floats/fp_eg/variable_precision.html" title="Variable Precision Newton Evaluation"><span class="index-entry-level-1">Variable Precision Newton Evaluation</span></a></p></li></ul></div>
<div class="index"><ul class="index" style="list-style-type: none; "><li class="listitem" style="list-style-type: none"><p><a class="link" href="../tut/floats/fp_eg/variable_precision.html" title="Variable-Precision Newton Evaluation"><span class="index-entry-level-1">Variable-Precision Newton Evaluation</span></a></p></li></ul></div>
</li></ul></div></dd>
<dt>
<a name="idx_id_8"></a><span class="term">I</span>
@@ -622,7 +622,10 @@
</li>
<li class="listitem" style="list-style-type: none">
<p><span class="index-entry-level-0">infinity</span></p>
<div class="index"><ul class="index" style="list-style-type: none; "><li class="listitem" style="list-style-type: none"><p><a class="link" href="../tut/limits/functions.html" title="std::numeric_limits&lt;&gt; functions"><span class="index-entry-level-1">std :: numeric_limits &lt;&gt; functions</span></a></p></li></ul></div>
<div class="index"><ul class="index" style="list-style-type: none; ">
<li class="listitem" style="list-style-type: none"><p><a class="link" href="../tut/limits/functions.html" title="std::numeric_limits&lt;&gt; functions"><span class="index-entry-level-1">std :: numeric_limits &lt;&gt; functions</span></a></p></li>
<li class="listitem" style="list-style-type: none"><p><a class="link" href="../tut/limits/constants.html" title="std::numeric_limits&lt;&gt; constants"><span class="index-entry-level-1">std::numeric_limits&lt;&gt; constants</span></a></p></li>
</ul></div>
</li>
<li class="listitem" style="list-style-type: none">
<p><span class="index-entry-level-0">integer_modulus</span></p>
@@ -814,7 +817,10 @@
<dd><div class="index"><ul class="index" style="list-style-type: none; ">
<li class="listitem" style="list-style-type: none">
<p><span class="index-entry-level-0">of</span></p>
<div class="index"><ul class="index" style="list-style-type: none; "><li class="listitem" style="list-style-type: none"><p><a class="link" href="../ref/backendconc.html#boost_multiprecision.ref.backendconc.optional_requirements_on_the_bac" title="Table&#160;1.9.&#160;Optional Requirements on the Backend Type"><span class="index-entry-level-1">Optional Requirements on the Backend Type</span></a></p></li></ul></div>
<div class="index"><ul class="index" style="list-style-type: none; ">
<li class="listitem" style="list-style-type: none"><p><a class="link" href="../tut/floats/float128.html" title="float128"><span class="index-entry-level-1">float128</span></a></p></li>
<li class="listitem" style="list-style-type: none"><p><a class="link" href="../ref/backendconc.html#boost_multiprecision.ref.backendconc.optional_requirements_on_the_bac" title="Table&#160;1.9.&#160;Optional Requirements on the Backend Type"><span class="index-entry-level-1">Optional Requirements on the Backend Type</span></a></p></li>
</ul></div>
</li>
<li class="listitem" style="list-style-type: none">
<p><span class="index-entry-level-0">overlap</span></p>
@@ -1001,7 +1007,7 @@
</dt>
<dd><div class="index"><ul class="index" style="list-style-type: none; "><li class="listitem" style="list-style-type: none">
<p><span class="index-entry-level-0">x</span></p>
<div class="index"><ul class="index" style="list-style-type: none; "><li class="listitem" style="list-style-type: none"><p><a class="link" href="../tut/floats/fp_eg/variable_precision.html" title="Variable Precision Newton Evaluation"><span class="index-entry-level-1">Variable Precision Newton Evaluation</span></a></p></li></ul></div>
<div class="index"><ul class="index" style="list-style-type: none; "><li class="listitem" style="list-style-type: none"><p><a class="link" href="../tut/floats/fp_eg/variable_precision.html" title="Variable-Precision Newton Evaluation"><span class="index-entry-level-1">Variable-Precision Newton Evaluation</span></a></p></li></ul></div>
</li></ul></div></dd>
<dt>
<a name="idx_id_20"></a><span class="term">Z</span>
+5 -4
View File
@@ -520,9 +520,10 @@
updated random examples to match.
</li>
<li class="listitem">
Fixed a bug in cpp_int's right shift operator when shifting negative
values - semantics now gives the same values as shifting 2's compliment
integers, though not the same bit pattern.
Fixed a bug in <code class="computeroutput"><span class="identifier">cpp_int</span></code>
right shift operator when shifting negative values - semantics now gives
the same values as shifting 2's compliment integers, though not the same
bit pattern.
</li>
<li class="listitem">
Fixed support for GCC-4.6.4 in C++0x mode by disabling conditional noexcept
@@ -791,7 +792,7 @@
</h5>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
2011-2012, John Maddock adds an expression template enabled front end
2011-2012, John Maddock adds an expression template enabled front-end
to Christopher's code, and adds support for other backends.
</li>
<li class="listitem">
@@ -38,7 +38,7 @@
</p>
<p>
Optional requirements have default implementations that are called if the
backend doesn't provide it's own. Typically the backend will implement these
backend doesn't provide its own. Typically the backend will implement these
to improve performance.
</p>
<p>
@@ -113,7 +113,7 @@
<p>
Internally, an N-bit <code class="computeroutput"><span class="identifier">cpp_bin_float</span></code>
is represented as an N-bit unsigned integer along with an exponent and a
sign. The integer part is normalized so that it's most significant bit is
sign. The integer part is normalized so that its most significant bit is
always 1. The decimal point is assumed to be directly after the most significant
bit of the integer part. The special values zero, infinity and NaN all have
the integer part set to zero, and the exponent to one of 3 special values
+4 -2
View File
@@ -49,6 +49,8 @@
<dd><dl>
<dt><span class="section"><a href="tut/floats/fp_eg/aos.html">Area of
Circle</a></span></dt>
<dt><span class="section"><a href="tut/floats/fp_eg/caveats.html">Drop-in
Caveats</a></span></dt>
<dt><span class="section"><a href="tut/floats/fp_eg/jel.html">Defining
a Special Function.</a></span></dt>
<dt><span class="section"><a href="tut/floats/fp_eg/nd.html">Calculating
@@ -57,8 +59,8 @@
an Integral</a></span></dt>
<dt><span class="section"><a href="tut/floats/fp_eg/poly_eg.html">Polynomial
Evaluation</a></span></dt>
<dt><span class="section"><a href="tut/floats/fp_eg/variable_precision.html">Variable
Precision Newton Evaluation</a></span></dt>
<dt><span class="section"><a href="tut/floats/fp_eg/variable_precision.html">Variable-Precision
Newton Evaluation</a></span></dt>
</dl></dd>
</dl></dd>
<dt><span class="section"><a href="tut/interval.html">Interval Number Types</a></span></dt>
@@ -202,7 +202,7 @@
</td>
<td>
<p>
Not a numbe rin it's own right, and hard to use as a result.
Not a number in its own right, and hard to use as a result.
</p>
</td>
</tr>
@@ -89,7 +89,8 @@
</ul></div>
<p>
It's also possible to access the underlying <code class="computeroutput"><span class="identifier">mpc_t</span></code>
via the data() member function of <code class="computeroutput"><span class="identifier">mpfr_float_backend</span></code>.
via the <code class="computeroutput"><span class="identifier">data</span><span class="special">()</span></code>
member function of <code class="computeroutput"><span class="identifier">mpfr_float_backend</span></code>.
</p>
<p>
Things you should know when using this type:
@@ -77,8 +77,10 @@
</li>
<li class="listitem">
Conversions to floating-point numbers from rational ones are rounded
to nearest (less than 0.5ulp error) as long as the floating-point number
is binary, and the integer type used by the rational number is unbounded.
to nearest (less than 0.5 <a href="http://en.wikipedia.org/wiki/Unit_in_the_last_place" target="_top">Unit
in the last place (ULP)</a> error) as long as the floating-point
number is binary, and the integer type used by the rational number is
unbounded.
</li>
</ul></div>
<p>
@@ -36,6 +36,8 @@
<dd><dl>
<dt><span class="section"><a href="floats/fp_eg/aos.html">Area of
Circle</a></span></dt>
<dt><span class="section"><a href="floats/fp_eg/caveats.html">Drop-in
Caveats</a></span></dt>
<dt><span class="section"><a href="floats/fp_eg/jel.html">Defining
a Special Function.</a></span></dt>
<dt><span class="section"><a href="floats/fp_eg/nd.html">Calculating
@@ -44,8 +46,8 @@
an Integral</a></span></dt>
<dt><span class="section"><a href="floats/fp_eg/poly_eg.html">Polynomial
Evaluation</a></span></dt>
<dt><span class="section"><a href="floats/fp_eg/variable_precision.html">Variable
Precision Newton Evaluation</a></span></dt>
<dt><span class="section"><a href="floats/fp_eg/variable_precision.html">Variable-Precision
Newton Evaluation</a></span></dt>
</dl></dd>
</dl></div>
<p>
@@ -159,6 +159,7 @@
</h6>
<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">multiprecision</span><span class="special">/</span><span class="identifier">cpp_bin_float</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
<span class="preprocessor">#include</span> <span class="special">&lt;</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">&gt;</span>
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">iostream</span><span class="special">&gt;</span>
<span class="keyword">int</span> <span class="identifier">main</span><span class="special">()</span>
@@ -169,14 +170,17 @@
<span class="identifier">cpp_bin_float_100</span> <span class="identifier">b</span> <span class="special">=</span> <span class="number">2</span><span class="special">;</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limits</span><span class="special">&lt;</span><span class="identifier">cpp_bin_float_100</span><span class="special">&gt;::</span><span class="identifier">digits</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="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limits</span><span class="special">&lt;</span><span class="identifier">cpp_bin_float_100</span><span class="special">&gt;::</span><span class="identifier">digits10</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">// We can use any C++ std lib function, lets print all the digits as well:</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</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">&lt;</span><span class="identifier">cpp_bin_float_100</span><span class="special">&gt;::</span><span class="identifier">max_digits10</span><span class="special">)</span>
<span class="special">&lt;&lt;</span> <span class="identifier">log</span><span class="special">(</span><span class="identifier">b</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">// print log(2)</span>
<span class="comment">// We can also use any function from Boost.Math:</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</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">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
<span class="comment">// These even work when the argument is an expression template:</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</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="identifier">b</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">// And since we have an extended exponent range we can generate some really large </span>
<span class="comment">// And since we have an extended exponent range we can generate some really large</span>
<span class="comment">// numbers here (4.0238726007709377354370243e+2564):</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</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">cpp_bin_float_100</span><span class="special">(</span><span class="number">1000</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="keyword">return</span> <span class="number">0</span><span class="special">;</span>
@@ -75,7 +75,7 @@
digit counts.
</p>
<p>
There is full standard library and <code class="computeroutput"><span class="identifier">numeric_limits</span></code>
There is full standard library and <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limits</span></code>
support available for this type.
</p>
<p>
@@ -46,7 +46,7 @@
with FORTRAN's 128-bit QUAD real.
</p>
<p>
All the usual standard library and <code class="computeroutput"><span class="identifier">numeric_limits</span></code>
All the usual standard library and <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limits</span></code>
support are available, performance should be equivalent to the underlying
native types: for example the LINPACK benchmarks for GCC's <code class="computeroutput"><a class="link" href="float128.html" title="float128">float128</a></code>
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" name="boost_multiprecision.tut.floats.float128.f0"><sup class="footnote">[3]</sup></a>.
@@ -129,6 +129,18 @@
as the suffix 'Q' is a GNU extension. Compilation fails with the flag
<code class="computeroutput"><span class="special">--</span><span class="identifier">std</span><span class="special">=</span><span class="identifier">c</span><span class="special">++</span><span class="number">11</span><span class="special">/</span><span class="number">14</span><span class="special">/</span><span class="number">17</span></code> unless you also use <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>.
</li>
<li class="listitem">
You will need to link to <code class="computeroutput"><span class="identifier">libquadmath</span><span class="special">.</span><span class="identifier">dll</span></code>
with the link command <code class="computeroutput"><span class="special">-</span><span class="identifier">lquadmath</span></code> and ensure that the DLL
is visible by the linker. If you are using the B2/bjam build system
then commands<code class="computeroutput"><span class="special">&lt;</span><span class="identifier">linkflags</span><span class="special">&gt;-</span><span class="identifier">lQUADMATH</span></code>
and <code class="computeroutput"><span class="special">&lt;</span><span class="identifier">linkflags</span><span class="special">&gt;-</span><span class="identifier">L</span><span class="string">"path/to/lib"</span></code> will be needed.
</li>
<li class="listitem">
The values shown by <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limits</span><span class="special">&lt;</span><span class="identifier">float128</span><span class="special">&gt;</span></code> and extremely close <span class="emphasis"><em>but
not identical</em></span> to those from the equivalent precision and
range multiprecision types <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limits</span><span class="special">&lt;</span><span class="identifier">cpp_bin_float_quad</span><span class="special">&gt;</span></code> and <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limits</span><span class="special">&lt;</span><span class="identifier">cpp_dec_float_quad</span><span class="special">&gt;</span></code>.
</li>
</ul></div>
<h6>
<a name="boost_multiprecision.tut.floats.float128.h0"></a>
@@ -141,30 +153,93 @@
<span class="keyword">int</span> <span class="identifier">main</span><span class="special">()</span>
<span class="special">{</span>
<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>
<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> <span class="comment">// Potential to cause name collisions?</span>
<span class="comment">// using boost::multiprecision::float128; // is safer.</span>
</pre>
<p>
The type float128 provides operations at 128-bit precision with <a href="https://en.wikipedia.org/wiki/Quadruple-precision_floating-point_format#IEEE_754_quadruple-precision_binary_floating-point_format:_binary128" target="_top">Quadruple-precision
floating-point format</a> and have full <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limits</span></code>
support:
</p>
<pre class="programlisting"><span class="identifier">float128</span> <span class="identifier">b</span> <span class="special">=</span> <span class="number">2</span><span class="special">;</span>
</pre>
<p>
There are 15 bits of (biased) binary exponent and 113-bits of significand
precision
</p>
<pre class="programlisting"><span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limits</span><span class="special">&lt;</span><span class="identifier">float128</span><span class="special">&gt;::</span><span class="identifier">digits</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>
</pre>
<p>
or 33 decimal places:
</p>
<pre class="programlisting"><span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limits</span><span class="special">&lt;</span><span class="identifier">float128</span><span class="special">&gt;::</span><span class="identifier">digits10</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>
</pre>
<p>
We can use any C++ std library function, so let's show all the at-most
36 potentially significant digits, and any trailing zeros, as well:
</p>
<pre class="programlisting"> <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span><span class="special">.</span><span class="identifier">setf</span><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">ios_base</span><span class="special">::</span><span class="identifier">showpoint</span><span class="special">);</span> <span class="comment">// Include any trailing zeros.</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</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">&lt;</span><span class="identifier">float128</span><span class="special">&gt;::</span><span class="identifier">max_digits10</span><span class="special">)</span>
<span class="special">&lt;&lt;</span> <span class="identifier">log</span><span class="special">(</span><span class="identifier">b</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">// Shows log(2) = 0.693147180559945309417232121458176575</span>
</pre>
<p>
We can also use any function from Boost.Math, for example, the 'true gamma'
function <code class="computeroutput"><span class="identifier">tgamma</span></code>:
</p>
<pre class="programlisting"><span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</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">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
</pre>
<p>
And since we have an extended exponent range, we can generate some really
large numbers here (4.02387260077093773543702433923004111e+2564):
</p>
<pre class="programlisting"><span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</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">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
</pre>
<p>
We can declare constants using GCC or Intel's native types, and literals
with the Q suffix, and these can be declared <code class="computeroutput"><span class="keyword">constexpr</span></code>
if required:
</p>
<pre class="programlisting"><span class="keyword">constexpr</span> <span class="identifier">float128</span> <span class="identifier">pi</span> <span class="special">=</span> <span class="number">3.14159265358979323846264338327950</span><span class="identifier">Q</span><span class="special">;</span>
</pre>
<p>
Values for <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limits</span><span class="special">&lt;</span><span class="identifier">float128</span><span class="special">&gt;</span></code>
are:
</p>
<pre class="programlisting"><span class="identifier">GCC</span> <span class="number">8.1</span><span class="special">.</span><span class="number">0</span>
<span class="comment">// Operations at 128-bit precision and full numeric_limits support:</span>
<span class="identifier">float128</span> <span class="identifier">b</span> <span class="special">=</span> <span class="number">2</span><span class="special">;</span>
<span class="comment">// There are 113-bits of precision:</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limits</span><span class="special">&lt;</span><span class="identifier">float128</span><span class="special">&gt;::</span><span class="identifier">digits</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">// Or 34 decimal places:</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limits</span><span class="special">&lt;</span><span class="identifier">float128</span><span class="special">&gt;::</span><span class="identifier">digits10</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">// We can use any C++ std lib function, lets print all the digits as well:</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</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">&lt;</span><span class="identifier">float128</span><span class="special">&gt;::</span><span class="identifier">max_digits10</span><span class="special">)</span>
<span class="special">&lt;&lt;</span> <span class="identifier">log</span><span class="special">(</span><span class="identifier">b</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">// print log(2) = 0.693147180559945309417232121458176575</span>
<span class="comment">// We can also use any function from Boost.Math:</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</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">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
<span class="comment">// And since we have an extended exponent range we can generate some really large </span>
<span class="comment">// numbers here (4.02387260077093773543702433923004111e+2564):</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</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">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
<span class="comment">//</span>
<span class="comment">// We can declare constants using GCC or Intel's native types, and the Q suffix,</span>
<span class="comment">// these can be declared constexpr if required:</span>
<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>
<span class="keyword">return</span> <span class="number">0</span><span class="special">;</span>
<span class="special">}</span>
<span class="identifier">Type</span> <span class="identifier">name</span> <span class="identifier">is</span> <span class="identifier">float128_t</span><span class="special">:</span>
<span class="identifier">Type</span> <span class="identifier">is</span> <span class="identifier">g</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">is_fundamental</span><span class="special">&lt;&gt;</span> <span class="special">=</span> <span class="keyword">true</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">is_signed</span><span class="special">&lt;&gt;</span> <span class="special">=</span> <span class="keyword">true</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">is_unsigned</span><span class="special">&lt;&gt;</span> <span class="special">=</span> <span class="keyword">false</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">is_integral</span><span class="special">&lt;&gt;</span> <span class="special">=</span> <span class="keyword">false</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">is_arithmetic</span><span class="special">&lt;&gt;</span> <span class="special">=</span> <span class="keyword">true</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">is_const</span><span class="special">&lt;&gt;</span> <span class="special">=</span> <span class="keyword">false</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">is_trivial</span><span class="special">&lt;&gt;</span> <span class="special">=</span> <span class="keyword">true</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">is_standard_layout</span><span class="special">&lt;&gt;</span> <span class="special">=</span> <span class="keyword">true</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">is_pod</span><span class="special">&lt;&gt;</span> <span class="special">=</span> <span class="keyword">true</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limits</span><span class="special">::&lt;&gt;</span><span class="identifier">is_exact</span> <span class="special">=</span> <span class="keyword">false</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limits</span><span class="special">::&lt;&gt;</span><span class="identifier">is</span> <span class="identifier">bounded</span> <span class="special">=</span> <span class="keyword">true</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limits</span><span class="special">::&lt;&gt;</span><span class="identifier">is_modulo</span> <span class="special">=</span> <span class="keyword">false</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limits</span><span class="special">::&lt;&gt;</span><span class="identifier">is_iec559</span> <span class="special">=</span> <span class="keyword">true</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limits</span><span class="special">::&lt;&gt;</span><span class="identifier">traps</span> <span class="special">=</span> <span class="keyword">false</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limits</span><span class="special">::&lt;&gt;</span><span class="identifier">tinyness_before</span> <span class="special">=</span> <span class="keyword">false</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limits</span><span class="special">::&lt;&gt;</span><span class="identifier">max</span><span class="special">()</span> <span class="special">=</span> <span class="number">1.18973149535723176508575932662800702e+4932</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limits</span><span class="special">::&lt;&gt;</span><span class="identifier">min</span><span class="special">()</span> <span class="special">=</span> <span class="number">3.36210314311209350626267781732175260e-4932</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limits</span><span class="special">::&lt;&gt;</span><span class="identifier">lowest</span><span class="special">()</span> <span class="special">=</span> <span class="special">-</span><span class="number">1.18973149535723176508575932662800702e+4932</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limits</span><span class="special">::&lt;&gt;</span><span class="identifier">min_exponent</span> <span class="special">=</span> <span class="special">-</span><span class="number">16381</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limits</span><span class="special">::&lt;&gt;</span><span class="identifier">max_exponent</span> <span class="special">=</span> <span class="number">16384</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limits</span><span class="special">::&lt;&gt;</span><span class="identifier">epsilon</span><span class="special">()</span> <span class="special">=</span> <span class="number">1.92592994438723585305597794258492732e-34</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limits</span><span class="special">::&lt;&gt;</span><span class="identifier">radix</span> <span class="special">=</span> <span class="number">2</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limits</span><span class="special">::&lt;&gt;</span><span class="identifier">digits</span> <span class="special">=</span> <span class="number">113</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limits</span><span class="special">::&lt;&gt;</span><span class="identifier">digits10</span> <span class="special">=</span> <span class="number">33</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limits</span><span class="special">::&lt;&gt;</span><span class="identifier">max_digits10</span> <span class="special">=</span> <span class="number">36</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limits</span><span class="special">::&lt;&gt;</span><span class="identifier">has</span> <span class="identifier">denorm</span> <span class="special">=</span> <span class="keyword">true</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limits</span><span class="special">::&lt;&gt;</span><span class="identifier">denorm</span> <span class="identifier">min</span> <span class="special">=</span> <span class="number">6.47517511943802511092443895822764655e-4966</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">denorm_loss</span> <span class="special">=</span> <span class="keyword">false</span>
<span class="identifier">limits</span><span class="special">::</span><span class="identifier">has_signaling_NaN</span> <span class="special">==</span> <span class="keyword">false</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limits</span><span class="special">::&lt;&gt;</span><span class="identifier">quiet_NaN</span> <span class="special">=</span> <span class="identifier">nan</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limits</span><span class="special">::&lt;&gt;</span><span class="identifier">infinity</span> <span class="special">=</span> <span class="identifier">inf</span>
</pre>
<div class="footnotes">
<br><hr style="width:100; text-align:left;margin-left: 0">
@@ -29,6 +29,8 @@
<div class="toc"><dl class="toc">
<dt><span class="section"><a href="fp_eg/aos.html">Area of
Circle</a></span></dt>
<dt><span class="section"><a href="fp_eg/caveats.html">Drop-in
Caveats</a></span></dt>
<dt><span class="section"><a href="fp_eg/jel.html">Defining
a Special Function.</a></span></dt>
<dt><span class="section"><a href="fp_eg/nd.html">Calculating
@@ -37,8 +39,8 @@
an Integral</a></span></dt>
<dt><span class="section"><a href="fp_eg/poly_eg.html">Polynomial
Evaluation</a></span></dt>
<dt><span class="section"><a href="fp_eg/variable_precision.html">Variable
Precision Newton Evaluation</a></span></dt>
<dt><span class="section"><a href="fp_eg/variable_precision.html">Variable-Precision
Newton Evaluation</a></span></dt>
</dl></div>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
@@ -7,7 +7,7 @@
<link rel="home" href="../../../../index.html" title="Chapter&#160;1.&#160;Boost.Multiprecision">
<link rel="up" href="../fp_eg.html" title="Examples">
<link rel="prev" href="../fp_eg.html" title="Examples">
<link rel="next" href="jel.html" title="Defining a Special Function.">
<link rel="next" href="caveats.html" title="Drop-in Caveats">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr>
@@ -20,7 +20,7 @@
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="../fp_eg.html"><img src="../../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../fp_eg.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="jel.html"><img src="../../../../../../../../doc/src/images/next.png" alt="Next"></a>
<a accesskey="p" href="../fp_eg.html"><img src="../../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../fp_eg.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="caveats.html"><img src="../../../../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h5 class="title">
@@ -114,7 +114,7 @@
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="../fp_eg.html"><img src="../../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../fp_eg.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="jel.html"><img src="../../../../../../../../doc/src/images/next.png" alt="Next"></a>
<a accesskey="p" href="../fp_eg.html"><img src="../../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../fp_eg.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="caveats.html"><img src="../../../../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>
@@ -6,7 +6,7 @@
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="../../../../index.html" title="Chapter&#160;1.&#160;Boost.Multiprecision">
<link rel="up" href="../fp_eg.html" title="Examples">
<link rel="prev" href="aos.html" title="Area of Circle">
<link rel="prev" href="caveats.html" title="Drop-in Caveats">
<link rel="next" href="nd.html" title="Calculating a Derivative">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
@@ -20,7 +20,7 @@
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="aos.html"><img src="../../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../fp_eg.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="nd.html"><img src="../../../../../../../../doc/src/images/next.png" alt="Next"></a>
<a accesskey="p" href="caveats.html"><img src="../../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../fp_eg.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="nd.html"><img src="../../../../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h5 class="title">
@@ -210,7 +210,7 @@
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="aos.html"><img src="../../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../fp_eg.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="nd.html"><img src="../../../../../../../../doc/src/images/next.png" alt="Next"></a>
<a accesskey="p" href="caveats.html"><img src="../../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../fp_eg.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="nd.html"><img src="../../../../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>
@@ -7,7 +7,7 @@
<link rel="home" href="../../../../index.html" title="Chapter&#160;1.&#160;Boost.Multiprecision">
<link rel="up" href="../fp_eg.html" title="Examples">
<link rel="prev" href="gi.html" title="Calculating an Integral">
<link rel="next" href="variable_precision.html" title="Variable Precision Newton Evaluation">
<link rel="next" href="variable_precision.html" title="Variable-Precision Newton Evaluation">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr>
@@ -1,7 +1,7 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>Variable Precision Newton Evaluation</title>
<title>Variable-Precision Newton Evaluation</title>
<link rel="stylesheet" href="../../../../multiprecision.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="../../../../index.html" title="Chapter&#160;1.&#160;Boost.Multiprecision">
@@ -24,8 +24,8 @@
</div>
<div class="section">
<div class="titlepage"><div><div><h5 class="title">
<a name="boost_multiprecision.tut.floats.fp_eg.variable_precision"></a><a class="link" href="variable_precision.html" title="Variable Precision Newton Evaluation">Variable
Precision Newton Evaluation</a>
<a name="boost_multiprecision.tut.floats.fp_eg.variable_precision"></a><a class="link" href="variable_precision.html" title="Variable-Precision Newton Evaluation">Variable-Precision
Newton Evaluation</a>
</h5></div></div></div>
<p>
This example illustrates the use of variable-precision arithmetic with
@@ -3,7 +3,7 @@
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>mpfr_float</title>
<link rel="stylesheet" href="../../../multiprecision.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<meta name="generator" content="DocBook XSL Stylesheets V1.77.1">
<link rel="home" href="../../../index.html" title="Chapter&#160;1.&#160;Boost.Multiprecision">
<link rel="up" href="../floats.html" title="floating-point Numbers">
<link rel="prev" href="gmp_float.html" title="gmp_float">
@@ -76,11 +76,13 @@
types is stored within <code class="computeroutput"><span class="identifier">mpfr_float_backend</span></code>).
The latter option can result in significantly faster code, at the expense
of growing the size of <code class="computeroutput"><span class="identifier">mpfr_float_backend</span></code>.
It can only be used at fixed precision, and should only be used for lower
digit counts. Note that we can not guarantee that using <code class="computeroutput"><span class="identifier">allocate_stack</span></code>
won't cause any calls to mpfr's allocation routines, as mpfr may call these
inside it's own code. The following table gives an idea of the performance
tradeoff's at 50 decimal digits precision<a href="#ftn.boost_multiprecision.tut.floats.mpfr_float.f0" class="footnote" name="boost_multiprecision.tut.floats.mpfr_float.f0"><sup class="footnote">[2]</sup></a>:
It can only be used at <span class="emphasis"><em>fixed precision</em></span>, and should
only be used for lower digit counts. Note that we can not guarantee that
using <code class="computeroutput"><span class="identifier">allocate_stack</span></code> won't
cause any calls to <code class="computeroutput"><span class="identifier">mpfr</span></code>'s
allocation routines, as <code class="computeroutput"><span class="identifier">mpfr</span></code>
may call these inside its own code. The following table gives an idea of
the performance tradeoff's at 50 decimal digits precision<a href="#ftn.boost_multiprecision.tut.floats.mpfr_float.f0" class="footnote"><sup class="footnote"><a name="boost_multiprecision.tut.floats.mpfr_float.f0"></a>[2]</sup></a>:
</p>
<div class="informaltable"><table class="table">
<colgroup>
@@ -277,7 +279,7 @@
<span class="special">}</span>
</pre>
<div class="footnotes">
<br><hr style="width:100; text-align:left;margin-left: 0">
<br><hr style="width:100; align:left;">
<div id="ftn.boost_multiprecision.tut.floats.mpfr_float.f0" class="footnote"><p><a href="#boost_multiprecision.tut.floats.mpfr_float.f0" class="para"><sup class="para">[2] </sup></a>
Compiled with VC++10 and /Ox, with MPFR-3.0.0 and MPIR-2.3.0
</p></div>
@@ -162,7 +162,8 @@
<p>
The regular Miller-Rabin functions in <code class="computeroutput"><span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">multiprecision</span><span class="special">/</span><span class="identifier">miller_rabin</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span></code>
are defined in terms of the above generic operations, and so function equally
well for built-in or __fundamental_types and multiprecision types.
well for <a href="https://en.cppreference.com/w/cpp/language/types" target="_top">fundamental
(built-in) types</a> and multiprecision types.
</p>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
@@ -30,7 +30,7 @@
</h3></div></div></div>
<p>
Any integer number type that uses <code class="computeroutput"><span class="identifier">cpp_int_backend</span></code>
as it's implementation layer can import or export its bits via two non-member
as its implementation layer can import or export its bits via two non-member
functions:
</p>
<pre class="programlisting"><span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">unsigned</span> <span class="identifier">MinBits</span><span class="special">,</span> <span class="keyword">unsigned</span> <span class="identifier">MaxBits</span><span class="special">,</span> <span class="identifier">cpp_integer_type</span> <span class="identifier">SignType</span><span class="special">,</span> <span class="identifier">cpp_int_check_type</span> <span class="identifier">Checked</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">Allocator</span><span class="special">,</span>
@@ -6,7 +6,7 @@
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="../../index.html" title="Chapter&#160;1.&#160;Boost.Multiprecision">
<link rel="up" href="../tut.html" title="Tutorial">
<link rel="prev" href="floats/fp_eg/variable_precision.html" title="Variable Precision Newton Evaluation">
<link rel="prev" href="floats/fp_eg/variable_precision.html" title="Variable-Precision Newton Evaluation">
<link rel="next" href="interval/mpfi.html" title="mpfi_float">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
@@ -58,7 +58,7 @@
<code class="computeroutput"><span class="identifier">mpfi_float_500</span></code>, <code class="computeroutput"><span class="identifier">mpfi_float_1000</span></code> provide arithmetic types
at 50, 100, 500 and 1000 decimal digits precision respectively. The <code class="computeroutput"><span class="keyword">typedef</span> <span class="identifier">mpfi_float</span></code>
provides a variable precision type whose precision can be controlled via
the <code class="computeroutput"><span class="identifier">number</span></code>s member functions.
theF <code class="computeroutput"><span class="identifier">number</span></code>s member functions.
</p>
<div class="note"><table border="0" summary="Note">
<tr>
@@ -93,7 +93,8 @@
</ul></div>
<p>
It's also possible to access the underlying <code class="computeroutput"><span class="identifier">mpfi_t</span></code>
via the data() member function of <code class="computeroutput"><span class="identifier">mpfi_float_backend</span></code>.
via the <code class="computeroutput"><span class="identifier">data</span><span class="special">()</span></code>
member function of <code class="computeroutput"><span class="identifier">mpfi_float_backend</span></code>.
</p>
<p>
Things you should know when using this type:
@@ -267,14 +267,15 @@
The type uses a sign-magnitude representation internally, so type
<code class="computeroutput"><span class="identifier">int128_t</span></code> has 128-bits
of precision plus an extra sign bit. In this respect the behaviour
of these types differs from built-in 2's complement types. In might
be tempting to use a 127-bit type instead, and indeed this does work,
but behaviour is still slightly different from a 2's complement built-in
type as the min and max values are identical (apart from the sign),
where as they differ by one for a true 2's complement type. That said
it should be noted that there's no requirement for built-in types to
be 2's complement either - it's simply that this is the most common
format by far.
of these types differs from <a href="https://en.cppreference.com/w/cpp/language/types" target="_top">fundamental
(built-in)</a> 2's complement types. In might be tempting to use
a 127-bit type instead, and indeed this does work, but behaviour is
still slightly different from a 2's complement <a href="https://en.cppreference.com/w/cpp/language/types" target="_top">fundamental
(built-in)</a> type as the minimum and maximum values are identical
(apart from the sign), where as they differ by one for a true 2's complement
type. That said it should be noted that there's no requirement for
fundamental_types to be 2's complement either - it's simply that this
is the most common format by far.
</li>
<li class="listitem">
Attempting to print negative values as either an Octal or Hexadecimal
@@ -340,12 +341,12 @@
have some support for <code class="computeroutput"><span class="keyword">constexpr</span></code>
values and user-defined literals, see <a class="link" href="../lits.html" title="Literal Types and constexpr Support">here</a>
for the full description. For example <code class="computeroutput"><span class="number">0xfffff</span><span class="identifier">_cppi1024</span></code> specifies a 1024-bit integer
with the value 0xffff. This can be used to generate compile time constants
with the value 0xffff. This can be used to generate compile-time constants
that are too large to fit into any built in number type.
</li>
<li class="listitem">
The <a class="link" href="cpp_int.html" title="cpp_int">cpp_int</a>
types support constexpr arithmetic, provided it is a fixed precision
types support constexpr arithmetic, provided it is a fixed-precision
type with no allocator. It may also be a checked integer: in which
case a compiler error will be generated on overflow or undefined behaviour.
In addition the free functions <code class="computeroutput"><span class="identifier">abs</span></code>,
@@ -59,7 +59,8 @@
for Binary Floating-Point Arithmetic</a>
</p>
<p>
There is a useful summary at <a href="http://www.cplusplus.com/reference/limits/numeric_limits/" target="_top">C++
There is a useful summary of <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limits</span></code>
at <a href="http://www.cplusplus.com/reference/limits/numeric_limits/" target="_top">C++
reference</a>.
</p>
<p>
@@ -76,10 +77,10 @@
<th align="left">Warning</th>
</tr>
<tr><td align="left" valign="top"><p>
GMP's <code class="computeroutput"><span class="identifier">mpf_t</span></code> does not have
a concept of overflow: operations that lead to overflow eventually run
of out of resources and terminate with stack overflow (often after several
seconds).
GMP's extendable floatin-point <code class="computeroutput"><span class="identifier">mpf_t</span></code>
does not have a concept of overflow: operations that lead to overflow eventually
run of out of resources and terminate with stack overflow (often after
several seconds).
</p></td></tr>
</table></div>
</div>
@@ -84,10 +84,16 @@
<p>
and using tests like this is strongly recommended to improve portability.
</p>
<p>
If the backend is switched to a type that does not support infinity then,
without checks like this, there will be trouble.
</p>
<div class="warning"><table border="0" summary="Warning">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Warning]" src="../../../../../../../doc/src/images/warning.png"></td>
<th align="left">Warning</th>
</tr>
<tr><td align="left" valign="top"><p>
If the backend is switched to a type that does not support infinity (or
similarly NaNs) then, without checks like this, there will be trouble.
</p></td></tr>
</table></div>
<h5>
<a name="boost_multiprecision.tut.limits.constants.h2"></a>
<span class="phrase"><a name="boost_multiprecision.tut.limits.constants.is_signed"></a></span><a class="link" href="constants.html#boost_multiprecision.tut.limits.constants.is_signed">is_signed</a>
@@ -98,9 +104,11 @@
is signed.
</p>
<p>
For built-in binary types, the sign is held in a single bit, but for other
types (cpp_dec_float and cpp_bin_float) it may be a separate storage element,
usually <code class="computeroutput"><span class="keyword">bool</span></code>.
For <a href="https://en.cppreference.com/w/cpp/language/types" target="_top">fundamental
(built-in)</a> binary types, the sign is held in a single bit, but
for other types (<code class="computeroutput"><span class="identifier">cpp_dec_float</span></code>
and <code class="computeroutput"><span class="identifier">cpp_bin_float</span></code>) it may
be a separate storage element, usually <code class="computeroutput"><span class="keyword">bool</span></code>.
</p>
<h5>
<a name="boost_multiprecision.tut.limits.constants.h3"></a>
@@ -169,8 +177,9 @@
by the type <code class="computeroutput"><span class="identifier">T</span></code> is finite.
</p>
<p>
This is <code class="computeroutput"><span class="keyword">true</span></code> for all built-in
integer, fixed and floating-point types, and most multi-precision types.
This is <code class="computeroutput"><span class="keyword">true</span></code> for all <a href="https://en.cppreference.com/w/cpp/language/types" target="_top">fundamental (built-in)
type</a> integer, fixed and floating-point types, and most multi-precision
types.
</p>
<p>
It is only <code class="computeroutput"><span class="keyword">false</span></code> for a few
@@ -195,7 +204,8 @@
value.
</p>
<p>
For most built-in integer types, <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limits</span><span class="special">&lt;&gt;::</span><span class="identifier">is_modulo</span></code>
For most <a href="https://en.cppreference.com/w/cpp/language/types" target="_top">fundamental
(built-in)</a> integer types, <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limits</span><span class="special">&lt;&gt;::</span><span class="identifier">is_modulo</span></code>
is <code class="computeroutput"><span class="keyword">true</span></code>.
</p>
<p>
@@ -221,7 +231,9 @@
be raised).
</p>
<p>
Built-in and multi-precision floating-point types are normally not modulo.
<a href="https://en.cppreference.com/w/cpp/language/types" target="_top">fundamental
(built-in)</a> and multi-precision floating-point types are normally
not modulo.
</p>
<p>
Where possible, overflow is to <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limits</span><span class="special">&lt;&gt;::</span><span class="identifier">infinity</span><span class="special">()</span></code>, provided <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limits</span><span class="special">&lt;&gt;::</span><span class="identifier">has_infinity</span>
@@ -388,7 +400,8 @@
<p>
For most purposes, you will much more likely want <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limits</span><span class="special">&lt;&gt;::</span><span class="identifier">max_digits10</span></code>,
the number of decimal digits that ensure that a change of one least significant
bit (ULP) produces a different decimal digits string.
bit (<a href="http://en.wikipedia.org/wiki/Unit_in_the_last_place" target="_top">Unit
in the last place (ULP)</a>) produces a different decimal digits string.
</p>
<p>
For the most common <code class="computeroutput"><span class="keyword">double</span></code>
@@ -596,10 +609,14 @@
<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span><span class="special">.</span><span class="identifier">precision</span><span class="special">(</span><span class="identifier">max_digits10</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;());</span>
<span class="preprocessor">#else</span>
<span class="preprocessor">#if</span><span class="special">(</span><span class="identifier">_MSC_VER</span> <span class="special">&lt;=</span> <span class="number">1600</span><span class="special">)</span>
<span class="comment">// Wrong value for std::numeric_limits&lt;float&gt;::max_digits10.</span>
<span class="comment">// The MSVC 2010 version had the wrong value for std::numeric_limits&lt;float&gt;::max_digits10.</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span><span class="special">.</span><span class="identifier">precision</span><span class="special">(</span><span class="identifier">max_digits10</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;());</span>
<span class="preprocessor">#else</span> <span class="comment">// Use the C++11 max_digits10.</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span><span class="special">.</span><span class="identifier">precision</span><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limits</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;::</span><span class="identifier">max_digits10</span><span class="special">);</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span><span class="special">.</span><span class="identifier">precision</span><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limits</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;::</span><span class="identifier">digits10</span><span class="special">);</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span><span class="special">.</span><span class="identifier">setf</span><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">ios_base</span><span class="special">::</span><span class="identifier">showpoint</span><span class="special">);</span> <span class="comment">// Append any trailing zeros,</span>
<span class="comment">// or more memorably</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">showpoint</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">// </span>
<span class="preprocessor">#endif</span>
<span class="preprocessor">#endif</span>
@@ -726,7 +743,7 @@
</p>
<p>
Generally true for <code class="computeroutput"><span class="identifier">is_iec559</span></code>
floating-point built-in types, but false for integer types.
floating-point __fundamantal types, but false for integer types.
</p>
<p>
Standard-compliant IEEE 754 floating-point implementations may detect the
@@ -36,7 +36,8 @@
then returns <code class="computeroutput"><span class="identifier">T</span><span class="special">()</span></code>.
</p>
<p>
For built-in types there is usually a corresponding MACRO value TYPE_MAX,
For <a href="https://en.cppreference.com/w/cpp/language/types" target="_top">fundamental
(built-in)</a> types there is usually a corresponding MACRO value TYPE_MAX,
where TYPE is CHAR, INT, FLOAT etc.
</p>
<p>
@@ -85,8 +86,9 @@
can be represented by the type T.
</p>
<p>
For built-in types, there is usually a corresponding MACRO value TYPE_MIN,
where TYPE is CHAR, INT, FLOAT etc.
For <a href="https://en.cppreference.com/w/cpp/language/types" target="_top">fundamental
(built-in)</a> types, there is usually a corresponding MACRO value
TYPE_MIN, where TYPE is CHAR, INT, FLOAT etc.
</p>
<p>
Other types, including those provided by a <code class="computeroutput"><span class="keyword">typedef</span></code>,
@@ -158,8 +160,9 @@
</h5>
<p>
Function <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limits</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;::</span><span class="identifier">round_error</span><span class="special">()</span></code>
returns the maximum error (in units of <a href="http://en.wikipedia.org/wiki/Unit_in_the_last_place" target="_top">ULP</a>)
that can be caused by any basic arithmetic operation.
returns the maximum error (in units of <a href="http://en.wikipedia.org/wiki/Unit_in_the_last_place" target="_top">Unit
in the last place (ULP)</a>) that can be caused by any basic arithmetic
operation.
</p>
<pre class="programlisting"><span class="identifier">round_style</span> <span class="special">==</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">round_indeterminate</span><span class="special">;</span>
</pre>
@@ -276,7 +279,9 @@
<p>
The C++ standard specifies <a href="https://en.cppreference.com/w/cpp/types/numeric_limits/epsilon" target="_top"><code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limits</span><span class="special">&lt;&gt;::</span><span class="identifier">epsilon</span><span class="special">()</span></code></a>
and Boost.Multiprecision implements this (where possible) for its program-defined
types analogous to the __fundamental floating-point types like <code class="computeroutput"><span class="keyword">double</span></code> <code class="computeroutput"><span class="keyword">float</span></code>.
types analogous to the <a href="https://en.cppreference.com/w/cpp/language/types" target="_top">fundamental
(built-in)</a> floating-point types like <code class="computeroutput"><span class="keyword">double</span></code>
<code class="computeroutput"><span class="keyword">float</span></code>.
</p>
<p>
For more information than you probably want (but still need) see <a href="http://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html" target="_top">What
@@ -395,11 +400,13 @@
</p>
<p>
This implementation-defined-ness has hampered use of infinity (and NaNs)
but Boost.Math and Boost.Multiprecision work hard to provide a sensible
representation for <span class="bold"><strong>all</strong></span> floating-point
types, not just the built-in types, which with the use of suitable facets
to define the input and output strings, makes it possible to use these
useful features portably and including Boost.Serialization.
but <a href="https://www.boost.org/doc/libs/release/libs/math/doc/index.html" target="_top">Boost.Math</a>
and <a href="https://www.boost.org/doc/libs/release/libs/multiprecision/doc/index.html" target="_top">Boost.Multiprecision</a>
work hard to provide a sensible representation for <span class="bold"><strong>all</strong></span>
floating-point types, not just the <a href="https://en.cppreference.com/w/cpp/language/types" target="_top">fundamental
(built-in) types</a>, which with the use of suitable facets to define
the input and output strings, makes it possible to use these useful features
portably and including <a href="https://www.boost.org/doc/libs/release/libs/serialization/doc/index.html" target="_top">Boost.Serialization</a>.
</p>
<h5>
<a name="boost_multiprecision.tut.limits.functions.h8"></a>
+66 -27
View File
@@ -156,9 +156,7 @@
<p>
Examples:
</p>
<pre class="programlisting"><span class="comment">//</span>
<span class="comment">// Any use of user defined literals requires that we import the literal-operators</span>
<span class="comment">// into current scope first:</span>
<pre class="programlisting"><span class="comment">// Any use of user defined literals requires that we import the literal-operators into current scope first:</span>
<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><span class="identifier">literals</span><span class="special">;</span>
<span class="comment">//</span>
<span class="comment">// To keep things simple in the example, we'll make our types used visible to this scope as well:</span>
@@ -179,21 +177,22 @@
<span class="comment">// Constants can be padded out with leading zeros to generate wider types:</span>
<span class="keyword">constexpr</span> <span class="identifier">uint256_t</span> <span class="identifier">e</span> <span class="special">=</span> <span class="number">0</span><span class="identifier">x0000000000000000000000000000000000000000000FFFFFFFFFFFFFFFFFFFFF_cppui</span><span class="special">;</span> <span class="comment">// OK</span>
<span class="comment">//</span>
<span class="comment">// However, specific width types are best produced with specific-width suffixes,</span>
<span class="comment">// However, specific-width types are best produced with specific-width suffixes,</span>
<span class="comment">// ones supported by default are `_cpp[u]i128`, `_cpp[u]i256`, `_cpp[u]i512`, `_cpp[u]i1024`.</span>
<span class="comment">//</span>
<span class="keyword">constexpr</span> <span class="identifier">int128_t</span> <span class="identifier">f</span> <span class="special">=</span> <span class="number">0x1234</span><span class="identifier">_cppi128</span><span class="special">;</span> <span class="comment">// OK, always produces an int128_t as the result.</span>
<span class="keyword">constexpr</span> <span class="identifier">uint1024_t</span> <span class="identifier">g</span> <span class="special">=</span> <span class="number">0</span><span class="identifier">xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbbbbbbccccccccccccccccccccc_cppui1024</span><span class="special">;</span>
<span class="keyword">constexpr</span> <span class="identifier">uint1024_t</span> <span class="identifier">g</span> <span class="special">=</span> <span class="number">0</span><span class="identifier">xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbbbbbbccccccccccccccccccccc_cppui1024</span><span class="special">;</span> <span class="comment">// OK,</span>
<span class="comment">// always produces an uint1024_t as the result.</span>
<span class="comment">//</span>
<span class="comment">// If other specific width types are required, then there is a macro for generating the operators</span>
<span class="comment">// for these. The macro can be used at namespace scope only:</span>
<span class="comment">// If other specific-width types are required, then there is a macro for generating the operators for these.</span>
<span class="comment">// The macro can be used at namespace scope only:</span>
<span class="comment">//</span>
<span class="identifier">BOOST_MP_DEFINE_SIZED_CPP_INT_LITERAL</span><span class="special">(</span><span class="number">2048</span><span class="special">);</span>
<span class="comment">//</span>
<span class="comment">// Now we can create 2048-bit literals as well:</span>
<span class="keyword">constexpr</span> <span class="keyword">auto</span> <span class="identifier">h</span> <span class="special">=</span> <span class="number">0xff</span><span class="identifier">_cppi2048</span><span class="special">;</span> <span class="comment">// h is of type number&lt;cpp_int_backend&lt;2048,2048,signed_magnitude,unchecked,void&gt; &gt;</span>
<span class="comment">//</span>
<span class="comment">// Finally negative values are handled via the unary minus operator:</span>
<span class="comment">// Finally, negative values are handled via the unary minus operator:</span>
<span class="comment">//</span>
<span class="keyword">constexpr</span> <span class="identifier">int1024_t</span> <span class="identifier">i</span> <span class="special">=</span> <span class="special">-</span><span class="number">0</span><span class="identifier">xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF_cppui1024</span><span class="special">;</span>
<span class="comment">//</span>
@@ -207,7 +206,7 @@
</h5>
<p>
The front end of the library is all <code class="computeroutput"><span class="keyword">constexpr</span></code>
from C++14 and later. Currently there are only two back end types that are
from C++14 and later. Currently there are only two backend types that are
<code class="computeroutput"><span class="keyword">constexpr</span></code> aware: <a class="link" href="floats/float128.html" title="float128">float128</a>
and <a class="link" href="ints/cpp_int.html" title="cpp_int">cpp_int</a>.
More backends will follow at a later date.
@@ -238,10 +237,17 @@
or GCC-6 or later in C++14 mode. Compilers other than GCC and without <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">is_constant_evaluated</span><span class="special">()</span></code> will support a very limited set of operations:
expect to hit roadblocks rather easily.
</p>
<p>
See <a href="https://en.cppreference.com/w/cpp/compiler_support" target="_top">compiler
support</a> for <a href="https://en.cppreference.com/w/cpp/types/is_constant_evaluated" target="_top"><code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">is_constant_evaluated</span></code></a>;
</p>
<p>
For example given:
</p>
<pre class="programlisting"><span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">&gt;</span>
<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">math</span><span class="special">/</span><span class="identifier">constants</span><span class="special">/</span><span class="identifier">constants</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span> <span class="comment">// For constant pi with full precision of type T.</span>
<span class="comment">// using boost::math::constants::pi;</span>
<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">&gt;</span>
<span class="keyword">inline</span> <span class="keyword">constexpr</span> <span class="identifier">T</span> <span class="identifier">circumference</span><span class="special">(</span><span class="identifier">T</span> <span class="identifier">radius</span><span class="special">)</span>
<span class="special">{</span>
<span class="keyword">return</span> <span class="number">2</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">constants</span><span class="special">::</span><span class="identifier">pi</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;()</span> <span class="special">*</span> <span class="identifier">radius</span><span class="special">;</span>
@@ -254,7 +260,7 @@
<span class="special">}</span>
</pre>
<p>
We can now calculate areas and circumferences using all constexpr arithmetic:
We can now calculate areas and circumferences, using all compile-time <code class="computeroutput"><span class="keyword">constexpr</span></code> arithmetic:
</p>
<pre class="programlisting"><span class="keyword">using</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>
@@ -266,9 +272,16 @@
<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="string">"Area = "</span> <span class="special">&lt;&lt;</span> <span class="identifier">a</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>
</pre>
<p>
Note that these make use of the numeric constants from the Math library,
which also happen to be <code class="computeroutput"><span class="keyword">constexpr</span></code>.
Note that these make use of the numeric constants from the <a href="https://www.boost.org/doc/libs/release/libs/math/doc/html/math_toolkit/constants.html" target="_top">Boost.Math
constants</a> library, which also happen to be <code class="computeroutput"><span class="keyword">constexpr</span></code>.
These usually have the full precision of the floating-point type, here 128-bit,
about 36 decimal digits.
</p>
<h6>
<a name="boost_multiprecision.tut.lits.h2"></a>
<span class="phrase"><a name="boost_multiprecision.tut.lits.hermite_poly_coeffics"></a></span><a class="link" href="lits.html#boost_multiprecision.tut.lits.hermite_poly_coeffics">Calculating
Hermite Polynomial coefficients at compile time</a>
</h6>
<p>
For a more interesting example, in <a href="../../../../example/constexpr_float_arithmetic_examples.cpp" target="_top">constexpr_float_arithmetic_examples.cpp</a>
we define a simple class for <code class="computeroutput"><span class="keyword">constexpr</span></code>
@@ -279,8 +292,8 @@
</pre>
<p>
Given this, we can use recurrence relations to calculate the coefficients
for various orthogonal polynomials - in the example we use the Hermite polynomials,
only the constructor does any work - it uses the recurrence relations to
for various orthogonal polynomials - in the example we use the Hermite polynomials.
Only the constructor does any work - it uses the recurrence relations to
calculate the coefficient array:
</p>
<pre class="programlisting"><span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">,</span> <span class="keyword">unsigned</span> <span class="identifier">Order</span><span class="special">&gt;</span>
@@ -308,7 +321,8 @@
<span class="special">};</span>
</pre>
<p>
Now we just need to define H<sub>0</sub> and H<sub>1</sub> as termination conditions for the recurrence:
Now we just need to define <span class="emphasis"><em>H<sub>0</sub></em></span> and <span class="emphasis"><em>H<sub>1</sub></em></span>
as termination conditions for the recurrence:
</p>
<pre class="programlisting"><span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">&gt;</span>
<span class="keyword">class</span> <span class="identifier">hermite_polynomial</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">,</span> <span class="number">0</span><span class="special">&gt;</span>
@@ -355,8 +369,9 @@
<span class="special">};</span>
</pre>
<p>
We can now declare H<sub>9</sub> as a constexpr object, access the coefficients, and
evaluate at an abscissa value, all using <code class="computeroutput"><span class="keyword">constexpr</span></code>
We can now declare <span class="emphasis"><em>H<sub>9</sub></em></span> as a <code class="computeroutput"><span class="keyword">constexpr</span></code>
object, access the coefficients, and evaluate at an abscissa value, all at
compile-time using <code class="computeroutput"><span class="keyword">constexpr</span></code>
arithmetic:
</p>
<pre class="programlisting"><span class="keyword">constexpr</span> <span class="identifier">hermite_polynomial</span><span class="special">&lt;</span><span class="identifier">float128</span><span class="special">,</span> <span class="number">9</span><span class="special">&gt;</span> <span class="identifier">h9</span><span class="special">;</span>
@@ -375,20 +390,26 @@
<span class="keyword">static_assert</span><span class="special">(</span><span class="identifier">h9</span><span class="special">[</span><span class="number">9</span><span class="special">]</span> <span class="special">==</span> <span class="number">512</span><span class="special">);</span>
<span class="comment">//</span>
<span class="comment">// Define an abscissa value to evaluate at:</span>
<span class="comment">//</span>
<span class="keyword">constexpr</span> <span class="identifier">float128</span> <span class="identifier">abscissa</span><span class="special">(</span><span class="number">0.5</span><span class="special">);</span>
<span class="comment">//</span>
<span class="comment">// Evaluate H_9(0.5) using all constexpr arithmetic:</span>
<span class="comment">//</span>
<span class="comment">// Evaluate H_9(0.5) using all constexpr arithmetic, and check that it has the expected result:</span>
<span class="keyword">static_assert</span><span class="special">(</span><span class="identifier">h9</span><span class="special">(</span><span class="identifier">abscissa</span><span class="special">)</span> <span class="special">==</span> <span class="number">6481</span><span class="special">);</span>
</pre>
<p>
Also since the coefficients to the Hermite polynomials are integers, we can
also generate the Hermite coefficients using (fixed precision) cpp_int's:
see <a href="../../../../test/constexpr_test_cpp_int_6.cpp" target="_top">constexpr_test_cpp_int_6.cpp</a>.
See <a href="../../../../example/constexpr_float_arithmetic_examples.cpp" target="_top">constexpr_float_arithmetic_examples.cpp</a>
for working code.
</p>
<p>
We can also generate factorials (and validate the result) like so:
Also since the coefficients to the Hermite polynomials are integers, we can
also generate the Hermite coefficients using (fixed precision) <code class="computeroutput"><span class="identifier">cpp_int</span></code>s: see <a href="../../../../test/constexpr_test_cpp_int_6.cpp" target="_top">constexpr_test_cpp_int_6.cpp</a>.
</p>
<h6>
<a name="boost_multiprecision.tut.lits.h3"></a>
<span class="phrase"><a name="boost_multiprecision.tut.lits.factorial_constexpr"></a></span><a class="link" href="lits.html#boost_multiprecision.tut.lits.factorial_constexpr"><code class="computeroutput"><span class="keyword">constexpr</span></code> Factorials</a>
</h6>
<p>
We can also generate integer factorials in <a href="../../test/constexpr_test_cpp_int_5.cpp" target="_top">constexpr_test_cpp_int_5.cpp</a>
like so:
</p>
<pre class="programlisting"><span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">&gt;</span>
<span class="keyword">constexpr</span> <span class="identifier">T</span> <span class="identifier">factorial</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">T</span><span class="special">&amp;</span> <span class="identifier">a</span><span class="special">)</span>
@@ -396,12 +417,30 @@
<span class="keyword">return</span> <span class="identifier">a</span> <span class="special">?</span> <span class="identifier">a</span> <span class="special">*</span> <span class="identifier">factorial</span><span class="special">(</span><span class="identifier">a</span> <span class="special">-</span> <span class="number">1</span><span class="special">)</span> <span class="special">:</span> <span class="number">1</span><span class="special">;</span>
<span class="special">}</span>
</pre>
<pre class="programlisting"><span class="keyword">constexpr</span> <span class="identifier">uint1024_t</span> <span class="identifier">f1</span> <span class="special">=</span> <span class="identifier">factorial</span><span class="special">(</span><span class="identifier">uint1024_t</span><span class="special">(</span><span class="number">31</span><span class="special">));</span>
<span class="keyword">static_assert</span><span class="special">(</span><span class="identifier">f1</span> <span class="special">==</span> <span class="number">0</span><span class="identifier">x1956ad0aae33a4560c5cd2c000000_cppi</span><span class="special">);</span>
<p>
and validate the result:
</p>
<pre class="programlisting"><span class="keyword">constexpr</span> <span class="identifier">uint1024_t</span> <span class="identifier">f1</span> <span class="special">=</span> <span class="identifier">factorial</span><span class="special">(</span><span class="identifier">uint1024_t</span><span class="special">(</span><span class="number">31</span><span class="special">));</span> <span class="comment">// Factorial 31!</span>
<span class="keyword">static_assert</span><span class="special">(</span><span class="identifier">f1</span> <span class="special">==</span> <span class="number">0</span><span class="identifier">x1956ad0aae33a4560c5cd2c000000_cppi</span><span class="special">);</span> <span class="comment">// Expected result as an Boost.Multiprecision integer literal. </span>
</pre>
<h6>
<a name="boost_multiprecision.tut.lits.h4"></a>
<span class="phrase"><a name="boost_multiprecision.tut.lits.random_constexpr"></a></span><a class="link" href="lits.html#boost_multiprecision.tut.lits.random_constexpr">Random
<code class="computeroutput"><span class="keyword">constexpr</span></code> values</a>
</h6>
<p>
Another example in <a href="../../../../test/constexpr_test_cpp_int_7.cpp" target="_top">constexpr_test_cpp_int_7.cpp</a>
generates a fresh multiprecision random number each time the file is compiled.
It includes an C++ template implementation of the <a href="https://en.wikipedia.org/wiki/KISS_(algorithm)" target="_top">KISS
random number algorithm by George Marsaglia</a> for <code class="computeroutput"><span class="identifier">cpp_int</span></code>
integers.
</p>
<pre class="programlisting"><span class="keyword">constexpr</span> <span class="identifier">uint1024_t</span> <span class="identifier">rand</span> <span class="special">=</span> <span class="identifier">nth_random_value</span><span class="special">&lt;</span><span class="identifier">uint1024_t</span><span class="special">&gt;(</span><span class="number">1000</span><span class="special">);</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">hex</span> <span class="special">&lt;&lt;</span> <span class="identifier">rand</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>
</pre>
<p>
See also the <a class="link" href="random.html" title="Generating Random Numbers">random number
generation</a> section.
</p>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
+2 -2
View File
@@ -149,10 +149,10 @@
With Optimized Mixed Precision Arithmetic</a>
</h5>
<p>
The following backends have at least some direct support for mixed precision
The following backends have at least some direct support for mixed-precision
arithmetic, and therefore avoid creating unnecessary temporaries when using
the interfaces above. Therefore when using these types it's more efficient
to use mixed precision arithmetic, than it is to explicitly cast the operands
to use mixed-precision arithmetic, than it is to explicitly cast the operands
to the result type:
</p>
<p>
+15 -3
View File
@@ -1,4 +1,4 @@
# \libs\math\example\jamfile.v2
# \libs\multiprecision\example\jamfile.v2
# Runs multiprecision examples.
# Copyright 2014 John Maddock
# Copyright Paul A. Bristow 2014.
@@ -7,7 +7,7 @@
# Distributed under the Boost Software License, Version 1.0.
# (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
# bring in the rules for testing
# Bring in the rules for testing.
import testing ;
import modules ;
import path ;
@@ -60,7 +60,19 @@ project
<toolset>msvc:<cxxflags>/wd4701
<toolset>msvc:<cxxflags>/wd4127
<toolset>msvc:<cxxflags>/wd4305
;
<toolset>clang-win:<link>static # Clang-win does not generate .dlls.
<toolset>clang:<link>static # Clang-linux does not generate .dlls.
<toolset>clang:<cxxflags>-Wno-unused-variable # warning: unused variable 'tolerance' [-Wunused-variable]
<toolset>clang:<cxxflags>-Wno-delete-non-abstract-non-virtual-dtor # delete called on non-final that has virtual functions but non-virtual destructor.
# This does not seem to suppress the warning in boost exception
<toolset>clang:<cxxflags>-Wno-unused-comparison # warning: equality comparison result unused.
<toolset>clang:<cxxflags>-Wno-unused-variable # unused variable 'd'.
<toolset>clang:<cxxflags>-Wno-unused-value # warning: expression result unused.
<toolset>clang:<cxxflags>-Wno-unused-const-variable
<toolset>clang:<cxxflags>-Wno-unused-local-typedef
<toolset>clang:<cxxflags>-Wno-self-assign-overloaded # explicitly assigning value of variable of type 'Real' to itself.
# <toolset>clang:<cxxflags>-v
; # project
lib gmp : : <search>$(gmp_path) ;
lib mpfr : : <search>$(gmp_path) <search>$(mpfr_path) <search>$(mpfr_path)/build.vc10/lib/Win32/Debug ;
+16 -10
View File
@@ -3,13 +3,18 @@
// Boost Software License, Version 1.0. (See accompanying file
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
// Contains Quickbook snippets used by boost/libs/multiprecision/doc/multiprecision.qbk,
// section Literal Types and constexpr Support.
#include <iostream>
#include <boost/math/constants/constants.hpp>
#ifdef BOOST_HAS_FLOAT128
#include <boost/multiprecision/float128.hpp>
#endif
//[constexpr_circle
#include <boost/math/constants/constants.hpp> // For constant pi with full precision of type T.
// using boost::math::constants::pi;
template <class T>
inline constexpr T circumference(T radius)
@@ -22,7 +27,7 @@ inline constexpr T area(T radius)
{
return boost::math::constants::pi<T>() * radius * radius;
}
//]
//] [/constexpr_circle]
template <class T, unsigned Order>
struct const_polynomial
@@ -35,7 +40,7 @@ struct const_polynomial
constexpr const_polynomial(const std::initializer_list<T>& init) : data{}
{
if (init.size() > Order + 1)
throw std::range_error("Too many initializers in list");
throw std::range_error("Too many initializers in list!");
for (unsigned i = 0; i < init.size(); ++i)
data[i] = init.begin()[i];
}
@@ -208,7 +213,8 @@ class hermite_polynomial
return m_data(val);
}
};
//]
//] [/hermite_example]
//[hermite_example2
template <class T>
class hermite_polynomial<T, 0>
@@ -253,7 +259,8 @@ class hermite_polynomial<T, 1>
return m_data(val);
}
};
//]
//] [/hermite_example2]
void test_double()
{
@@ -315,7 +322,7 @@ void test_double()
void test_float128()
{
#ifdef BOOST_HAS_FLOAT128
//[constexpr_circle_usage
//[constexpr_circle_usage
using boost::multiprecision::float128;
@@ -326,7 +333,8 @@ void test_float128()
std::cout << "Circumference = " << c << std::endl;
std::cout << "Area = " << a << std::endl;
//]
//] [/constexpr_circle_usage]
constexpr hermite_polynomial<float128, 2> h1;
static_assert(h1[0] == -2);
@@ -356,11 +364,9 @@ void test_float128()
static_assert(h9[9] == 512);
//
// Define an abscissa value to evaluate at:
//
constexpr float128 abscissa(0.5);
//
// Evaluate H_9(0.5) using all constexpr arithmetic:
//
// Evaluate H_9(0.5) using all constexpr arithmetic, and check that it has the expected result:
static_assert(h9(abscissa) == 6481);
//]
#endif
+6 -2
View File
@@ -6,6 +6,7 @@
//[cpp_bin_float_eg
#include <boost/multiprecision/cpp_bin_float.hpp>
#include <boost/math/special_functions/gamma.hpp>
#include <iostream>
int main()
@@ -16,14 +17,17 @@ int main()
cpp_bin_float_100 b = 2;
std::cout << std::numeric_limits<cpp_bin_float_100>::digits << std::endl;
std::cout << std::numeric_limits<cpp_bin_float_100>::digits10 << std::endl;
// We can use any C++ std lib function, lets print all the digits as well:
std::cout << std::setprecision(std::numeric_limits<cpp_bin_float_100>::max_digits10)
std::cout << std::setprecision(std::numeric_limits<cpp_bin_float_100>::max_digits10)
<< log(b) << std::endl; // print log(2)
// We can also use any function from Boost.Math:
std::cout << boost::math::tgamma(b) << std::endl;
// These even work when the argument is an expression template:
std::cout << boost::math::tgamma(b * b) << std::endl;
// And since we have an extended exponent range we can generate some really large
// And since we have an extended exponent range we can generate some really large
// numbers here (4.0238726007709377354370243e+2564):
std::cout << boost::math::tgamma(cpp_bin_float_100(1000)) << std::endl;
return 0;
+66 -15
View File
@@ -3,6 +3,9 @@
// Software License, Version 1.0. (See accompanying file
// LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt
// Demonstrations of using Boost.Multiprecision float128 type.
// Contains Quickbook markup in comments.
//[float128_eg
#include <boost/multiprecision/float128.hpp>
#include <boost/math/special_functions/gamma.hpp>
@@ -10,33 +13,81 @@
int main()
{
using namespace boost::multiprecision;
using namespace boost::multiprecision; // Potential to cause name collisions?
// using boost::multiprecision::float128; // is safer.
// Operations at 128-bit precision and full numeric_limits support:
/*`The type float128 provides operations at 128-bit precision with
[@https://en.wikipedia.org/wiki/Quadruple-precision_floating-point_format#IEEE_754_quadruple-precision_binary_floating-point_format:_binary128 Quadruple-precision floating-point format]
and have full `std::numeric_limits` support:
*/
float128 b = 2;
// There are 113-bits of precision:
//` There are 15 bits of (biased) binary exponent and 113-bits of significand precision
std::cout << std::numeric_limits<float128>::digits << std::endl;
// Or 34 decimal places:
//` or 33 decimal places:
std::cout << std::numeric_limits<float128>::digits10 << std::endl;
// We can use any C++ std lib function, lets print all the digits as well:
std::cout << std::setprecision(std::numeric_limits<float128>::max_digits10)
<< log(b) << std::endl; // print log(2) = 0.693147180559945309417232121458176575
// We can also use any function from Boost.Math:
//` We can use any C++ std library function, so let's show all the at-most 36 potentially significant digits, and any trailing zeros, as well:
std::cout.setf(std::ios_base::showpoint); // Include any trailing zeros.
std::cout << std::setprecision(std::numeric_limits<float128>::max_digits10)
<< log(b) << std::endl; // Shows log(2) = 0.693147180559945309417232121458176575
//` We can also use any function from Boost.Math, for example, the 'true gamma' function `tgamma`:
std::cout << boost::math::tgamma(b) << std::endl;
// And since we have an extended exponent range we can generate some really large
// numbers here (4.02387260077093773543702433923004111e+2564):
/*` And since we have an extended exponent range, we can generate some really large
numbers here (4.02387260077093773543702433923004111e+2564):
*/
std::cout << boost::math::tgamma(float128(1000)) << std::endl;
//
// We can declare constants using GCC or Intel's native types, and the Q suffix,
// these can be declared constexpr if required:
/*` We can declare constants using GCC or Intel's native types, and literals with the Q suffix, and these can be declared `constexpr` if required:
*/
/*<-*/
#ifndef BOOST_NO_CXX11_CONSTEXPR
/*->*/
constexpr float128 pi = 3.1415926535897932384626433832795028841971693993751058Q;
constexpr float128 pi = 3.14159265358979323846264338327950Q;
/*<-*/
#endif
/*->*/
//] [/float128_eg]
return 0;
}
//]
/*
//[float128_numeric_limits
GCC 8.1.0
Type name is float128_t:
Type is g
std::is_fundamental<> = true
std::is_signed<> = true
std::is_unsigned<> = false
std::is_integral<> = false
std::is_arithmetic<> = true
std::is_const<> = false
std::is_trivial<> = true
std::is_standard_layout<> = true
std::is_pod<> = true
std::numeric_limits::<>is_exact = false
std::numeric_limits::<>is bounded = true
std::numeric_limits::<>is_modulo = false
std::numeric_limits::<>is_iec559 = true
std::numeric_limits::<>traps = false
std::numeric_limits::<>tinyness_before = false
std::numeric_limits::<>max() = 1.18973149535723176508575932662800702e+4932
std::numeric_limits::<>min() = 3.36210314311209350626267781732175260e-4932
std::numeric_limits::<>lowest() = -1.18973149535723176508575932662800702e+4932
std::numeric_limits::<>min_exponent = -16381
std::numeric_limits::<>max_exponent = 16384
std::numeric_limits::<>epsilon() = 1.92592994438723585305597794258492732e-34
std::numeric_limits::<>radix = 2
std::numeric_limits::<>digits = 113
std::numeric_limits::<>digits10 = 33
std::numeric_limits::<>max_digits10 = 36
std::numeric_limits::<>has denorm = true
std::numeric_limits::<>denorm min = 6.47517511943802511092443895822764655e-4966
std::denorm_loss = false
limits::has_signaling_NaN == false
std::numeric_limits::<>quiet_NaN = nan
std::numeric_limits::<>infinity = inf
//] [/float128_numeric_limits]
*/
+27 -10
View File
@@ -7,17 +7,10 @@
// (See accompanying file LICENSE_1_0.txt
// or copy at http://www.boost.org/LICENSE_1_0.txt)
// Examples of numeric_limits usage as snippets for multiprecision documentation.
// Examples of std::numeric_limits usage as snippets for multiprecision documentation at multiprecision.qbk.
// Includes text as Quickbook comments.
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <limits> // numeric_limits
#include <iomanip>
#include <locale>
#include <boost/assert.hpp>
#include <boost/math/constants/constants.hpp>
@@ -33,7 +26,27 @@
#include <boost/test/unit_test.hpp> // Boost.Test
#include <boost/test/floating_point_comparison.hpp>
static long double const log10Two = 0.30102999566398119521373889472449L; // log10(2.)
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <limits> // numeric_limits
#include <iomanip>
#include <locale>
// static long double const log10Two = 0.30102999566398119521373889472449L; // log10(2.)
// It is more portable useful to use a Boost macro
// See https://www.boost.org/doc/libs/release/libs/config/doc/html/boost_config/boost_macro_reference.html
BOOST_STATIC_CONSTEXPR long double log10Two = 0.30102999566398119521373889472449L;
// which expands to static constexpr on standard C++11 and up, but static const on earlier versions.
/*`By default, output would only show the standard 6 decimal digits,
so set precision to show all 50 significant digits, including any trailing zeros.
This is generally useful to show the implicit precision of the type of the value.
*/
template <typename T>
int max_digits10()
@@ -66,10 +79,14 @@ BOOST_AUTO_TEST_CASE(test_numeric_limits_snips)
std::cout.precision(max_digits10<T>());
#else
#if(_MSC_VER <= 1600)
// Wrong value for std::numeric_limits<float>::max_digits10.
// The MSVC 2010 version had the wrong value for std::numeric_limits<float>::max_digits10.
std::cout.precision(max_digits10<T>());
#else // Use the C++11 max_digits10.
std::cout.precision(std::numeric_limits<T>::max_digits10);
std::cout.precision(std::numeric_limits<T>::digits10);
std::cout.setf(std::ios_base::showpoint); // Append any trailing zeros,
// or more memorably
std::cout << std::showpoint << std::endl; //
#endif
#endif
@@ -8,7 +8,6 @@
#include <limits>
#include <boost/utility/enable_if.hpp>
#include <boost/core/nvp.hpp>
#include <boost/type_traits/is_convertible.hpp>
#include <boost/type_traits/is_constructible.hpp>
#include <boost/type_traits/decay.hpp>
@@ -49,6 +48,7 @@
#define BOOST_MP_THREAD_LOCAL
#endif
// Test if the std library provides std::is_constant_evaluated() and signal by defining BOOST_MP_HAS_IS_CONSTANT_EVALUATED
#ifdef __has_include
# if __has_include(<version>)
# include <version>
@@ -59,18 +59,23 @@
# endif
#endif
#ifdef __has_builtin
#if __has_builtin(__builtin_is_constant_evaluated) && !defined(BOOST_NO_CXX14_CONSTEXPR) && !defined(BOOST_NO_CXX11_UNIFIED_INITIALIZATION_SYNTAX)
#define BOOST_MP_CLANG_CD
#endif
#endif
// BOOST_MP_HAS_IS_CONSTANT_EVALUATED(x) controls how to do std::is_constant_evaluated() or equivalents.
// Use the real std::is_constant_evaluated() if the std library provides it.
#if defined(BOOST_MP_HAS_IS_CONSTANT_EVALUATED) && !defined(BOOST_NO_CXX14_CONSTEXPR)
# define BOOST_MP_IS_CONST_EVALUATED(x) std::is_constant_evaluated()
#elif (defined(BOOST_GCC) && !defined(BOOST_NO_CXX14_CONSTEXPR) && (__GNUC__ >= 9)) || defined(BOOST_MP_CLANG_CD)
// if not look for an equivalent builtin function (Clang and GCC)
// Might check first for #ifdef __has_builtin although we know that Clang >= 9 has this anyway?
#elif defined(BOOST_GCC) && !defined(BOOST_NO_CXX14_CONSTEXPR) && (__GNUC__ >= 9)
# define BOOST_MP_IS_CONST_EVALUATED(x) __builtin_is_constant_evaluated()
#elif defined(BOOST_CLANG) && !defined(BOOST_NO_CXX14_CONSTEXPR) && (__clang_major__ >= 9)
# define BOOST_MP_IS_CONST_EVALUATED(x) __builtin_is_constant_evaluated()
// Older GCC
#elif !defined(BOOST_NO_CXX14_CONSTEXPR) && defined(BOOST_GCC) && (__GNUC__ >= 6)
# define BOOST_MP_IS_CONST_EVALUATED(x) __builtin_constant_p(x)
#else
# define BOOST_MP_NO_CONSTEXPR_DETECTION
#endif
@@ -104,6 +109,14 @@
#endif
namespace boost {
namespace serialization {
template <class T>
struct nvp;
template <class T>
const nvp<T> make_nvp(const char* name, T& t);
} // namespace serialization
namespace multiprecision {
enum expression_template_option
+6 -4
View File
@@ -30,7 +30,7 @@ local tommath_path = [ modules.peek : TOMMATH_PATH ] ;
# concepts
# examples
#
# You can run an individual suite by passing it's name to b2 on the command line.
# You can run an individual suite by passing its name to b2 on the command line.
# Or you can run all except the "specfun" tests (which are very slow) by not specifying anything.
#
# Please make sure that any new tests are added to one of the test suites, and that the
@@ -58,8 +58,11 @@ project : requirements
<toolset>msvc:<cxxflags>/fp\:precise
<toolset>intel-win:<runtime-link>static
<toolset>intel-win:<link>static
<toolset>clang-win:<link>static
<toolset>clang-win:<link>static # Clang-win does not generate .dlls.
<toolset>clang:<link>static # Clang-linux does not generate .dlls.
<toolset>clang:<cxxflags>-Wno-unused-variable # warning: unused variable 'tolerance' [-Wunused-variable]
<toolset>clang:<cxxflags>-v
# Assembler error "File too big" caused by lots of C++ templates, for example, math/floating_point_examples.cpp.
# Some projects on some toolsets may require
# <toolset>gcc-mingw:<cxxflags>\"-Wa,-mbig-obj\"
@@ -331,7 +334,6 @@ test-suite functions_and_limits :
[ check-target-builds ../config//has_mpfi : : <build>no ]
: test_numeric_limits_mpfi_50 ]
[ run test_numeric_limits.cpp quadmath no_eh_support
: # command line
: # input files
+2
View File
@@ -3,6 +3,8 @@
// Boost Software License, Version 1.0. (See accompanying file
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
// Contains Quickbook markup, using in Boost.Multiprecision.qbk section on Literals and constexpr, penultimate section on factorials.
#include "constexpr_arithmetric_test.hpp"
#include "boost/multiprecision/cpp_int.hpp"
#include "boost/multiprecision/integer.hpp"
+11 -3
View File
@@ -1,9 +1,16 @@
///////////////////////////////////////////////////////////////
// Copyright 2018 John Maddock. Distributed under the Boost
// Software License, Version 1.0. (See accompanying file
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt).
// Contains Quickbook snippets used by boost/libs/multiprecision/doc/multiprecision.qbk,
// used in section Literal Types and constexpr Support, last example on constexpr randoms.
// A implementation and demonstration of the Keep It Simple Stupid random number generator algorithm https://en.wikipedia.org/wiki/KISS_(algorithm) for cpp_int integers.
// b2 --abbreviate-paths toolset=clang-9.0.0 address-model=64 cxxstd=2a release misc > multiprecision_clang_misc.log
#include <boost/multiprecision/cpp_int.hpp>
#include <iostream>
struct kiss_rand
@@ -54,8 +61,7 @@ inline constexpr void hash_combine(std::uint64_t& h, std::uint64_t k)
h ^= k;
h *= m;
// Completely arbitrary number, to prevent 0's
// from hashing to 0.
// Completely arbitrary number, to prevent 0's from hashing to 0.
h += 0xe6546b64;
}
@@ -116,7 +122,9 @@ int main()
{
using namespace boost::multiprecision;
//[random_constexpr_cppint
constexpr uint1024_t rand = nth_random_value<uint1024_t>(1000);
std::cout << std::hex << rand << std::endl;
//] [/random_constexpr_cppint]
return 0;
}