Master | Develop | |
---|---|---|
Drone | ||
Github Actions | ||
Codecov |
Boost.Multiprecision
is a C++ library that provides integer, rational, floating-point, complex and interval number types
having more range and precision than the language's ordinary built-in types.
Language adherence:
Boost.Multiprecision
requires a compliant C++14 compiler.- It is compatible with C++14, 17, 20, 23 and beyond.
The big number types in Boost.Multiprecision
can be used with a wide selection of basic
mathematical operations, elementary transcendental functions as well as the functions in Boost.Math. The Multiprecision types can
also interoperate with the built-in types in C++ using clearly defined conversion rules. This allows Boost.Multiprecision
to be
used for all kinds of mathematical calculations involving integer, rational and floating-point types requiring extended range and precision.
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, rational and floating-point types. Boost.Multiprecision
provides a selection of back ends provided off-the-rack in
including interfaces to GMP, MPFR, MPIR, TomMath as well as its own collection of Boost-licensed, header-only back ends for integers,
rationals, floats and complex. 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 number
type with its backend.
The full documentation is available on boost.org.
In the following example, we use Multiprecision's Boost-licensed binary
floating-point backend type cpp_bin_float
to compute
where we also observe that Multiprecision can seemlesly interoperate with Boost.Math.
#include <iomanip>
#include <iostream>
#include <sstream>
#include <boost/multiprecision/cpp_bin_float.hpp>
#include <boost/math/special_functions/gamma.hpp>
auto main() -> int
{
using big_float_type = boost::multiprecision::cpp_bin_float_100;
const big_float_type sqrt_pi { sqrt(boost::math::constants::pi<big_float_type>()) };
const big_float_type half { big_float_type(1) / 2 };
const big_float_type gamma_half { boost::math::tgamma(half) };
std::stringstream strm { };
strm << std::setprecision(std::numeric_limits<big_float_type>::digits10) << "sqrt_pi : " << sqrt_pi << '\n';
strm << std::setprecision(std::numeric_limits<big_float_type>::digits10) << "gamma_half: " << gamma_half;
std::cout << strm.str() << std::endl;
}
Defining BOOST_MP_STANDALONE
allows Boost.Multiprecision
to be used with the only dependency being Boost.Config.
Our package on this page already includes a copy of Boost.Config so no other downloads are required. Some functionality is reduced in this mode. A static_assert message will alert you if a particular feature has been disabled by standalone mode. Boost.Math standalone mode is compatiable, and recommended if special functions are required for the floating point types.
Bugs and feature requests can be reported through the Gitub issue tracker (see open issues and closed issues).
You can submit your changes through a pull request.
There is no mailing-list specific to Boost Multiprecision
,
although you can use the general-purpose Boost mailing-list
using the tag [multiprecision].
Clone the whole boost project, which includes the individual Boost projects as submodules (see boost+git doc):
git clone https://github.com/boostorg/boost
cd boost
git submodule update --init
The Boost Multiprecision Library is located in libs/multiprecision/
.
First, build the b2
engine by running bootstrap.sh
in the root of the boost directory. This will generate b2
configuration in project-config.jam
.
./bootstrap.sh
Now make sure you are in libs/multiprecision/test
. You can either run all the tests listed in Jamfile.v2
or run a single test:
../../../b2 <- run all tests
../../../b2 test_complex <- single test