IEEE 754 中的指数

发布于 2024-08-22 02:16:01 字数 65 浏览 6 评论 0原文

为什么浮点数中的指数被替换为 127?
好吧,真正的问题是:与 2 的补码表示法相比,这种表示法有什么优势?

Why exponent in float is displaced by 127?
Well, the real question is : What is the advantage of such notation in comparison to 2's complement notation?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

回忆那么伤 2024-08-29 02:16:01

由于存储的指数是无符号的,因此可以使用整数指令来比较浮点值。出于比较目的,整个浮点值可以被视为有符号大小的整数值(而不是二进制补码)。

Since the exponent as stored is unsigned, it is possible to use integer instructions to compare floating point values. the the entire floating point value can be treated as a signed magnitude integer value for purposes of comparison (not twos-compliment).

清旖 2024-08-29 02:16:01

只是为了纠正一些错误信息:它是 2^n * 1.mantissa,分数前面的 1 是隐式存储的。

Just to correct some misinformation: it is 2^n * 1.mantissa, the 1 infront of the fraction is implicitly stored.

胡大本事 2024-08-29 02:16:01

请注意,有偏指数和 2 的补码之间的指数可表示范围略有不同。 IEEE 标准支持的指数范围为(-127 到 +128),而如果是 2 的补码,则为(-128 到 +127)。我真的不知道标准选择偏差形式的原因,但也许委员会成员认为允许极大的数字而不是极小的数字更有用。

Note that there is a slight difference in the representable range for the exponent, between biased and 2's complement. The IEEE standard supports exponents in the range of (-127 to +128), while if it was 2's complement, it would be (-128 to +127). I don't really know the reason why the standard chooses the bias form, but maybe the committee members thought it would be more useful to allow extremely large numbers, rather than extremely small numbers.

江湖正好 2024-08-29 02:16:01

@Stephen Canon,回应ysap的回答(抱歉,这应该是我的回答的后续评论,但原始答案是作为未注册用户输入的,所以我还不能真正发表评论)。

斯蒂芬,显然你是对的,我提到的指数范围是不正确的,但答案的精神仍然适用。假设它是 2 的补码而不是偏置值,并且假设 0x00 和 0xFF 值仍然是特殊值,则偏置指数允许比 2 的补码指数大 (2x) 的数字。

@Stephen Canon, in response to ysap's answer (sorry, this should have been a follow up comment to my answer, but the original answer was entered as an unregistered user, so I cannot really comment it yet).

Stephen, obviously you are right, the exponent range I mentioned is incorrect, but the spirit of the answer still applies. Assuming that if it was 2's complement instead of biased value, and assuming that the 0x00 and 0xFF values would still be special values, then the biased exponents allow for (2x) bigger numbers than the 2's complement exponents.

ι不睡觉的鱼゛ 2024-08-29 02:16:01

32 位浮点数中的指数由 8 位组成,但没有符号位。所以范围实际上是[0;255]。为了表示数字< 2^0,该范围移动 127,变为 [-127;128]。

这样,就可以非常精确地表示非常小的数字。对于 [0;255] 范围,小数字必须表示为 2^0 * 0.mantissa,尾数中有很多零。但在 [-127;128] 范围内,小数字更精确,因为它们可以表示为 2^-126 * 0.mantissa (尾数中不必要的零较少)。希望你明白这一点。

The exponent in a 32-bit float consists of 8 bits, but without a sign bit. So the range is effectively [0;255]. In order to represent numbers < 2^0, that range is shifted by 127, becoming [-127;128].

That way, very small numbers can be represented very precisely. With a [0;255] range, small numbers would have to be represented as 2^0 * 0.mantissa with lots of zeroes in the mantissa. But with a [-127;128] range, small numbers are more precise because they can be represented as 2^-126 * 0.mantissa (with less unnecessary zeroes in the mantissa). Hope you get the point.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文