Numerics library
Math, random generation, complex arithmetic, constants, bit utilities, floating-point environment, and data-parallel numerics.
The C++ numerics area combines several different problem spaces: scalar arithmetic helpers, bit-level integer tools, mathematical functions, random engines and distributions, complex numbers, compile-time ratios, floating-point control, and newer data-parallel facilities. This hub is the curated entry point when you know the task is numeric, but not yet which numeric model or header family you need.
# Start Here
Mathematical functions
Use this route for scalar math, transcendental functions, classification helpers, rounding, and the broader <cmath> surface.
Random numbers and distributions
Start here when you need engines, distributions, seeding, or random-device entry points rather than deterministic arithmetic helpers.
Complex numbers
Use std::complex and its function family when the numeric model itself is complex-valued, not just formatted text or scalar math.
complex · polar · arithmetic
Bit and integer helpers
Use the <bit> family and neighboring numeric helpers for bit width/counting, rotations, byte swapping, and exact integer-oriented utilities.
# Quick Map
| If you need | Start with | Why |
|---|---|---|
| Scalar math, rounding, classification, or transcendental functions | Math | This is the main route for <cmath>-style facilities such as sqrt, log, hypot, classification predicates, and rounding behavior. |
| Mathematical constants or named numeric values | Constants, <numbers> | Use this route when the need is a named constant like pi, e, or related compile-time numeric values rather than a runtime computation. |
| Random engines, distributions, or non-deterministic seeding | Random | The random library separates engine choice, distribution choice, and seeding strategy in a way that is distinct from general-purpose arithmetic. |
| Complex arithmetic or complex-valued functions | complex | Use the complex route when the value model itself is complex rather than when you just need more math functions on real numbers. |
| Integer gcd/lcm, midpoint, interpolation, or saturating arithmetic | gcd, lcm, midpoint, lerp, add_sat | These helpers solve focused numeric tasks without requiring the full math or algorithm hubs. |
| Bit-level integer operations such as rotations, popcount, or width calculations | <bit>, popcount, bit_width, byteswap | These are modern integer utilities aimed at representation-aware code, hashing primitives, encodings, and low-level performance work. |
| Compile-time rational arithmetic or unit-style ratios | ratio | std::ratio is the dedicated compile-time numeric model, distinct from runtime math and random facilities. |
| Floating-point exception flags or rounding-mode control | Floating-point environment | This route is for status flags and control modes, not general exception handling or arbitrary precision numerics. |
| Vectorized or data-parallel numerics | SIMD, valarray, <linalg> | These facilities are the right entry points when the question is about parallel numeric structure rather than just a scalar algorithm. |
# Numeric Families
Scalar math
Core real-valued math functions, classifications, rounding modes, and the standard C-compatible math surface.
Bit and integer utilities
Representation-aware integer operations such as popcount, rotations, width detection, bit casting, and byte swapping.
Random
Pseudo-random engines, distributions, adapters, and seeding components for sampling and simulation tasks.
Complex arithmetic
Complex values, transcendental functions on complex numbers, user-defined imaginary literals, and polar/cartesian conversions.
Compile-time numerics
Ratios and associated arithmetic/comparison templates for type-level unit scales and exact rational constants.
Data-parallel numerics
SIMD and array-style numerics for wide-lane or vectorized computations, with valarray as the older array-expression route.
# Focused Numeric Helpers
| Helper family | Use it for | Primary destinations |
|---|---|---|
| Arithmetic helpers | Exact integer relationships, interpolation, and midpoint-style calculations. | gcd, lcm, midpoint, lerp |
| Saturating arithmetic | Overflow-bounded integer arithmetic where saturation is the intended semantic model. | add_sat, sub_sat, mul_sat, div_sat, saturate_cast |
| Bit manipulation | Population counts, shifts-as-rotations, bit widths, and representation transforms. | popcount, countl_zero, countr_zero, byteswap, bit_cast |
| Floating-point environment | Status flags, exceptions, and rounding mode control around floating-point evaluation. | fenv, fetestexcept, feround |
# Modern Additions
| Standard | What became easier to navigate |
|---|---|
| C++17 | gcd and lcm provide direct integer relationship helpers that used to require ad hoc implementations. |
| C++20 | <bit>, constants, midpoint, and lerp added a major modern wave of low-level and numerical convenience utilities. |
| C++23 | Constexpr expansion across math and newer fixed-width floating-point support make older numeric pages intersect more with modern compile-time and portability concerns. |
| C++26 | SIMD, <linalg>, and the saturating arithmetic family make the numerics hub much broader than the legacy math/random view. |
# Adjacent Hubs And Boundaries
| This hub covers | Use a different hub for |
|---|---|
| Math, random generation, complex numbers, bit utilities, ratios, floating-point environment, and data-parallel numeric facilities. | Algorithms for generic sequence-processing algorithms, Chrono for date/time modeling, Utility for formatting and char conversions, and Type support for traits and numeric limits. |
| Modern C++ numeric facilities. | C numerics when you need the C-side compatibility surface or a C-only math/fenv/random route. |