This question already has an answer here:
- What's the first double that deviates from its corresponding long by delta? 4 answers
- Which is the first integer that an IEEE 754 float is incapable of representing exactly? 2 answers
What is the exact range of (contiguous) integers that can be expressed as a double (resp. float?) The reason I ask is because I am curious for questions such as this one when a loss of accuracy will occur.
That is
- What is the least positive integer
m
such thatm+1
cannot be precisely expressed as a double (resp. float)? - What is the greatest negative integer
-n
such that-n-1
cannot be precisely expressed as a double (resp. float)? (May be the same as the above).
This means that every integer between -n
and m
has an exact floating-point representation. I'm basically looking for the range [-n, m]
for both floats and doubles.
Let's limit the scope to the standard IEEE 754 32-bit and 64-bit floating point representations. I know that the float has 24 bits of precision and the double has 53 bits (both with a hidden leading bit), but due to the intricacies of the floating point representation I'm looking for an authoritative answer for this. Please don't wave your hands!
(Ideal answer would prove that all the integers from 0
to m
are expressible, and that m+1
is not.)