I would like to define some kind of safe division (and modulo) function, one that would return some predefined value when attempting to divide by zero. I don’t want to throw exceptions, just to return some “reasonable” value (1? 0?) and continue the program flow. Obviously there is no correct return value, but I wonder if there is some standard or known approach to this
Share
The IEEE floating point standard defines what to get from a division by zero.
If you work with integers, you can use this standard to define your own routine, but you have to define what is Inf and what is NaN in integer logic.