二进制浮点数的十进制精度 [英] Decimal accuracy of binary floating point numbers

查看:206
本文介绍了二进制浮点数的十进制精度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在很多面试考试中发现了这个问题,但是没有看到如何自己制定出正确的解决方案。问题是:
$ b


用两个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.

这篇关于二进制浮点数的十进制精度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆