为什么我们偏向浮点数的指数? [英] Why do we bias the exponent of a floating-point number?

查看:181
本文介绍了为什么我们偏向浮点数的指数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图用二进制数字的浮点数来表达我的头,但我无法找到,无论我在哪里看,这个问题的答案都很好。



为什么指数有偏差?

好的旧可靠的补码法有什么问题?

<我试图看看维基百科关于这个话题的文章,但是它所说的只是:对于有符号值的通常表示,会使比较变得更难。

解决方案IEEE 754编码具有一个方便的性质,即通过按照字典顺序比较相应的位串,或者等价地将这些位串解释为无符号的,可以在两个正的非NaN数之间执行顺序比较整数和比较这些整数。这适用于从+0.0到+ Infinity的整个浮点范围(然后扩展比较以考虑符号是一件简单的事情)。因此,例如在IEEE 754二进制64格式中, 1.1 被编码为位串(msb优先)

<$ p $ 0011111111110001100110011001100110011001100110011001100110011010

0.01 被编码为位串

$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $在$ 1.1 的位串之前按照字典顺序出现。

>为了这个工作,具有较小指数的数字需要在具有较大指数的数字之前进行比较。一个有偏倚的指数使得这个工作成为可能,而一个用二进制补码表示的指数会使得比较更加涉及。我相信这就是维基百科的评论。



另一个观察结果是,使用所选的编码,浮点数 +0.0 被编码为完全由零组成的位串。

I'm trying to wrap my head around this floating point representation of binary numbers, but I couldn't find, no matter where I looked, a good answer to the question.

Why is the exponent biased?

What's wrong with the good old reliable two's complement method?

I tried to look at the Wikipedia's article regarding the topic, but all it says is: "the usual representation for signed values, would make comparison harder."

解决方案

The IEEE 754 encodings have a convenient property that an order comparison can be performed between two positive non-NaN numbers by simply comparing the corresponding bit strings lexicographically, or equivalently, by interpreting those bit strings as unsigned integers and comparing those integers. This works across the entire floating-point range from +0.0 to +Infinity (and then it's a simple matter to extend the comparison to take sign into account). Thus for example in IEEE 754 binary 64 format, 1.1 is encoded as the bit string (msb first)

0011111111110001100110011001100110011001100110011001100110011010

while 0.01 is encoded as the bit string

0011111110000100011110101110000101000111101011100001010001111011

which occurs lexicographically before the bit string for 1.1.

For this to work, numbers with smaller exponents need to compare before numbers with larger exponents. A biased exponent makes that work, while an exponent represented in two's complement would make the comparison more involved. I believe this is what the Wikipedia comment applies to.

Another observation is that with the chosen encoding, the floating-point number +0.0 is encoded as a bit string consisting entirely of zeros.

这篇关于为什么我们偏向浮点数的指数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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