-2

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.

Paul Totzke
  • 1,470
  • 17
  • 33

2 Answers2

3

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.

Community
  • 1
  • 1
Patricia Shanahan
  • 25,849
  • 4
  • 38
  • 75
  • Each Mantissa represents 2^52 which we will call blocks? There is one exponent for the range [1-2), [.5-1), [.25-.5), [.125, .25) ... So the range [-.5-.5) contains the most Exponent/Sign combinations making it contains the most doubles. This makes sense. – Paul Totzke Dec 08 '15 at 16:57
2

The distribution of IEEE floating point numbers x is roughly proportional to 1 / abs(x), so the length-1 range with the most representable numbers in it is the [-0.5, 0.5] range.

WolframAlpha plot of 1 / abs(x)

Timothy Shields
  • 75,459
  • 18
  • 120
  • 173