非规范化数字 - IEEE 754 浮点 [英] Denormalized Numbers - IEEE 754 Floating Point

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

问题描述

因此,我正在尝试了解有关 IEEE 754 浮点数标准中定义的非规范化数字的更多信息.感谢 Google 搜索结果,我已经阅读了几篇文章,并且浏览了几篇 StackOverFlow 帖子.但是我还有一些问题没有得到解答.

So I'm trying to learn more about Denormalized numbers as defined in the IEEE 754 standard for Floating Point numbers. I've already read several articles thanks to Google search results, and I've gone through several StackOverFlow posts. However I still have some questions unanswered.

首先,回顾一下我对非规范化浮点数的理解:

First off, just to review my understanding of what a Denormalized float is:

精度位数较少且较小的数字(在幅度)比归一化数字

Numbers which have fewer bits of precision, and are smaller (in magnitude) than normalized numbers

本质上,非规范化的浮点数能够表示可以用任何浮点值表示的最小(数量级)数.

Essentially, a denormalized float has the ability to represent the SMALLEST (in magnitude) number that is possible to be represented with any floating point value.

听起来正确吗?还有什么比这更重要的吗?

我读过:

使用非规范化数字会在许多方面带来性能成本平台

using denormalized numbers comes with a performance cost on many platforms

对此有何评论?

我也读过一篇文章

应该避免规范化和非规范化数字之间的重叠"

one should "avoid overlap between normalized and denormalized numbers"

对此有何评论?

在 IEEE 标准的某些演示文稿中,当呈现浮点范围时,非规范化值被排除在外,并且表格被标记为有效范围",就好像演讲者在想我们知道非规范化数字可以代表最小可能的浮点值,但由于非规范化数字的某些缺点,我们选择将它们排除在更适合常见使用场景的范围之外"——好像非规范化数字不常用一样.

In some presentations of the IEEE standard, when floating point ranges are presented the denormalized values are excluded and the tables are labeled as an "effective range", almost as if the presenter is thinking "We know that denormalized numbers CAN represent the smallest possible floating point values, but because of certain disadvantages of denormalized numbers, we choose to exclude them from ranges that will better fit common use scenarios" -- As if denormalized numbers are not commonly used.

我想我只是一直觉得在大多数情况下使用非规范化数字并不是一件好事?

如果我必须自己回答这个问题,我会想:

If I had to answer that question on my own I would want to think that:

使用非规范化数字很好,因为您可以表示可能的最小(数量级)数字 - 只要精度不重要,并且您不会将它们与规范化数字混淆,并且应用程序的最终性能符合要求.

Using denormalized numbers is good because you can represent the smallest (in magnitude) numbers possible -- As long as precision is not important, and you do not mix them up with normalized numbers, AND the resulting performance of the application fits within requirements.

使用非规范化数字是一件坏事,因为大多数应用程序不需要如此小的表示 - 精度损失是有害的,并且您可以通过将它们与规范化数字混合来太容易地打自己的脚,而性能不是在大多数情况下,物有所值.

Using denormalized numbers is a bad thing because most applications do not require representations so small -- The precision loss is detrimental, and you can shoot yourself in the foot too easily by mixing them up with normalized numbers, AND the peformance is not worth the cost in most cases.

对这两个答案有何评论?关于非规范化数字,我还有什么遗漏或不了解的地方?

推荐答案

本质上,非规范化的浮点数能够表示可以用 SMALLEST(数量级)表示的数任何浮点值.

Essentially, a denormalized float has the ability to represent the SMALLEST (in magnitude) number that is possible to be represented with any floating point value.

没错.

在许多平台上使用非规范化数字会带来性能成本

using denormalized numbers comes with a performance cost on many platforms

不同处理器上的惩罚不同,但最高可达 2 个数量级.原因?与此建议相同:

The penalty is different on different processors, but it can be up to 2 orders of magnitude. The reason? The same as for this advice:

应该避免规范化和非规范化数字之间的重叠"

one should "avoid overlap between normalized and denormalized numbers"

这是关键:非正规是 IEEE-754 浮点格式中的定点微格式".在普通数字中,指数表示二进制点的位置.非正规数包含定点表示法的最后 52 位,双精度数的指数为 2-1074.

Here's the key: denormals are a fixed-point "micro-format" within the IEEE-754 floating-point format. In normal numbers, the exponent indicates the position of the binary point. Denormal numbers contain the last 52 bits in the fixed-point notation with an exponent of 2-1074 for doubles.

因此,非规范化很慢,因为它们需要特殊处理.在实践中,它们很少发生,芯片制造商不喜欢在罕见的情况下花费太多宝贵的资源.

So, denormals are slow because they require special handling. In practice, they occur very rarely, and chip makers don't like to spend too many valuable resources on rare cases.

将非正规与法线混合很慢,因为您正在混合格式,并且您需要在两者之间进行转换.

Mixing denormals with normals is slow because then you're mixing formats and you have the additional step of converting between the two.

我想我只是一直觉得使用非规范化在大多数情况下,数字并不是一件好事?

I guess I just keep getting the impression that using denormalized numbers turns out to not be a good thing in most cases?

创建非正规有一个主要目的:逐渐下溢.这是一种使微小数字之间的相对差异保持较小的方法.如果从最小的正常数直接到零(突然下溢),则相对变化是无限的.如果您在下溢上进行非规范化,则相对变化仍然不完全准确,但至少更合理.这种差异会在计算中体现出来.

Denormals were created for one primary purpose: gradual underflow. It's a way to keep the relative difference between tiny numbers small. If you go straight from the smallest normal number to zero (abrupt underflow), the relative change is infinite. If you go to denormals on underflow, the relative change is still not fully accurate, but at least more reasonable. And that difference shows up in calculations.

换一种说法.浮点数不是均匀分布的.2 的连续幂之间总是有相同数量的数字:252(对于双精度).因此,如果没有非规范化,您总是会在 0 和最小浮点数之间出现差距,即 252 乘以最小两个数字之间的差异大小.非正规均匀地填补了这个空白.

To put it a different way. Floating-point numbers are not distributed uniformly. There are always the same amount of numbers between successive powers of two: 252 (for double precision). So without denormals, you always end up with a gap between 0 and the smallest floating-point number that is 252 times the size of the difference between the smallest two numbers. Denormals fill this gap uniformly.

作为关于突然下溢与逐渐下溢影响的示例,请查看数学上等效的 x == yx - y == 0.如果 xy 很小但不同,并且您使用突然下溢,则如果它们的差小于最小截止值,则它们的差将为零,因此等价违反了.

As an example about the effects of abrupt vs. gradual underflow, look at the mathematically equivalent x == y and x - y == 0. If x and y are tiny but different and you use abrupt underflow, then if their difference is less than the minimum cutoff value, their difference will be zero, and so the equivalence is violated.

随着逐渐下溢,两个微小但不同的正常数之间的差异变为非正规数,但仍不为零.等价性被保留.

With gradual underflow, the difference between two tiny but different normal numbers gets to be a denormal, which is still not zero. The equivalence is preserved.

因此,不建议故意使用非规范化,因为它们仅被设计为特殊情况下的备用机制.

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

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