3 ms·
>Compelling alternative would be for it to return zero. That's actually way less safe than crashing. If your code doesn't handle the case where the denominator
by jovial_cavalier 3y ago
>Compelling alternative would be for it to return zero.
That's actually way less safe than crashing. If your code doesn't handle the case where the denominator is zero, it is likely that the logic around your division doesn't consider it either. The behavior you suggest would take a rapidly increasing number and instantaneously set it to 0, then silently pass it into the logic that was humming along up to that point.
Since there's no symbol for NaN in integers, there is no safe way to represent `x / 0`, and thus the best way to handle it is to fault. Even better would be if the compiler caught it and warned you.
- jstimpfle 3y ago> Even better would be if the compiler caught it and warned you Which is probably what the big compilers do (seems reasonable to expect it) -- I can't really know though because the last time I've written code that divides by 0 in an easily provable way is probably a long time ago.