3 ms·
Most of the time when I have to think about what to do with a 0 divisor, I come to the conclusion that if (foo == 0): return MAX_FLOAT else: return
by ifdefdebug 8y ago
Most of the time when I have to think about what to do with a 0 divisor, I come to the conclusion that
if (foo == 0):
return MAX_FLOAT
else:
return bar / foo
is more sound for the given algorithm than "return 0" (still crappy, but more sound).
Then use MAX_FLOAT as an error flag instead of 0, which could have been the result of a legal operation (with bar==0).