|
|
|
|
|
by nvy
702 days ago
|
|
>Zero is a fine answer for integer division by zero. It's not. Division (edit: of a positive integer) by zero is better approximated by +infinity rather than zero. In real life to divide something into zero groups is nonsensical, thus the number system in programs should reflect this. In the exceptionally-rare case where you want to divide by zero and it makes sense (can't think of a scenario where that's true but let's stipulate), then you can use your language's equivalent of try/catch or (if (zerop x) ...) to get around it. Don't fuck up normal mathematics for the rest of us just because some lazy programmer doesn't like to add error checking. |
|
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.