- Notifications
You must be signed in to change notification settings - Fork123
boostorg/multiprecision
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Master | Develop | |
---|---|---|
Drone | ||
Github Actions | ||
Codecov |
Boost.Multiprecision
is a C++ library that provides integer,rational, floating-point, complex and interval number typeshaving 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 inBoost.Multiprecision
can be used with a wide selection of basicmathematical operations, elementary transcendental functions as well as the functions inBoost.Math
.The Multiprecision types also interoperate with built-in types in C++.The big number types adhere to clearly defined conversion rules. This allowsBoost.Multiprecision
to beused for all kinds of mathematical calculations involving integer, rational and floating-point typesrequiring extended range and precision.
Multiprecision consists of a generic interface to the mathematicsof large numbers as well as a selection of big number backends.These include interfaces to GMP, MPFR, MPIR and TomMathand also Multiprecision's own collection of Boost-licensed,header-only backends for integers, rationals, floats and complex-floats.
In addition, user-defined backends can be created and used with the interface of Multiprecision,presuming that the class implementation adheres to the necessary concepts.
Depending upon the multiprecision type, precision may be arbitrarily large (limited only by available memory),fixed at compile time (for examplenumber
type with its backend.Most of the multiprecision types are expression-template-enabled by default.This usually provides better performance than using types configured without expression templates.
The full documentation is available onboost.org.
A practical, comprehensive, instructive, clear and very helpful video regarding the use of Multiprecisioncan be foundhere.
In the following example, we use Multiprecision's Boost-licensed binaryfloating-point backend typecpp_bin_float
to compute
where we also observe that Multiprecision can seamlesly interoperate withBoost.Math
.
// ------------------------------------------------------------------------------// Copyright Christopher Kormanyos 2024 - 2025.// 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)//#include<boost/math/special_functions/gamma.hpp>#include<boost/multiprecision/cpp_bin_float.hpp>#include<iomanip>#include<iostream>#include<sstream>automain() -> int{// Configure a multiprecision binary floating-point type with approximately// 100 decimal digits of precision and expression templates enabled.// Note that the popular type cpp_bin_float_100 has already been preconfigured// and aliased in the multiprecision headers.using big_float_type = boost::multiprecision::cpp_bin_float_100;// In the next few lines, compute and compare sqrt(pi) with tgamma(1/2)// using the 100-digit multiprecision type.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 { };// 1.772453850905516027298167483341145182797549456122387128213807789852911284591032181374950656738544665 strm <<std::setprecision(std::numeric_limits<big_float_type>::digits10) <<"sqrt_pi :" << sqrt_pi <<"\ngamma_half:" << gamma_half; std::cout << strm.str() << std::endl;}
DefiningBOOST_MP_STANDALONE
allowsBoost.Multiprecision
to be used with the only dependency beingBoost.Config.Ourpackage on this pagealready includes a copy ofBoost.Config.So no other downloads are required.
Some functionality is reduced in this mode.Astatic_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 theGitub issue tracker(seeopen issues andclosed issues).
You can submit your changes through apull request.
There is no mailing-list specific toBoost Multiprecision
,although you can use the general-purpose Boostmailing-listusing 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/boostcd boost git submodule update --init
TheBoost.Multiprecision
Library is located inlibs/multiprecision/
.
First, build theb2
engine by runningbootstrap.sh
in the root of the boost directory. This will generateb2
configuration inproject-config.jam
.
./bootstrap.sh
Now make sure you are inlibs/multiprecision/test
. You can either run all the tests listed inJamfile.v2
or run a single test:
../../../b2<- run all tests ../../../b2 test_complex<- singletest
About
Boost.Multiprecision
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.