4

My assumptions for IEEE 754-2008:

binary16 - 2^16 distinct values, binary32 - 2^32 distinct values, ... binary128 - 2^128 distinct values.

Is this correct?

1 Answer 1

10

This is a trick question.

The floating-point formats define some special values. Whether you count these as distinct depends on your point of view. The following is for double-precision (binary64):

  1. There are two representations of 0: with the sign bit 0 or 1 and both the exponent and mantissa all zero. The values are distinguishable by the fact that 1/+0 = infinity and 1/-0 = -infinity. But they compare equal.
  2. There are 2 infinities, where the first 12 bits are 0x7ff or 0xfff and the mantissa is all zero. These are not finite real numbers, but they are values.
  3. There is a whole range of Not-A-Number (NaN) values, having sign+exponent bits 0x7ff (signaling NaN) or 0xfff ("quiet" NaN) and a nonzero mantissa. Again, these are not real numbers but they are distinguishable values.

So, to summarize:

  1. The total number of distinguishable values (real numbers or otherwise) is 2^64.
  2. The number of distinct real numbers, excluding infinities and counting zero only once, is 2*(2^11-1)*2^52-1 = 18,437,736,874,454,810,623.

For binary16, the number of distinct real numbers is 2*(2^5-1)*2^10-1 = 63,487. For binary32, it's 2*(2^8-1)*2^23-1=4,278,190,079. For binary128, it's 2*(2^15-1)*2^112-1 or about 3.4*10^38.

2
  • Yes, I forgot about NaN range. So there is 2*(2^8-1)*2^23-1 = 4278190079 for binary32, right? Commented Oct 12, 2011 at 17:48
  • Using binary16 for clarity: is it 2*(2^5-1)*(2^10-1) or (2*(2^5-1)*2^10)-1? The latter makes more sense to me, but if it's the former, can you please clarify? Commented Oct 30, 2013 at 0:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.