From 9a2cf459dc04e2162d7ca42e7ee56df5965d2f2c Mon Sep 17 00:00:00 2001
From: jzmaddock A B C D E F H I L M N O P R S T V X Z BOOST_ASSERT constexpr convert_to e empty infinity integer_modulus cpp_dec_float_50 A B C D E F G H I L M N O P R S T U V X Z Bit Operations bits BOOST_ASSERT BOOST_MP_DEFINE_SIZED_CPP_INT_LITERAL constexpr Constructing and Interconverting Between Number Types cpp_dec_float_50 e empty infinity Input Output Literal Types and constexpr Support llrint std::numeric_limits<> constants std::numeric_limits<> functions std :: numeric_limits <> functions std::numeric_limits<> constants str
Multiprecision consists of a generic interface to the mathematics of large
- numbers as well as a selection of big number back ends, with support for integer,
+ numbers as well as a selection of big number back-ends, with support for integer,
rational, floating-point, and complex types. Boost.Multiprecision provides
- a selection of back ends provided off-the-rack in including interfaces to GMP,
+ a selection of back-ends provided off-the-rack in including interfaces to GMP,
MPFR, MPIR, MPC, TomMath as well as its own collection of Boost-licensed, header-only
- back ends for integers, rationals and floats. In addition, user-defined back
- ends can be created and used with the interface of Multiprecision, provided
- the class implementation adheres to the necessary concepts.
+ back-ends for integers, rationals and floats. In addition, user-defined back-ends
+ can be created and used with the interface of Multiprecision, provided the
+ class implementation adheres to the necessary concepts.
Depending upon the number type, precision may be arbitrarily large (limited
- only by available memory), fixed at compile time (for example 50 or 100 decimal
+ only by available memory), fixed at compile time (for example, 50 or 100 decimal
digits), or a variable controlled at run-time by member functions. The types
are expression
- template -enabled for better performance than naive user-defined types.
+ templates - enabled for better performance than naive user-defined
+ types.
The Multiprecision library comes in two distinct parts:
@@ -232,7 +234,7 @@
The great advantage of this method is the elimination of temporaries:
- for example the "naive" implementation of
In fact it is particularly easy to create dangling references by mixing expression
- templates with the auto keyword, for example:
+ templates with the
- In this situation the integer literal is stored directly in the expression
- template - so its use is OK here - but the cpp_dec_float_50 temporary is
- stored by reference and then destructed when the statement completes leaving
- a dangling reference.
+ In this situation, the integer literal is stored directly in the expression
+ template - so its use is OK here - but the
If in doubt, do not ever mix expression templates
- with the auto keyword.
+ with the
And finally... the performance improvements from an expression template library
like this are often not as dramatic as the reduction in number of temporaries
- would suggest. For example if we compare this library with mpfr_class
+ would suggest. For example, if we compare this library with mpfr_class
and mpreal, with
all three using the underlying MPFR
library at 50 decimal digits precision then we see the following typical results
@@ -720,7 +723,7 @@
[1]
The actual number generated will depend on the compiler, how well it optimizes
the code, and whether it supports rvalue references. The number of 11 temporaries
- was generated with Visual C++ 10
+ was generated with Visual C++ 2010.
+
operator* above, requires one temporary for computing
+ for example, the "naive" implementation of operator* above, requires one temporary for computing
the result, and at least another one to return it. It's true that sometimes
this overhead can be reduced by using move-semantics, but it can't be eliminated
completely. For example, lets suppose we're evaluating a polynomial via Horner's
@@ -374,28 +376,29 @@
auto keyword,
+ for example:
auto val
= cpp_dec_float_50("23.1") * 100;
cpp_dec_float_50
+ temporary is stored by reference and then destructed when the statement completes,
+ leaving a dangling reference.
auto keyword.
cpp_bin_50
+ and cpp_dec_50?
Unless you have a specific reason to choose cpp_dec_,
diff --git a/doc/html/boost_multiprecision/tut.html b/doc/html/boost_multiprecision/tut.html
index f92dc00a..34fcb293 100644
--- a/doc/html/boost_multiprecision/tut.html
+++ b/doc/html/boost_multiprecision/tut.html
@@ -91,7 +91,8 @@
constexpr Supportcpp_int
+ and cpp_bin_float
std::numeric_limits<> functionsnumber on this backend
move aware.
+constexpr
+ aware - basic constexpr arithmetic is supported from C++14 and onwards,
+ comparisons, plus the functions fabs,
+ abs, fpclassify, isnormal,
+ isfinite, isinf and isnan
+ are also supported if either the compiler implements C++20's std::is_constant_evaluated(),
+ or if the compiler is GCC.
+ <boost/multiprecision/integer.hpp>.
Where these operations require a temporary increase in precision (such as
- for powm), then if no built in type is available, a cpp_int
+ for powm), then if no built
+ in type is available, a cpp_int
of appropriate precision will be used.
@@ -161,7 +162,7 @@
The regular Miller-Rabin functions in <boost/multiprecision/miller_rabin.hpp>
are defined in terms of the above generic operations, and so function equally
- well for built in and multiprecision types.
+ well for built-in or __fundamental_types and multiprecision types.
Note that this function is optimized for the case where the data can be
- memcpy'ed from the source to the integer - in this case both iterators
- much be pointers, and everything must be little-endian.
+ |
@@ -199,7 +201,7 @@
import_bits(i, v.begin(), v.end());
cpp_bin_float_100 g(i);
g.backend().exponent() = e;
- assert(f == g);
+ BOOST_ASSERT(f == g);
}
diff --git a/doc/html/boost_multiprecision/tut/interval/mpfi.html b/doc/html/boost_multiprecision/tut/interval/mpfi.html
index 13c791fa..b4b9d7b1 100644
--- a/doc/html/boost_multiprecision/tut/interval/mpfi.html
+++ b/doc/html/boost_multiprecision/tut/interval/mpfi.html
@@ -54,11 +54,11 @@
Type mpfi_float_backend
can be used at fixed precision by specifying a non-zero Digits10
template parameter, or at variable precision by setting the template argument
- to zero. The typedefs mpfi_float_50, mpfi_float_100, mpfi_float_500, mpfi_float_1000
- provide arithmetic types at 50, 100, 500 and 1000 decimal digits precision
- respectively. The typedef mpfi_float provides a variable precision type
- whose precision can be controlled via the numbers
- member functions.
+ to zero. The typedefs mpfi_float_50, mpfi_float_100,
+ mpfi_float_500, mpfi_float_1000 provide arithmetic types
+ at 50, 100, 500 and 1000 decimal digits precision respectively. The typedef mpfi_float
+ provides a variable precision type whose precision can be controlled via
+ the numbers member functions.
![]() |
-Note | -
|---|---|
- The features described in this section make heavy use of C++11 language - features, currently (as of May 2013) only GCC-4.7 and later, and Clang - 3.3 and later have the support required to make these features work. - |
- There is limited support for constexpr
- and user-defined literals in the library, currently the number
- front end supports constexpr
- on default construction and all forwarding constructors, but not on any of
- the non-member operators. So if some type B
- is a literal type, then number<B>
- is also a literal type, and you will be able to compile-time-construct such
- a type from any literal that B
- is compile-time-constructible from. However, you will not be able to perform
- compile-time arithmetic on such types.
+ There are two kinds of constexpr
+ support in this library:
- Currently the only backend type provided by the library that is also a literal
- type are instantiations of cpp_int_backend
- where the Allocator parameter is type void,
- and the Checked parameter is boost::multiprecision::unchecked.
+ There are two backend types which are literals:
cpp_int_backend
+ where the Allocator parameter is type void,
+ and the Checked parameter is boost::multiprecision::unchecked.
+ For example:
using namespace boost::multiprecision; +constexpr float128 f = 0.1Q // OK, float128's are always literals in C++11 + constexpr int128_t i = 0; // OK, fixed precision int128_t has no allocator. constexpr uint1024_t j = 0xFFFFFFFF00000000uLL; // OK, fixed precision uint1024_t has no allocator. @@ -67,8 +73,8 @@ constexpr cpp_int l = 2; // Error, type is not a literal as it performs memory management.
- There is also limited support for user defined-literals - these are limited
- to unchecked, fixed precision cpp_int's
+ There is also limited support for user defined-literals with cpp_int
+ - these are limited to unchecked, fixed precision cpp_int's
which are specified in hexadecimal notation. The suffixes supported are:
| diff --git a/doc/html/index.html b/doc/html/index.html index f178b550..c0b9ef2a 100644 --- a/doc/html/index.html +++ b/doc/html/index.html @@ -107,7 +107,8 @@ |
Last revised: August 13, 2019 at 14:01:03 GMT |
+Last revised: August 30, 2019 at 15:57:26 GMT |
A B C D E F H I L M N O P R S T V X Z
BOOST_ASSERT
- -A B C D E F G H I L M N O P R S T U V X Z
Bit Operations
-bits
@@ -161,10 +158,6 @@BOOST_ASSERT
- -BOOST_MP_DEFINE_SIZED_CPP_INT_LITERAL
- Should you just wish to cut to the chase and use a fully Boost-licensed number - type, then skip to cpp_int - for multiprecision integers, cpp_rational - for rational types, cpp_dec_float - for multiprecision floating-point types and cpp_complex - for complex types. + Should you just wish to 'cut to the chase' just to get bigger integers or bigger + and more precise reals as simply and portably as possible, close to 'drop-in' + replacements for the fundamental + (built-in) type anlogs, then use a fully Boost-licensed number type, + and skip to: +
+
+ The library is very often used via one of the predefined convenience typedefs like boost::multiprecision::int128_t
+ or boost::multiprecision::cpp_bin_float_quad.
- The library is often used via one of the predefined typedefs: for example if - you wanted an arbitrary + For example, if you want a signed, 128-bit fixed size integer: +
+#include <boost/multiprecision/cpp_int.hpp> // Integer types. + +boost::multiprecision::int128_t my_128_bit_int; ++
+ Alternatively, and more adventurously, if you wanted an arbitrary precision integer type using GMP as the underlying implementation then you could use:
@@ -98,27 +131,37 @@ boost::multiprecision::mpz_int myint; // Arbitrary precision integer type.
- Alternatively, you can compose your own multiprecision type, by combining
+ Or for a simple, portable 128-bit floating-point close to a drop-in for a
+ fundamental (built-in)
+ type like double, usually
+ 64-bit
+
#include <boost/multiprecision/cpp_bin_float.hpp> + +boost::multiprecision::cpp_bin_float_quad my_quad_real; ++
+ Alternatively, you can compose your own 'custom' multiprecision type, by combining
number with one of the predefined
back-end types. For example, suppose you wanted a 300 decimal digit floating-point
type based on the MPFR library. In
- this case, there's no predefined typedef with that level of precision, so instead
- we compose our own:
+ this case, there's no predefined typedef
+ with that level of precision, so instead we compose our own:
#include <boost/multiprecision/mpfr.hpp> // Defines the Backend type that wraps MPFR +#include <boost/multiprecision/mpfr.hpp> // Defines the Backend type that wraps MPFR. namespace mp = boost::multiprecision; // Reduce the typing a bit later... typedef mp::number<mp::mpfr_float_backend<300> > my_float; -my_float a, b, c; // These variables have 300 decimal digits precision +my_float a, b, c; // These variables have 300 decimal digits precision.We can repeat the above example, but with the expression templates disabled (for faster compile times, but slower runtimes) by passing a second template argument to
-number:#include <boost/multiprecision/mpfr.hpp> // Defines the Backend type that wraps MPFR +#include <boost/multiprecision/mpfr.hpp> // Defines the Backend type that wraps MPFR. namespace mp = boost::multiprecision; // Reduce the typing a bit later... @@ -162,7 +205,7 @@ b = a * 3.14; // Error, no operator overload if the conversion would be explicit.- + Move Semantics
@@ -202,7 +245,7 @@ library containers.- + Expression Templates
@@ -226,11 +269,11 @@ unmentionable-type operator * (const number<Backend>& a, const number<Backend>& b);- Where the "unmentionable" return type is an implementation detail - that, rather than containing the result of the multiplication, contains instructions - on how to compute the result. In effect it's just a pair of references to the - arguments of the function, plus some compile-time information that stores what - the operation is. + Where the 'unmentionable' return type is an implementation + detail that, rather than containing the result of the multiplication, contains + instructions on how to compute the result. In effect it's just a pair of references + to the arguments of the function, plus some compile-time information that stores + what the operation is.
The great advantage of this method is the elimination of temporaries: diff --git a/doc/html/boost_multiprecision/tut/floats/float128.html b/doc/html/boost_multiprecision/tut/floats/float128.html index 2c6021c6..7bd1c961 100644 --- a/doc/html/boost_multiprecision/tut/floats/float128.html +++ b/doc/html/boost_multiprecision/tut/floats/float128.html @@ -106,6 +106,14 @@ Type
float128can be used as a literal type (constexpr support). +
float128 can be
+ used for full constexpr
+ arithmetic from C++14 and later with GCC. The functions abs, fabs,
+ fpclassify, isnan, isinf,
+ isfinite and isnormal are also constexpr,
+ but the transcendental functions are not.
+ float128
if it's available and _Quad
diff --git a/doc/html/boost_multiprecision/tut/ints/cpp_int.html b/doc/html/boost_multiprecision/tut/ints/cpp_int.html
index bb069c52..81670ef5 100644
--- a/doc/html/boost_multiprecision/tut/ints/cpp_int.html
+++ b/doc/html/boost_multiprecision/tut/ints/cpp_int.html
@@ -343,6 +343,25 @@
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.
abs,
+ swap, multiply, add,
+ subtract, divide_qr, integer_modulus,
+ powm, lsb, msb,
+ bit_test, bit_set, bit_unset,
+ bit_flip, sqrt, gcd,
+ lcm are all supported.
+ Use of cpp_int
+ in this way requires either a C++2a compiler (one which supports std::is_constant_evaluated()),
+ or GCC-6 or later in C++14 mode. Compilers other than GCC and without
+ std::is_constant_evaluated()
+ will support a very limited set of operations: expect to hit roadblocks
+ rather easily.
+ import_bits
diff --git a/doc/html/boost_multiprecision/tut/limits/functions.html b/doc/html/boost_multiprecision/tut/limits/functions.html
index 75ae53c7..8cb3baa0 100644
--- a/doc/html/boost_multiprecision/tut/limits/functions.html
+++ b/doc/html/boost_multiprecision/tut/limits/functions.html
@@ -76,9 +76,10 @@
-(std::numeric_limits<double>::max)() == std::numeric_limits<double>::lowest();-
- [h4min_function min function]
-
min function
+
Function (std::numeric_limits<T>::min)() returns the minimum finite value that
can be represented by the type T.
@@ -117,7 +118,7 @@
Of course, these simply use std::numeric_limits<T>::min() if available.
@@ -195,7 +196,7 @@ of significance or cancellation error or very many iterations.
@@ -263,7 +264,7 @@
RealType tolerance = boost::math::tools::epsilon<RealType>() * 2;
See Donald. E. Knuth. The art of computer programming (vol II). Copyright 1998 Addison-Wesley Longman, Inc., 0-201-89684-2. Addison-Wesley Professional; - 3rd edition. + 3rd edition. (The relevant equations are in paragraph 4.2.2, Eq. 36 and + 37.) +
++ See Boost.Math + floating_point comparison for more details.
See also: @@ -326,8 +332,11 @@ BOOST_CHECK_CLOSE_FRACTION(expected, calculated, tolerance);
- used thus: cd ./test BOOST_CHECK_CLOSE_FRACTION(expected, calculated, tolerance); + used thus:
+cd ./test +BOOST_CHECK_CLOSE_FRACTION(expected, calculated, tolerance); +
(There is also a version BOOST_CHECK_CLOSE using tolerance as a percentage rather than a fraction; usually the fraction version is simpler to use). @@ -356,7 +365,7 @@ BOOST_CHECK_CLOSE_FRACTION(expected, calculated, tolerance);
@@ -484,7 +493,8 @@ infinity input was inf
- Similarly we can do the same with NaN (except that we cannot use assert)
+ Similarly we can do the same with NaN (except that we cannot use assert (because any comparisons with
+ NaN always return false).
{ std::locale old_locale; @@ -501,11 +511,11 @@ std::cout << "NaN input was " << n << std::endl; }-
- NaN output was nan NaN input was nan -
+NaN output was nan +NaN input was nan +
cpp_int_backend
- where the Allocator parameter is type void,
- and the Checked parameter is boost::multiprecision::unchecked.
+ where the Allocator parameter is type void.
+ In addition, prior to C++14 the Checked parameter must be boost::multiprecision::unchecked.
@@ -69,11 +69,12 @@ constexpr int128_t i = 0; // OK, fixed precision int128_t has no allocator. constexpr uint1024_t j = 0xFFFFFFFF00000000uLL; // OK, fixed precision uint1024_t has no allocator. -constexpr checked_uint128_t k = -1; // Error, checked type is not a literal type as we need runtime error checking. +constexpr checked_uint128_t k = 1; // OK from C++14 and later, not supported for C++11. +constexpr checked_uint128_t k = -1; // Error, as this would normally lead to a runtime failure (exception). constexpr cpp_int l = 2; // Error, type is not a literal as it performs memory management.
- There is also limited support for user defined-literals with cpp_int
+ There is also support for user defined-literals with cpp_int
- these are limited to unchecked, fixed precision cpp_int's
which are specified in hexadecimal notation. The suffixes supported are:
The front end of the library is all constexpr
- from C++14 and later. Currently there is only one back-end type that is
- constexpr aware, and that is
- float128.
+ from C++14 and later. Currently there are only two back end types that are
+ constexpr aware: float128
+ and cpp_int.
More backends will follow at a later date.
@@ -220,6 +221,23 @@
isfinite and isnormal are also fully supported, but
the transcendental functions are not.
+ The cpp_int
+ 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 abs, swap, multiply,
+ add, subtract,
+ divide_qr, integer_modulus, powm,
+ lsb, msb,
+ bit_test, bit_set,
+ bit_unset, bit_flip, sqrt,
+ gcd, lcm
+ are all supported. Use of cpp_int
+ in this way requires either a C++2a compiler (one which supports std::is_constant_evaluated()), or GCC-6 or later in C++14 mode. Compilers
+ other than GCC and without std::is_constant_evaluated() will support a very limited set of operations:
+ expect to hit roadblocks rather easily.
+
For example given:
@@ -364,6 +382,27 @@ // static_assert(h9(abscissa) == 6481); ++ Also since the coefficients to the Hermite polynomials are integers, we can + also generate the Hermite coefficients using (fixed precision) cpp_int's: + see constexpr_test_cpp_int_6.cpp. +
++ We can also generate factorials (and validate the result) like so: +
+template <class T> +constexpr T factorial(const T& a) +{ + return a ? a * factorial(a - 1) : 1; +} ++
constexpr uint1024_t f1 = factorial(uint1024_t(31)); +static_assert(f1 == 0x1956ad0aae33a4560c5cd2c000000_cppi); ++
+ Another example in constexpr_test_cpp_int_7.cpp + generates a fresh multiprecision random number each time the file is compiled. +
| diff --git a/doc/html/index.html b/doc/html/index.html index c0b9ef2a..ee1d40f6 100644 --- a/doc/html/index.html +++ b/doc/html/index.html @@ -177,7 +177,7 @@ |
Last revised: August 30, 2019 at 15:57:26 GMT |
+Last revised: September 19, 2019 at 14:40:03 GMT |