# Between an adjacent pair of nonzero IEEE single precision real numbers, how many IEEE doubles are there?

My calculation: consider an adjacent pair of IEEE single precision floating point numbers (known as "floats" in C++ for example). Then the gap between those numbers is the corresponding machine epsilon $2^{-24}$. But the gap between doubles is $2^{-53}$. Assuming that each float is a double, the relative interval between two floats could be written as the sequence

$$2^{-24}+ 2^{-53}, 2^{-24}+ 2\cdot2^{-53}, 2^{-24}+ 3\cdot2^{-53}, \dots$$

Anyways... $2^{-24}/2^{-53} = 2^{29}$ so to exclude the endpoints there should be

$$2^{29} -1$$

doubles in each single gap. Seems too large, that's why I'm posting.

Edit: Didn't account for the gaps properly: $2^{29} -2 \to 2^{29} -1$

• If you are unsure you can convince yourself by explicitly counting the numbers:  #include <iostream> #include <cmath> int main(){ float next_float = std::nextafter(1.f,2.f); double x = 1.0; int n = 0; while(1){ x = std::nextafter(x, 2.); if(x >= next_float) break; n++; } std::cout << n << std::endl; } This will confirm your result $536870911 = 2^{29}-1$ – Winther Jun 4 '18 at 20:29
• The absolute spacing/gap is $\epsilon$ at 1, it is larger/smaller for larger/smaller numbers. – gammatester Jun 4 '18 at 20:29

Note that "single" means $1$ sign bit, $8$ bit exponent, $23$ bit mantissa; and "double means $1$ sign bit, $11$ bit exponent, $52$ bit mantissa.
Given two consecutive normalized and non-zero single precision floats with same exponent (and automatically of same sign), we can simply copy the signs, exponent (with bias adjustments) and mantissa from the floats to the corresponding parts of doubles. This determines only 23 of the 52 mantissa bits (the rest being zero for the converted float values themselves), hence leaves room to play with 29 bits (based off the number with lower mantissa), hence in this case there are $2^{29}-1$ doubles strictly between the floats.