libboost-multiprecision/1.87.0

[brief]

Extended precision arithmetic types for floating point, integer, and rational arithmetic

Master Develop
Drone Build Status Build Status
Github Actions Build Status Build Status
Codecov codecov 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:

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 $50$ or $100$ decimal digits), or a variable controlled at run-time by member functions. The types are expression-template-enabled by default. This usually provides better performance than naive user-defined types. If not needed, expression templates can be disabled when configuring the number type with its backend.

The full documentation is available on boost.org.

Using Multiprecision

In the following example, we use Multiprecision's Boost-licensed binary floating-point backend type cpp_bin_float to compute ${\sim}100$ decimal digits of

$$\sqrt{\pi} = \Gamma \left( \frac{1}{2} \right)~{\approx}~1.772453850905516027298{\ldots}\text{,}$$

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;
}

Standalone

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.

Support, bugs and feature requests

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].

Development

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/.

Running tests

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
version 1.87.0
license BSL-1.0Boost Software License 1.0
repository https://pkg.cppget.org/1/stable
download libboost-multiprecision-1.87.0.tar.gz
sha256 c0b2045945975fb104973a9fd217214e1bc9c897f1424b173117ac55499a4de6
project boost
url github.com/boostorg/multiprecision
doc-url www.boost.org/doc/libs/1_87_0/libs/multiprecision
package-url github.com/build2-packaging/boost
package-email packaging@build2.orgMailing list
topics C++Boost

Depends (10)

Eigen ^3.3.8
libboost-assert == 1.87.0
libboost-config == 1.87.0
libboost-core == 1.87.0
libboost-integer == 1.87.0
libboost-lexical-cast == 1.87.0
libboost-math == 1.87.0
libboost-predef == 1.87.0
libboost-random == 1.87.0
libboost-throw-exception == 1.87.0

Reviews

fail 0
pass 1

Builds

toolchain public-0.17.0
target x86_64-microsoft-win32-msvc14.3
tgt config windows_10-clang_18_llvm_msvc_17.10-static_O2
timestamp 2025-08-21 12:34:43 UTC (06:13:28 hours ago)
result warning (update) | warning (test-installed) | log | rebuild
toolchain public-0.17.0
target x86_64-microsoft-win32-msvc14.3
tgt config windows_10-clang_18_llvm_msvc_17.10-O2
timestamp 2025-08-21 12:33:07 UTC (06:15:05 hours ago)
result warning (update) | warning (test-installed) | log | rebuild
toolchain public-0.17.0
target x86_64-microsoft-win32-msvc14.3
tgt config windows_10-clang_18_llvm_msvc_17.10
timestamp 2025-08-21 12:32:00 UTC (06:16:12 hours ago)
result warning (update) | warning (test-installed) | log | rebuild
toolchain public-0.17.0
target x86_64-microsoft-win32-msvc14.3
tgt config windows_10-clang_17_msvc_msvc_17.10
timestamp 2025-08-21 12:20:47 UTC (06:27:24 hours ago)
result warning (update) | warning (test-installed) | log | rebuild
toolchain public-0.17.0
target x86_64-freebsd14.1
tgt config freebsd_14-clang_18-O3
timestamp 2025-08-21 12:14:38 UTC (06:33:33 hours ago)
result warning (update) | warning (test-installed) | log | rebuild
toolchain public-0.17.0
target x86_64-freebsd14.1
tgt config freebsd_14-clang_18-static_O3
timestamp 2025-08-21 12:14:20 UTC (06:33:51 hours ago)
result warning (update) | warning (test-installed) | log | rebuild
toolchain public-0.17.0
target x86_64-freebsd14.1
tgt config freebsd_14-clang_18
timestamp 2025-08-21 12:13:35 UTC (06:34:36 hours ago)
result warning (update) | warning (test-installed) | log | rebuild
toolchain public-0.17.0
target aarch64-linux-gnu
tgt config linux_debian_12-clang_18_libc++-static_O3
timestamp 2025-08-21 12:01:15 UTC (06:46:56 hours ago)
result warning (update) | warning (test-installed) | log | rebuild
toolchain public-0.17.0
target aarch64-linux-gnu
tgt config linux_debian_12-clang_18_libc++-O3
timestamp 2025-08-21 12:00:46 UTC (06:47:26 hours ago)
result warning (update) | warning (test-installed) | log | rebuild
toolchain public-0.17.0
target aarch64-linux-gnu
tgt config linux_debian_12-clang_18_libc++
timestamp 2025-08-21 12:00:13 UTC (06:47:58 hours ago)
result warning (update) | warning (test-installed) | log | rebuild
toolchain public-0.17.0
target aarch64-linux-gnu
tgt config linux_debian_12-gcc_13
timestamp 2025-08-21 10:42:06 UTC (08:06:06 hours ago)
result warning (update) | warning (test-installed) | log | rebuild
toolchain public-0.17.0
target x86_64-w64-mingw32
tgt config windows_10-gcc_13.2_mingw_w64-static_O2
timestamp 2025-08-21 08:50:33 UTC (09:57:38 hours ago)
result success | log | rebuild
toolchain public-0.17.0
target x86_64-w64-mingw32
tgt config windows_10-gcc_13.2_mingw_w64-O2
timestamp 2025-08-21 08:31:09 UTC (10:17:03 hours ago)
result success | log | rebuild
toolchain public-0.17.0
target x86_64-w64-mingw32
tgt config windows_10-gcc_13.2_mingw_w64
timestamp 2025-08-21 08:04:47 UTC (10:43:24 hours ago)
result success | log | rebuild
toolchain public-0.17.0
target x86_64-microsoft-win32-msvc14.3
tgt config windows_10-msvc_17.8-static_O2
timestamp 2025-08-21 08:04:23 UTC (10:43:48 hours ago)
result success | log | rebuild
toolchain public-0.17.0
target x86_64-microsoft-win32-msvc14.3
tgt config windows_10-msvc_17.8-O2
timestamp 2025-08-21 08:01:17 UTC (10:46:55 hours ago)
result success | log | rebuild
toolchain public-0.17.0
target x86_64-microsoft-win32-msvc14.3
tgt config windows_10-msvc_17.8
timestamp 2025-08-21 07:49:52 UTC (10:58:20 hours ago)
result success | log | rebuild
toolchain public-0.17.0
target x86_64-microsoft-win32-msvc14.3
tgt config windows_10-msvc_17.10-static_O2
timestamp 2025-08-20 09:32:42 UTC (01 09:15:29 days ago)
result success | log | rebuild
toolchain public-0.17.0
target x86_64-microsoft-win32-msvc14.3
tgt config windows_10-msvc_17.10-O2
timestamp 2025-08-20 09:28:35 UTC (01 09:19:36 days ago)
result success | log | rebuild
toolchain public-0.17.0
target x86_64-microsoft-win32-msvc14.3
tgt config windows_10-msvc_17.10
timestamp 2025-08-20 09:20:18 UTC (01 09:27:54 days ago)
result success | log | rebuild
toolchain public-0.17.0
target x86_64-linux-gnu
tgt config linux_debian_12-gcc_14-static_O3
timestamp 2025-08-20 08:04:23 UTC (01 10:43:48 days ago)
result success | log | rebuild
toolchain public-0.17.0
target x86_64-linux-gnu
tgt config linux_debian_12-gcc_14-O3
timestamp 2025-08-20 08:02:09 UTC (01 10:46:02 days ago)
result success | log | rebuild
toolchain public-0.17.0
target x86_64-linux-gnu
tgt config linux_debian_12-gcc_14-ndebug_O3
timestamp 2025-08-20 07:56:37 UTC (01 10:51:34 days ago)
result success | log | rebuild
toolchain public-0.17.0
target x86_64-linux-gnu
tgt config linux_debian_12-gcc_14
timestamp 2025-08-20 07:54:42 UTC (01 10:53:30 days ago)
result success | log | rebuild
toolchain public-0.17.0
target x86_64-linux-gnu
tgt config linux_fedora_40-gcc_14-bindist
timestamp 2025-08-20 03:49:37 UTC (01 14:58:35 days ago)
result success | log | rebuild
toolchain public-0.17.0
target x86_64-linux-gnu
tgt config linux_debian_12-gcc_12-bindist
timestamp 2025-08-20 03:30:06 UTC (01 15:18:06 days ago)
result success | log | rebuild
toolchain public-0.17.0
target aarch64-linux-gnu
tgt config linux_debian_12-clang_18-O3
timestamp 2025-08-20 03:26:27 UTC (01 15:21:44 days ago)
result success | log | rebuild
toolchain public-0.17.0
target aarch64-linux-gnu
tgt config linux_debian_12-clang_18-static_O3
timestamp 2025-08-20 03:24:03 UTC (01 15:24:08 days ago)
result success | log | rebuild
toolchain public-0.17.0
target aarch64-linux-gnu
tgt config linux_debian_12-clang_18
timestamp 2025-08-20 03:23:35 UTC (01 15:24:37 days ago)
result success | log | rebuild
toolchain public-0.17.0
target x86_64-linux-gnu
tgt config linux_ubuntu_24.04-gcc_13-bindist
timestamp 2025-08-20 03:08:08 UTC (01 15:40:03 days ago)
result success | log | rebuild
toolchain public-0.17.0
target x86_64-linux-gnu
tgt config linux_debian_12-clang_17_libc++
timestamp 2025-08-20 03:01:36 UTC (01 15:46:35 days ago)
result success | log | rebuild
toolchain public-0.17.0
target x86_64-linux-gnu
tgt config linux_debian_12-clang_17
timestamp 2025-08-20 03:01:16 UTC (01 15:46:55 days ago)
result success | log | rebuild
toolchain public-0.17.0
target x86_64-freebsd13.3
tgt config freebsd_13-clang_17
timestamp 2025-08-20 02:59:55 UTC (01 15:48:16 days ago)
result success | log | rebuild
toolchain public-0.17.0
target x86_64-linux-gnu
tgt config linux_debian_12-gcc_13.1
timestamp 2025-08-20 02:58:39 UTC (01 15:49:32 days ago)
result success | log | rebuild
toolchain public-0.17.0
target aarch64-linux-gnu
tgt config linux_debian_12-gcc_14-static_O3
timestamp 2025-08-19 11:08:18 UTC (02 07:39:53 days ago)
result warning (update) | warning (test-installed) | log | rebuild
toolchain public-0.17.0
target aarch64-linux-gnu
tgt config linux_debian_12-gcc_14-ndebug_O3
timestamp 2025-08-19 11:07:46 UTC (02 07:40:26 days ago)
result warning (update) | warning (test-installed) | log | rebuild
toolchain public-0.17.0
target aarch64-linux-gnu
tgt config linux_debian_12-gcc_14
timestamp 2025-08-19 11:02:15 UTC (02 07:45:56 days ago)
result warning (update) | warning (test-installed) | log | rebuild
toolchain public-0.17.0
target aarch64-linux-gnu
tgt config linux_debian_12-gcc_14-O3
timestamp 2025-08-19 10:59:26 UTC (02 07:48:46 days ago)
result warning (update) | warning (test-installed) | log | rebuild
toolchain public-0.17.0
target aarch64-linux-gnu
tgt config linux_debian_12-clang_17_libc++
timestamp 2025-08-19 01:51:12 UTC (02 16:57:00 days ago)
result success | log | rebuild
toolchain public-0.17.0
target aarch64-linux-gnu
tgt config linux_debian_12-clang_17
timestamp 2025-08-19 01:45:24 UTC (02 17:02:48 days ago)
result success | log | rebuild
toolchain public-0.17.0
target x86_64-linux-gnu
tgt config linux_debian_12-clang_18
result unbuilt
toolchain public-0.17.0
target x86_64-linux-gnu
tgt config linux_debian_12-clang_18-O3
result unbuilt
toolchain public-0.17.0
target x86_64-linux-gnu
tgt config linux_debian_12-clang_18-static_O3
result unbuilt
toolchain public-0.17.0
target x86_64-linux-gnu
tgt config linux_debian_12-clang_18_libc++
result unbuilt
toolchain public-0.17.0
target x86_64-linux-gnu
tgt config linux_debian_12-clang_18_libc++-O3
result unbuilt
toolchain public-0.17.0
target x86_64-linux-gnu
tgt config linux_debian_12-clang_18_libc++-static_O3
result unbuilt
toolchain public-0.17.0
target x86_64-linux-gnu
tgt config linux_fedora_39-gcc_13-bindist
result unbuilt
toolchain public-0.17.0
target x86_64-apple-darwin22.5.0
tgt config macos_13-clang_15.0
result unbuilt
toolchain public-0.17.0
target x86_64-apple-darwin23.5.0
tgt config macos_14-clang_15.0
result unbuilt
toolchain public-0.17.0
target x86_64-apple-darwin23.5.0
tgt config macos_14-clang_15.0-O3
result unbuilt
toolchain public-0.17.0
target x86_64-apple-darwin23.5.0
tgt config macos_14-clang_15.0-static_O3
result unbuilt
target x86_64-apple-darwin23.5.0
tgt config macos_14-gcc_14_homebrew
result excluded (https://github)
target x86_64-apple-darwin23.5.0
tgt config macos_14-gcc_14_homebrew-O3
result excluded (https://github)
target x86_64-apple-darwin23.5.0
tgt config macos_14-gcc_14_homebrew-static_O3
result excluded (https://github)