|
|
|
|
|
by foobar1962
702 days ago
|
|
> Division by zero is better approximated by +infinity rather than zero. No it's not. Division by zero is UNDEFINED. How does a calculation return +infinity anyway? On the positive side of the graph, 1/x approaches +infinity. However from the negative side of the graph 1/x approaches -infinity. So at zero, 1/x is simultaneously +infinity and -infinity, which is not possible. The answer to 1/0 is "there is no answer" which is UNDEFINED. A reasonable result for a calculation is to return "?" or possibly NULL or nothing, depending on what other parts of the system are expecting. |
|
Computer integers aren't the real numbers you learned about in gradeschool. INT_MAX+1 is not greater than INT_MAX. :)
x/0 = program explodes is also a justifiable choice. It is not however more or less fundamentally correct than making the result 0.
Floating point division by zero doesn't (typically) crash programs the way integer division by zero does (it typically returns a NaN-- and the programmer is free to turn nans to zeros if they like :)).