Why does division by zero in IEEE754 standard results in Infinite value?

后端 未结 4 2109
孤街浪徒
孤街浪徒 2020-11-27 15:51

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

4条回答
  •  野趣味
    野趣味 (楼主)
    2020-11-27 16:16

    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.

提交回复
热议问题