为什么 IEEE 浮点数使用有偏形式计算指数? [英] why IEEE floating point number calculate exponent using a biased form?

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

问题描述

比方说,对于c中的float类型,根据IEEE浮点规范,分数字段有8位,计算为先取这8位并将其转换为一个无符号数,然后减去BIASE,即2^7 - 1 = 127,结果是一个从-127到128的指数,包括-127到128.但是为什么我们不能将这些 8 位模式视为有符号数,因为结果范围是 [-128,127],与前一个几乎相同.

let's say, for the float type in c, according to the IEEE floating point specification, there are 8-bit used for the fraction filed, and it is calculated as first taken these 8-bit and translated it into an unsigned number, and then minus the BIASE, which is 2^7 - 1 = 127, and the result is an exponent ranges from -127 to 128, inclusive. But why can't we just treat these 8-bit pattern as a signed number, since the resulting range is [-128,127], which is almost the same as the previous one.

推荐答案

偏置的目的是让指数以unsigned形式存储,便于比较.来自 维基百科:

The purpose of the bias is so that the exponent is stored in unsigned form, making it easier to do comparisons. From Wikipedia:

通过排列字段,使标志位在最高有效位位置,在偏置指数中间,然后是最少的尾数有效位,结果值将正确订购,无论是解释为浮点数或整数值.这允许高速浮点数的比较使用定点硬件.

By arranging the fields so the sign bit is in the most significant bit position, the biased exponent in the middle, then the mantissa in the least significant bits, the resulting value will ordered properly, whether it's interpreted as a floating point or integer value. This allows high speed comparisons of floating point numbers using fixed point hardware.

所以基本上,浮点数是:

So basically, a floating point number is:

[sign] [unsigned exponent (aka exponent + bias)] [mantissa]

这个网站提供了关于为什么这是好的很好的信息 - 特别是,比较浮点比较函数的实现.

This website provides excellent information about why this is good - specifically, compare the implementations of floating point comparison functions.

此外,如果不提及What Every计算机科学家应该了解浮点运算."它很长,很密集,在数学上有点沉重,但它很长,很密集数学黄金(或类似的东西).

Also, no complete answer about floating point oddities can go without mentioning "What Every Computer Scientist Should Know About Floating-Point Arithmetic." It's long, dense and a bit heavy on the math, but it's long dense mathematical gold (or something like that).

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

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