Maximum Value of a double in C++
Short answer:
#include <limits>
std::numeric_limits<double>::max() // ~1.7976931348623157e308
std::numeric_limits<double>::lowest() // ~-1.7976931348623157e308
std::numeric_limits<double>::min() // ~2.2250738585072014e-308 (smallest POSITIVE)
The third line is the one that catches people — read on.
The Two Ways to Get It
#include <iostream>
#include <cfloat> // DBL_MAX, DBL_MIN
#include <limits> // std::numeric_limits
int main() {
std::cout << DBL_MAX << '\n'; // 1.79769e+308
std::cout << std::numeric_limits<double>::max() << '\n'; // same
}
To print all the digits rather than the default six significant figures:
#include <iomanip>
std::cout << std::setprecision(17)
<< std::numeric_limits<double>::max() << '\n';
// 1.7976931348623157e+308
The min() vs lowest() Trap
This is the single most important thing on this page.
std::numeric_limits<int>::min() // -2147483648 — most negative
std::numeric_limits<double>::min() // 2.2e-308 — smallest POSITIVE
For integers, min() is the most negative value. For floating-point types, min() means the smallest positive normal number — a tiny value just above zero, not a large negative one.
So this common pattern is silently wrong:
// BROKEN — finds nothing below 2.2e-308
double largest = std::numeric_limits<double>::min();
for (double v : values) {
if (v > largest) largest = v;
}
// if every value is negative, largest stays at 2.2e-308
Use lowest(), added in C++11 precisely to fix this:
double largest = std::numeric_limits<double>::lowest(); // -1.8e308
float and long double
std::cout << std::numeric_limits<float>::max() << '\n'; // ~3.4e38
std::cout << std::numeric_limits<double>::max() << '\n'; // ~1.8e308
std::cout << std::numeric_limits<long double>::max() << '\n'; // platform dependent
The C-style macros are FLT_MAX, DBL_MAX and LDBL_MAX from <cfloat>.
Note the enormous jump from float to double — that is why double is the sensible default for general arithmetic, and float is reserved for cases where memory or GPU bandwidth genuinely matters.
Overflow Gives Infinity, Not Wraparound
Integer overflow is undefined behaviour. Floating-point overflow is well defined:
#include <cmath>
double big = std::numeric_limits<double>::max();
double bigger = big * 2;
std::cout << bigger << '\n'; // inf
std::cout << std::isinf(bigger) << '\n'; // 1
You can also produce infinity deliberately, which is often useful as a sentinel:
double inf = std::numeric_limits<double>::infinity();
double smallest = inf; // safe starting point for a minimum search
And check for the other special value:
double nan = 0.0 / 0.0;
std::cout << std::isnan(nan); // 1
// NaN is not equal to itself — this is the standard test
std::cout << (nan == nan); // 0
Precision Is Not the Same as Range
A double can represent numbers up to 1.8e308, but only with about 15–17 significant digits. Huge magnitude does not mean exactness:
double a = 1e16;
std::cout << std::setprecision(20) << a + 1 << '\n'; // 10000000000000000
Adding 1 to 10¹⁶ changes nothing, because the gap between representable doubles at that magnitude is larger than 1. This is also why you should never compare doubles with == — see comparing floating-point numbers.
The relevant constant is epsilon:
std::cout << std::numeric_limits<double>::epsilon(); // ~2.22e-16
That is the smallest difference from 1.0 that the type can represent.
Checking What Your Platform Uses
std::cout << std::numeric_limits<double>::digits10 << '\n'; // 15
std::cout << std::numeric_limits<double>::is_iec559 << '\n'; // 1 = IEEE 754
std::cout << sizeof(double) << '\n'; // 8 bytes
is_iec559 confirms the platform follows IEEE 754, which is what makes infinity and NaN behave as described.
Quick Reference
| You want | Use |
|---|---|
| Largest double | numeric_limits<double>::max() |
| Most negative double | numeric_limits<double>::lowest() |
| Smallest positive double | numeric_limits<double>::min() |
| Infinity | numeric_limits<double>::infinity() |
| Comparison tolerance | numeric_limits<double>::epsilon() |
| C-style macro | DBL_MAX from <cfloat> |
Take Your C++ Further
If you want types, precision and the rest of the fundamentals explained properly, the C++ Better Explained Ebook covers them in plain English. Just $19.
👉 Get the C++ Better Explained Ebook — $19
Related Articles
- INT_MAX and INT_MIN in C++ — the integer equivalent.
- INT_MAX and numeric_limits in C++ — the full numeric_limits reference.
- Comparing Floating-Point Numbers in C++ — why == fails on doubles.
- C++ float vs double — choosing between them.
- C++ Variables and Data Types — the wider type picture.