Circular safe integer values ​​with IEEE 754 double precision floating point data type

The C ++ standard guarantees us that we can only safely round decimal values ​​to for value double std::numeric_limits<double>::digits10. After reading this post , I wonder if for integers this threshold will extend to std::numeric_limits<double>::digits10+1

+4
source share
1 answer

std :: numeric_limits :: digits10 is 15 because only values ​​containing 15 digits or less guarantee rounding from decimal to double precision and vice versa. Some 16-digit values ​​will be round-trip, but not all of them. In the case of integers, only those <= 2 ^ 53 = 9007199254740992 guarantee rounding (because they are represented exactly). 9007199254740993, for example, is returned as 9007199254740992.

+3
source

All Articles