How many positive integers divisible by 2 can (could) be represented in IEEE-754 floating point with double precision?
-
52 for double precision – syntagma Sep 12 '14 at 07:16
-
Never mind, I was just taking my socks off to count a bit higher when I came across this http://stackoverflow.com/questions/1848700/biggest-integer-that-can-be-stored-in-a-double which makes your question a near-duplicate and therefore closeworthy. – High Performance Mark Sep 12 '14 at 07:20
-
As it is a near-duplicate, can you actually answer the question or give me some hint in the comment? – syntagma Sep 12 '14 at 07:24
-
@HighPerformanceMark Being making an attempt to answer the question, I do not find it a (near-)duplicate of either “larger bound below which all integers are representable” questions or your question, although it looks a bit like both. – Pascal Cuoq Sep 12 '14 at 07:35
1 Answers
All even integers between -254 and 254 are representable as IEEE 754 double-precision numbers. All finite double-precision numbers larger in magnitude than 254 also happen to be even integers that should be counted. We count these two categories of numbers separately and then add the counts.
The first category represents all the numbers -(254-2), -(254-4), …, -2, 0, 2, 4, …, (254-2).
The second category represents numbers such as 254+4, 254+8, as well as very large double-precision numbers such as 21023. These numbers are IEEE 754 double-precision numbers that represent even integers, so they should be taken into account. The reason the numbers in this category must be counted separately is that in this range, not all even integers are representable as double-precision IEEE 754 numbers (for instance, neither of 254+2, 254+6, and 21023+1024 is representable).
The first category of numbers contains 2 * 253 - 1 items, from -(254-2) to 254-2.
The second category represents 2 * (1024 - 54) binades (the factor two is because both negative binades and positive binades are being counted), that is, 2 * (1024 - 54) * 252 items.
This makes for a total of about 8754997675608244224 even integers in double-precision (give or take an off-by-one error in the computations).

- 79,187
- 7
- 161
- 281
-
There's a 53 bit mantissa. If 2^52 <= x < 2^53, the last bit of the mantissa has a value of 1, so x is an integer. If x >= 2^53, the last bit of the mantissa has a value of 2^k, k >= 1, so x is an even integer. All double precision floating point numbers >= 2^53 are even integers. – gnasher729 Sep 12 '14 at 08:39
-
1@PascalCuoq: I believe you want `2 * (1024 - 54) * 2^52` for the count of values with absolute value in `[2^54, 2^1024)`. I agree with the `2 * 2^53 - 1` for the count of even integers with absolute value strictly less than `2^54`. – Mark Dickinson Sep 12 '14 at 18:27
-
Why each number from interval `[2^{54}...2^{54}]` is representable ? Why `2^{54}+2` is not representable ? – Aug 31 '16 at 23:00