用两个16位字表示的浮点数可以表示精度的多少位?
解决方案显然是大约6位数。
这是从哪里来的,如何解决这个问题?
解决方案这非常简单:32位IEEE-754浮点数为23 + 1位尾数(AKA有效数,以IEEE语言发言)。尾数的大小或多或少决定了可表示的数字的数量。
为了得到有效位数,简单地计算log 10
(2 24 ),这是近似的。 7.22 。 (或者,如果您认为只有23位计数,无论如何顶部位都是固定的,您可以获得 10 (2 23 )这是大约6.92美元)。所以实际上,对于标准化的值,你有大约6-7个有效位数。对于64位浮点值(双精度值)也是一样的。他们有52(或53)位来存储尾数,所以计算log(sub> 10)(2 52 ) 15.6 (或者 15.9 ,53位),这给了你约15个有效数字。
I've found this problem in many interview exams, but don't see how to work out the proper solution myself. The problem is:
How many digits of accuracy can be represented by a floating point number represented by two 16-bit words?
The solution is apparently approximately 6 digits.
Where does this come from, and how would you work it out?
解决方案It's quite simple: a 32 bit IEEE-754 float has 23+1 bits for the mantissa (AKA significand, in IEEE-speak). The size of the mantissa more or less determines the number of representable digits.
To get the number of significant digits, simply calculate log10(224), which is approx. 7.22. (or, if you think that only 23 bits count, as the top bit is fixed anyway, you get log10(223), which is approx. 6.92). So in effect, you have about 6-7 significant digits, for normalized values.
The same can be done for 64 bit floating point values (doubles). They have 52 (or 53) bits to store the mantissa, so calculate log10(252), which is approx. 15.6 (or 15.9 for 53 bits), which gives you about 15 significant digits.
更多推荐
二进制浮点数的十进制精度
发布评论