了解非规范化浮点数的用途 [英] Understanding the usefulness of denormalized floating point numbers

查看:194
本文介绍了了解非规范化浮点数的用途的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

阅读Goldberg的每位计算机科学家应该了解的有关浮动的知识-点算术,我发现了一些我不太了解的东西.

Reading Goldberg's What Every Computer Scientist Should Know About Floating-Point Arithmetic, I found something I don't really understand.

他指出,具有非规格化数字是好的,因为x = y当且仅当x-y==0时.然后他举了一个例子:

He states that having denormalized numbers is good, because x = y if and only if x-y==0. Then he gives the example:

如果(x!= y)则z = 1/(x-y)

if (x != y) then z = 1/(x-y)

现在,假设x-y是非正规数.那么1/(x-y)很有可能成为inf.如果我们一开始就没有非规范化的数字,那么结果是一样的.

Now, suppose that x-y is a denormalized number. Then there is a high chance that 1/(x-y) will become inf. Which is the same result, if we didn't have denormalized numbers in the first place.

即使我要执行除法并避免出现inf结果,如果我们没有非规范化的数字,也将更加方便:

Even, if I want to execute a division, and avoid inf results, then it is more convenient, if we don't have denormalized numbers:

if (x-y) then z = 1/(x-y) // here, we know that z is not inf

我无法用归一化的数字实现相同的效果,因为x-y可能不是零,而是一个非归一化的数字,然后1/(x-y)的除法将导致inf.因此,在这里,非规范化的数字实际上会引起麻烦.

I cannot achieve the same with denormalized numbers, as x-y might not be zero, but a denormalized number, and then the 1/(x-y) divison will result in inf. So, here, denormalized numbers are actually cause trouble.

为什么并且只有当x-y=0时,拥有x=y才是好特性?

Why is it a good property to have x=y if and only if x-y=0?

非规范化数字有用吗?

推荐答案

威廉·卡汉(William Kahan)逐渐下沉:

  • 如果浮点格式具有次正规值,则可表示值之间的差距不会随着数字的减少而增加.这可以在编写证明时有所帮助,因为可以断言,如果 x 0 与它的最近邻居之间的差是 u ,那么对于任何 x x 0 x 与它的最近邻居之间的差最大为 u .然后,您可以继续得出结论,只要输入在范围之内,由某些计算序列产生的误差最多是某个值.如果没有次正规值,您将不得不考虑以下情况:编写例外情况,其中考虑中间值下溢的情况,将证明分为多个情况,从证明中排除域的某些部分,依此类推.
  • x ± y 不能下溢,因为存在次正态差异.
  • 只要至少一项是正常的,则乘积总和的次等项舍入误差较小.
  • If a floating-point format has subnormal values, the gaps between representable values do not increase as numbers decrease. This helps when writing proofs, as one can assert that, if the difference between x0 and its nearest neighbor is u, then, for any xx0, the difference between x and its nearest neighbor is at most u. Then you can go on and conclude that the error produced by some sequence of computations is at most some value as long as the input is within bounds. Without subnormal values, you would have to write exceptions where you consider cases where intermediate values underflowed, different your proof into multiple cases, exclude certain parts of the domain fro the proof, and so on.
  • x±y cannot underflow since a subnormal difference is exact.
  • A sum of products suffers less rounding error from subnormal terms as long as at least one term is normal.

本文并未声称渐进式下溢在每种情况下均具有优越性,但已证明总体上更可取.

The paper does not claim that gradual underflow is superior in every situation, but that it has proven to be preferable overall.

在您给出此示例时:

if (x-y) then z = 1/(x-y) // here, we know that z is not inf

具有受限制的实用程序,因为在if (x-y) then z = 4/(x-y)中不是这样.

that has restricted utility, as it is not true in if (x-y) then z = 4/(x-y).

这篇关于了解非规范化浮点数的用途的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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