![]() |
Home | Libraries | People | FAQ | More |
Boost.Math can be consumed as the named module boost.math. The
module covers the public interface of the library: special functions, statistical
distributions, constants, policies, ccmath, the public tools (root finding,
minima, polynomials, rational and series evaluation, norms, condition numbers
and friends), quadrature, the modern interpolators, statistics, optimization,
differentiation (autodiff, finite differences and Lanczos smoothing), the complex
inverse trigonometric functions, and the quaternion and octonion types.
import boost.math; int main() { return boost::math::cdf(boost::math::normal_distribution<>(), 0.0) == 0.5 ? 0 : 1; }
Module support is completely inert unless the module is built and consumed explicitly: nothing changes for existing header users.
The module is consumable from C++20 onward. The interface unit lives in libs/math/module/math.cppm
and builds with any toolchain that provides the standard library module (import std);
the standard library maintainers agreed to make import
std available in C++20 mode as well
as C++23, so a C++23 compilation mode is not required. CI exercises two configurations,
both with CMake 4.4, Ninja and the matching CMAKE_EXPERIMENTAL_CXX_IMPORT_STD
UUID: clang 20 with libc++ runs the full module test suite, and GCC 15 with
libstdc++ builds the module and runs the quick test (libstdc++ cannot yet mix
the textual standard library includes used by the wider test sources with
import std
in the same translation unit). From a Boost superproject checkout:
cmake -G Ninja -DBOOST_INCLUDE_LIBRARIES=math -DBUILD_TESTING=ON \ -DBOOST_MATH_BUILD_MODULE=ON \ -DCMAKE_CXX_COMPILER=clang++-20 \ -DCMAKE_CXX_FLAGS="-stdlib=libc++ -Wno-reserved-module-identifier" \ -DCMAKE_EXPERIMENTAL_CXX_IMPORT_STD=<uuid-for-your-cmake-version> \ -DCMAKE_CXX_STDLIB_MODULES_JSON=/usr/lib/llvm-20/lib/libc++.modules.json .. cmake --build . --target tests ctest
The module test suite reuses a curated subset of the regular test files, which
switch from textual inclusion to import
boost.math; when
BOOST_MATH_BUILD_MODULE is
defined. The cmake-module-test
job in the library's CI runs this configuration on every commit.
BOOST_MATH_DOMAIN_ERROR_POLICY
and friends) and the convenience macros BOOST_MATH_DECLARE_DISTRIBUTIONS
and BOOST_MATH_DECLARE_SPECIAL_FUNCTIONS
therefore have no effect on an importing translation unit. Configure policies
at the call site with boost::math::policies::make_policy
or a policy<...>
type instead; those interfaces are fully available through the import.
user_error policy is
not supported through the module, because a user supplied boost::math::policies::user_..._error definition cannot attach to the
module.
boost/math/tools/config.hpp
and boost/math/tools/assert.hpp, which the test support headers rely
on.
common_factor
headers, boost/math/bindings, boost/math/concepts,
boost/math/cstdfloat, all deprecated headers, and
the headers that require external non-Boost dependencies (chebyshev_transform.hpp and interpolators/cardinal_trigonometric.hpp
need FFTW, optimization/cma_es.hpp
needs Eigen). These remain available as ordinary includes.
__float128 support (BOOST_MATH_USE_FLOAT128) is not enabled
in the module build.
<execution> support), matching the ordinary header
behavior on that standard library.