指数偏差如何使比较容易 [英] How does exponent bias make comparison easier

查看:67
本文介绍了指数偏差如何使比较容易的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在阅读这篇有关浮动的指数偏差的文章点号,并显示以下内容:

I'm reading this article about exponent bias in floating point numbers and it says the following:

n个IEEE 754浮点数,指数在工程意义上的单词–存储的值与实际值受指数偏差的影响.进行偏移是因为指数必须签名的值,以便能够代表这两个微小的和巨大的价值,但有两个补语,通常表示签名的值,将使比较更加困难.为了解决这个问题通过调整指数的值来存储之前对指数进行偏置它在一个适合比较的无符号范围内.通过安排字段,以使符号位处于最高有效位位置,中间的有偏指数,然后最小的是尾数有效位,结果值将正确排序,解释为浮点数还是整数值.这允许使用固定值对浮点数进行高速比较点硬件.

n IEEE 754 floating point numbers, the exponent is biased in the engineering sense of the word – the value stored is offset from the actual value by the exponent bias. Biasing is done because exponents have to be signed values in order to be able to represent both tiny and huge values, but two's complement, the usual representation for signed values, would make comparison harder. To solve this problem the exponent is biased before being stored, by adjusting its value to put it within an unsigned range suitable for comparison. By arranging the fields so that 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 be 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.

我还从维基百科的文章中找到了有关偏移二进制文件的解释:

I've also found this explanation from wikipedia's article about offset binary:

其结果是零"值由1表示在最高有效位中,在所有其他位中为零,通常方便地,效果与使用二进制补码相同,只是最高位被反转.它也有后果在逻辑比较操作中获得的结果与用二进制补码数值比较运算,而二的补码表示法逻辑比较将与二的一致当且仅当数字时才对数字比较运算进行补充被比较具有相同的符号.否则的意义比较将被取反,所有负值均视为大于所有正值.

This has the consequence that the "zero" value is represented by a 1 in the most significant bit and zero in all other bits, and in general the effect is conveniently the same as using two's complement except that the most significant bit is inverted. It also has the consequence that in a logical comparison operation, one gets the same result as with a two's complement numerical comparison operation, whereas, in two's complement notation a logical comparison will agree with two's complement numerical comparison operation if and only if the numbers being compared have the same sign. Otherwise the sense of the comparison will be inverted, with all negative values being taken as being larger than all positive values.

我不太了解他们在这里谈论哪种比较.有人可以用一个简单的例子来解释吗?

I don't really understand what kind of comparison they are talking about here. Can someone please explain using a simple example?

推荐答案

这里的比较"是指按大小对数字进行的常规比较:5> 4,等等.假设浮点数存储为

'Comparison' here refers to the usual comparison of numbers by size: 5 > 4, etc. Suppose floating-point numbers were stored with as

[sign bit] [unbiased exponent] [mantissa]

例如,如果指数是2的补码3位二进制数,而尾数是4位无符号二进制数,那么您将拥有

For example, if the exponent is a 2's complement 3-bit binary number and the mantissa is a 4-bit unsigned binary number, you'd have

1 010 1001 = 4.5
1 110 0111 = 0.21875

您可以看到第一个大于第二个,但要弄清楚这一点,计算机将必须计算 1.001 x 2 ^ 2 0.111 x 2 ^(-2),然后比较生成的浮点数.对于浮点硬件来说,这已经很复杂了,如果这台计算机没有这样的硬件,那么...

You can see that the first is bigger than the second, but to figure this out, the computer would have to calculate 1.001 x 2^2 and 0.111 x 2^(-2) and then compare the resulting floating-point numbers. This is already complex with floating-point hardware, and if there is no such hardware for this computer, then...

因此该数字存储为

[sign bit] [biased exponent] [mantissa]

使用相同的3位二进制数作为指数(这次是有偏见的;请参见相关问题)和无符号的4位尾数,我们有

Using the same 3-bit binary number for the exponent (this time biased; see a related question) and unsigned 4-bit mantissa, we have

1 101 1001 = 4.5
1 001 0111 = 0.21875

但是现在比较非常容易!您可以将这两个数字视为整数 11011001 10010111 ,然后看到第一个数字显然更大:即使对于计算机,这也是显而易见的,因为整数比较很容易.这就是为什么要使用有偏指数的原因.

But now comparison is very easy! You can treat the two numbers as integers 11011001 and 10010111 and see that the first is obviously bigger: obvious even to a computer, as integer comparisons are easy. This is why biased exponents are used.

这篇关于指数偏差如何使比较容易的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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