Numbers & Math in C++

From the C++ cheat sheet · Numbers, Date/Time & Regex · verified Jul 2026

Numbers & Math

<cmath>, <random>, and numeric limits.

cpp
// Quick Reference
#include <cmath>
std::sqrt(16.0);  std::pow(2, 10);
std::abs(-5);  std::round(3.6);
#include <limits>
std::numeric_limits<int>::max();
💡 Use <random> (mt19937 + a distribution), not rand() - it is higher quality and unbiased.
⚡ std::numeric_limits<T> reports the range/precision of any numeric type.
📌 <numeric> adds gcd, lcm, accumulate, iota, and reduce beyond the plain math functions.
🟢 Integer and floating overflow differ: signed integer overflow is undefined behavior.
mathrandom

More C++ tasks

Back to the full C++ cheat sheet