From Double-precision floating-point format: IEEE 754 double-precision binary floating-point format: binary64 [emphasis mine]:
Double-precision binary floating-point is a commonly used format on PCs, due to its wider range over single-precision floating point, in spite of its performance and bandwidth cost. It is commonly known simply as double. The IEEE 754 standard specifies a binary64 as having:
- Sign bit: 1 bit
- Exponent: 11 bits
- Significand precision: 53 bits (52 explicitly stored)
a double-precision IEEE 754-compliant binary floating-point have a significand precision of 53 bits, whereas a signed integer of 64 bits (int64_t
) naturally have a precision of 64 bits, meaning the former will not be able to represent all values of the latter. Moreover, floating points in C++ are not even guaranteed to be IEE 754 compliant (implementation-defined), but for implementations for which they are
#include <limits>
static_assert(std::numeric_limits<double>::is_iec559, "");
as per the significant argument above, a double
would be able to represent all numbers of a 32-bit integer.