How many normalized numbers can be represented using IEEE-754 Single Precision?

不羁的心 提交于 2019-12-20 16:41:37

问题


Based on the IEEE-754 Single Precision standard, how can I know how many normalized numbers can be represented if I know the following:

1 bit for the Sign

8 bits for the exponent

23 bits for the mantissa

Is there a rule that can be applied to any other system of floating-point?


回答1:


You've identified the number of bits for each portion of the representation, so you're already halfway there. There are:

  • 2^1 = 2 possibilities for the sign
  • 2^8 = 256 possibilities for the exponent bits, of which two are reserved for non-normals: an exponent field of all zeros is used for floating-point zeros and subnormals, while an exponent field of all ones is used for infinities and nans
  • 2^23 = 8388608 possibilities for the mantissa (note that 'significand' is generally the preferred term).

Multiplying, that gives 2 * 2^23 * (2^8 - 2), or equivalently 2^32 - 2^25, possibilities altogether. So there are 2^32 - 2^25 = 4261412864 distinct normal numbers in the IEEE 754 binary32 format. The two zeros are not, technically, normal numbers, but if you wanted to include them in the count you'd get 2^32 - 2^25 + 2 instead.

And yes, this generalises directly to all the other IEEE 754 binary interchange formats. I'll leave it to you to find the numbers for double precision, half precision, quadruple precision etc.


Just for fun, here's a complete breakdown:

  • 2 zeros (sign 0 or 1, exponent and significand fields zero)

  • 2^24 - 2 subnormal numbers (sign 0 or 1, exponent field zero, significand field nonzero)

  • 2^32 - 2^25 normal numbers (as above)

  • 2 infinities (sign 0 or 1, exponent field all ones, significand field zero)

  • 2^23 - 2 signaling NaNs (sign 0 or 1, exponent field all ones, significand field nonzero but with zero first bit)

  • 2^23 quiet NaNs (sign 0 or 1, exponent field all ones, significand field has 1 as first bit)



来源:https://stackoverflow.com/questions/12558780/how-many-normalized-numbers-can-be-represented-using-ieee-754-single-precision

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!