为什么在IEEE754标准中除零会导致无穷大的值? [英] Why does division by zero in IEEE754 standard results in Infinite value?
问题描述
IEEE-754
任何非零浮点数除以零导致无限值?从数学的角度来看,这是无稽之谈。所以我认为这个操作的正确结果是NaN。 函数f(x)= 1 / x在x = 0时没有定义,如果x是实数。例如,如果 IEEE-754
产生一个 NaN $ c $,函数sqrt没有为任何负数定义,而sqrt(-1.0f)价值。但是1.0f / 0是
Inf
。
但是由于某些原因,在 IEEE-754
。
那么有什么意义呢?
是的,这是从数学的角度来说的废话。没有排序。
事情是:浮点数是近似值。你想使用广泛的指数和有限的数字,并得到不完全错误的结果。 :)
IEEE-754背后的想法是,每一个操作都可能引发陷阱,表明可能存在问题。它们是 它们是
现在很多人喜欢科学家和工程师不想被打扰编写陷阱程序。因此,IEEE-754的发明者Kahan认为,如果没有陷阱例程存在,每一个操作都应该返回一个合理的默认值。
- NaN代表非法值
- 有符号无符号溢出符号
- 对于(x / 0 x!= 0)不确定的结果(0/0)和无穷的NaN
- 不正确的正常运算结果 li>
事情是,所有情况下99%的零是由于下溢引起的,所以无穷大是99%b $ b即使从数学的角度来看是错误的,正确也是如此。
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.
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
.
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.
So what's the point?
It's a nonsense from the mathematical perspective.
Yes. No. Sort of.
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. :)
The idea behind IEEE-754 is that every operation could trigger "traps" which indicate possible problems. They are
- Illegal (senseless operation like sqrt of negative number)
- Overflow (too big)
- Underflow (too small)
- Division by zero (The thing you do not like)
- Inexact (This operation may give you wrong results because you are losing precision)
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.
They are
- NaN for illegal values
- signed infinities for Overflow
- signed zeroes for Underflow
- NaN for indeterminate results (0/0) and infinities for (x/0 x != 0)
- normal operation result for Inexact
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屋!