3 ms·
I don't know if I per-se agree with defaulting to zero in all instances, but I agree with a somewhat general sentiment. Division by zero, it would be nice if it
by tcmart14 2y ago
I don't know if I per-se agree with defaulting to zero in all instances, but I agree with a somewhat general sentiment. Division by zero, it would be nice if it returned something we can count on. In my mind, I see it some pre-determined safe default value. Which in many cases, may be zero.
I think what I would like is perhaps a way to have something almost like an interrupt. And being able to set what the interrupt does or swap between different interrupts. At runtime we can see the denominator is zero, so trigger the interrupt. For a set of functions, I can set an interrupt where a divide by zero does return zero, these would be functions whose callers can safely handle the zero or perform some default state at zero. But other functions, maybe there is a different default value that callers can use and it not screw everything up.
Some may gripe about, but its a mathematically in correct answer. Sure, it is. But for systems, especially saftey critical systems, I'd rather know that in the event I didn't properly guard against a 0 in the denominator, a behavior that I can account for is guaranteed to happen (some safe default).
- dylan604 2y ago> I don't know if I per-se agree with defaulting to zero in all instances, but I agree with a somewhat general sentiment I agree with this. Forcing every instance to be 0 might hide the issue as 0 could be a valid if unexpected result in situations which might make debugging more difficult. The same reason === is a thing. NaN seems plausible yet equally awkward. Null could work too