Search code examples
mathdoublerangeieee-754

For IEEE 754 double precision numbers, what range with length of 1 contains the most doubles?


Length of a range is equal to Range.Max - Range.Min

For example, "[0-1]" and "[3.5-4.5]" are example of length 1 ranges.

So what length-1 range(s), if any, has the most double precision numbers?

My guess is either [-0.5 - 0.5] or [0-1] but no way of prove it one way or the other.


Solution

  • I agree with the prior answer posted by Timothy Shields. This is an attempt at a more specific justification.

    Let a "block" of numbers be the set of numbers with the same exponent and sign. Each block contains 2^52 numbers. They do not overlap, with the arguable exception of zero, if you do not want to count both positive and negative zero.

    The range [0, 0.5) contains all the numbers with exponents 0 through 1021, 1022 blocks. (-0.5, 0.5) contains 2044 blocks. [-0.5, 0.5] contains all those numbers plus the two end points.

    Changing to [0, 1] deletes 1022 blocks for the negative numbers with exponents 0 through 1021, and adds a single block for [0.5, 1). the numbers with exponent 1022.

    [1,2) is a single block, and that is the last complete block that only covers length 1. Any length 1 range outside (-2, 2) can only contain a partial block.

    At 2044*(2^52)+2, [-0.5, 0.5] is the clear winner.