How to calculate decimal digits of precision based on the number of bits?

我只是一个虾纸丫 提交于 2019-11-28 04:07:58

问题


I am learning about floating point formats (IEEE). In the single precision floating point format ,it is mentioned that the mantissa has 24 bits and so it has 6 1/2 decimal digits of precision (as the per the book "understanding the machine") , and 7.22 decimal digits of precision.

I don't understand how the decimal digits of precision is calculated. Can somebody please enlighten me ?


回答1:


With 24 bits, assuming one bit is reserved for the sign, then the largest decimal number you can represent is 2^23-1=8388607. That is, you can get 6 digits and sometimes a 7th. This is often expressed as "6 1/2 digits". If the 24 bits are representing an unsigned number, then the maximum value you can store is 2^24-1=16,777,215, or 7 and a fraction digits.

When someone quotes you a number with explicit decimal places like 7.22 decimal digits, what they're doing is taking the log (base 10) of the maximum value. So log(16777115)=7.22.

In general, the number of decimal digits you'll get from a given number of bits is:

d=log[base 10](2^b)

where b is the number of bits and d is the number of decimal digits. Then:

d=b * log(2)
d~=b * .3010

So 24 bits gives 24 * .3010 = 7.224



来源:https://stackoverflow.com/questions/10484332/how-to-calculate-decimal-digits-of-precision-based-on-the-number-of-bits

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