4 ms·
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 providin
by jeremyjh 8y ago
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.
- Giroflex 8y agoWell, 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.
- seandougall 8y agoIf I'm not mistaken, jeremyjh was referring to checking for 0 in the denominator, not the numerator.