问题
Why is 0 11110 1111111111
and not 0 11111 1111111111
the highest half precision number?
回答1:
Because an exponent field of 111112 is reserved for infinities and NaNs. Section 3.4 of the IEEE 754-2008 standard says:
The range of the encoding’s biased exponent E shall include:
- every integer between 1 and 2w − 2, inclusive, to encode normal numbers
- the reserved value 0 to encode ±0 and subnormal numbers
- the reserved value 2w − 1 to encode ±∞ and NaNs.
Here "w" is the width of the exponent field. This applies not just to the half-precision format, but to all the IEEE 754 binary interchange formats (including the usual single and double precision formats).
In the particular case of the binary16 format, w is 5 and the top 5 bits following the sign bit describe the biased exponent E, and can range from 000002 to 111112. The top value in this range, 111112, is used for infinities and NaN values, and the bottom value of 000002 is used for zeros and subnormals. The remaining biased exponent values are used for representing finite normal numbers. So the top biased exponent value available for a finite number is 2w - 2 = 111102 rather than 111112.
For this format, the exponent bias is 15, so the bit pattern 0 11110 1111111111 gives an unbiased exponent of 30 - 15 = 15, and represents a value of 1.11111111112 × 215, or 65504.
To give another example, the largest binary32 (single-precision) float is represented by bit pattern
0 11111110 111111111111111111111112
来源:https://stackoverflow.com/questions/33454045/highest-existing-number-in-half-precision-ieee-754