为什么在 IEEE754 标准中除以零会导致无限值? [英] Why does division by zero in IEEE754 standard results in Infinite value?
问题描述
我只是好奇,为什么在 IEEE-754
中任何非零浮点数除以零会产生无限值?从数学的角度来看,这是无稽之谈.所以我认为这个操作的正确结果是 NaN.
I'm just curious, why in IEEE-754
any non zero float number divided by zero results in infinite value? It's a nonsense from the mathematical perspective. So I think that correct result for this operation is NaN.
如果 x 是实数,则当 x=0 时未定义函数 f(x) = 1/x.例如,如果 IEEE-754
产生 NaN
值,则没有为任何负数定义函数 sqrt 和 sqrt(-1.0f).但是 1.0f/0 是 Inf
.
Function f(x) = 1/x is not defined when x=0, if x is a real number. For example, function sqrt is not defined for any negative number and sqrt(-1.0f) if IEEE-754
produces a NaN
value. But 1.0f/0 is Inf
.
但出于某种原因,IEEE-754
中的情况并非如此.这一定是有原因的,可能是一些优化或兼容性的原因.
But for some reason this is not the case in IEEE-754
. There must be a reason for this, maybe some optimization or compatibility reasons.
那么有什么意义呢?
推荐答案
从数学的角度来看,这是一派胡言.
It's a nonsense from the mathematical perspective.
是的.不.有点.
问题是:浮点数是近似值.您想使用范围广泛的指数和有限的位数,并获得并非完全错误的结果.:)
The thing is: Floating-point numbers are approximations. You want to use a wide range of exponents and a limited number of digits and get results which are not completely wrong. :)
IEEE-754 背后的想法是,每个操作都可能触发陷阱",表明可能存在问题.他们是
The idea behind IEEE-754 is that every operation could trigger "traps" which indicate possible problems. They are
- 非法(负数 sqrt 等无意义的操作)
- 溢出(太大)
- 下溢(太小)
- 除以零(你不喜欢的东西)
- 不精确(此操作可能会因为您失去精度而给您错误的结果)
现在像科学家和工程师这样的许多人不想被编写陷阱例程所困扰.因此,IEEE-754 的发明者 Kahan 决定,如果不存在陷阱例程,每个操作也应该返回一个合理的默认值.
Now many people like scientists and engineers do not want to be bothered with writing trap routines. So Kahan, the inventor of IEEE-754, decided that every operation should also return a sensible default value if no trap routines exist.
他们是
- NaN 表示非法值
- 为溢出签名无穷大
- 下溢的有符号零
- 不确定结果 (0/0) 的 NaN 和 (x/0 x != 0) 的无穷大
- Inexact 的正常运行结果
问题是在 99% 的情况下,零是由下溢引起的,因此在 99% 的情况下一直以来,无穷大都是正确的",即使从数学角度来看是错误的.
The thing is that in 99% of all cases zeroes are caused by underflow and therefore in 99% of all times Infinity is "correct" even if wrong from a mathematical perspective.
这篇关于为什么在 IEEE754 标准中除以零会导致无限值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!