It is part of the design philosophy of ForwardCom to avoid "undefined" behavior. Ideally, every situation should have a predictable outcome. I will not use error traps because this is inefficient and bad for vector processing, so I decided that the most sensible solution is to return INT_MAX or INT_MIN, depending on the sign of the dividend. Unsigned division by zero will give UINT_MAX.
Now, I am not sure what to do with an integer modulo zero. I am considering three possible solutions:
- a % 0 = 0
- a % 0 = INT_MIN or some other extreme value to indicate an error
- a % 0 = a
Code: Select all
q = a / b; r = a % b;
Code: Select all
q = a / b; r = a - q * b;
The latter code is faster, and r can be calculated with a single mul_add instruction.
What do you think? Are there any strong reasons to choose another solution?