Re:1/0 = 0
by jeremyjh on Saturday August 11, 2018 @08:22AM
(#17739407)
You can check for 0 and throw in those cases, and then propagate the error path appropriately. And as they've already said in this thread, they will be providing a checked arithmetic in the standard library to do that for you.
[ Parent
| on HN ]
Well, sometimes the average is 0, e.g. (-2 + 2)/2.
And the whole point is that this is meant to catch unforeseen interactions as soon as possible. If you add a check it's no longer unforeseen, and it may easily slip the programmer's mind.
Re:1/0 = 0
by seandougall on Saturday August 11, 2018 @01:19PM
(#17740584)
If I'm not mistaken, jeremyjh was referring to checking for 0 in the denominator, not the numerator.