Half precision conversion

笑着哭i 提交于 2019-12-11 12:04:17

问题


How comes that 0 11110 1111111111 is equal to the half precision format 1.1111111111 * 2^15? Both should be 65504.

The sign bit here is a 0. The exponent would be 11101 and the fractional part 1111111111. But that doesn't look like 1.1111111111 * 2^15 at all.

Can someone explain that to me?


回答1:


Here is the layout of your half-precision number:

The exponent's value is 111102, which is 3010. Half-precision numbers have exponent bias of 1510, so we need to subtract 1510 from 3010 to get the actual exponent of 1510.

There is an implicit 12 pre-pended to the fraction, so the actual fraction has one extra 1 in front of it. The binary fraction point is located immediately after that implicit 1, making the number look like this:

1.1111111111

In order to apply the binary exponent of 1510, we need to move the fraction point fifteen positions to the right. This produces the number 11111111111000002, which is equal to 6550410 after the conversion.



来源:https://stackoverflow.com/questions/33461757/half-precision-conversion

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