The sizeof(long double)
is 8, which means that if I use all the bits for the integer part of an unsigned number, I can maximum store 2^64-1=18446744073709551615
.
However, std::numeric_limits<long double>::max()
is 1.79769e+308
, which is 1.79769 * 10^308
, which is way larger than 2^64
.
How can I then store a number that big in just 8 bytes?
The reason std::numeric_limits<long double>::max()
is much greater than 2^64
(e.g., ~1.8e308
) even though sizeof(long double)
might be 8 bytes is because floating-point types like long double
use the IEEE 754 format (or compiler-specific variants), which split those bytes into sign, exponent, and significand fields. This allows them to represent extremely large numbers though with limited precision ,unlike integers where all bits directly represent the value.
You can read more in the C++ reference for std::numeric_limits<long double>::max