C++ 什么是次正规浮点数?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8341395/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What is a subnormal floating point number?
提问by B?ови?
isnormal() reference pagetells :
Determines if the given floating point number arg is normal, i.e. is neither zero, subnormal, infinite, nor NaN.
确定给定的浮点数 arg 是否正常,即既不是零、次正规、无限也不是 NaN。
A number being zero, infinite or NaN is clear what it means. But it also says subnormal. When is a number subnormal?
数字为零、无穷大或 NaN 很清楚它的含义。但它也说不正常。什么时候一个数低于正规数?
采纳答案by Kerrek SB
In the IEEE754 standard, floating point numbers are represented as binary scientific notation, x = M × 2e. Here Mis the mantissaand eis the exponent. Mathematically, you can always choose the exponent so that 1 ≤ M < 2.* However, since in the computer representation the exponent can only have a finite range, there are some numbers which are bigger than zero, but smaller than 1.0 × 2emin. Those numbers are the subnormalsor denormals.
在 IEEE754 标准中,浮点数表示为二进制科学记数法,x = M × 2 e。这里M是尾数,e是指数。在数学上,你总是可以选择指数,使得 1 ≤ M < 2.* 但是,由于在计算机表示中指数只能有一个有限的范围,所以有些数字大于零但小于 1.0 × 2 e分钟。这些数字是subnormals或denormals。
Practically, the mantissa is stored without the leading 1, since there is always a leading 1, exceptfor subnormal numbers (and zero). Thus the interpretation is that if the exponent is non-minimal, there is an implicit leading 1, and if the exponent is minimal, there isn't, and the number is subnormal.
实际上,尾数的存储没有前导 1,因为总是有前导 1,除了次正规数(和零)。因此解释是,如果指数是非最小的,则有一个隐含的前导 1,如果指数最小,则没有,并且数字是次正规的。
*) More generally, 1 ≤ M < B for any base-Bscientific notation.
*)更一般地,1≤ 中号 < 乙 任何碱基乙科学记数法。
回答by allwyn.menezes
From http://blogs.oracle.com/d/entry/subnormal_numbers:
来自http://blogs.oracle.com/d/entry/subnormal_numbers:
There are potentially multiple ways of representing the same number, using decimal as an example, the number 0.1 could be represented as 1*10-1or 0.1*100or even 0.01 * 10. The standard dictates that the numbers are always stored with the first bit as a one. In decimal that corresponds to the 1*10-1 example.
Now suppose that the lowest exponent that can be represented is -100. So the smallest number that can be represented in normal form is 1*10-100. However, if we relax the constraint that the leading bit be a one, then we can actually represent smaller numbers in the same space. Taking a decimal example we could represent 0.1*10-100. This is called a subnormal number. The purpose of having subnormal numbers is to smooth the gap between the smallest normal number and zero.
It is very important to realise that subnormal numbers are represented with less precision than normal numbers. In fact, they are trading reduced precision for their smaller size. Hence calculations that use subnormal numbers are not going to have the same precision as calculations on normal numbers. So an application which does significant computation on subnormal numbers is probably worth investigating to see if rescaling (i.e. multiplying the numbers by some scaling factor) would yield fewer subnormals, and more accurate results.
可能有多种表示相同数字的方式,以十进制为例,数字 0.1 可以表示为 1*10 -1或 0.1*10 0甚至 0.01 * 10。标准规定数字始终以第一位作为一个。对应于 1*10-1 示例的十进制数。
现在假设可以表示的最低指数是 -100。所以可以用标准形式表示的最小数字是 1*10 -100。然而,如果我们放宽前导位为 1 的约束,那么我们实际上可以在相同的空间中表示更小的数字。以十进制为例,我们可以表示 0.1*10 -100。这称为次正规数。使用次正规数的目的是平滑最小正规数和零之间的差距。
认识到次正规数的表示精度低于正规数是非常重要的。事实上,他们正在用较小的尺寸换取降低的精度。因此,使用次正规数的计算将不会具有与正规数计算相同的精度。因此,对次正规数进行大量计算的应用程序可能值得研究,以查看重新缩放(即,将数字乘以某个比例因子)是否会产生更少的次正规数和更准确的结果。