Numerical flaws with C.
If we put aside the fact that negation does not turn negative numbers into
positive ones in 2s complement math we should notice the following:
- C does not define the shift value to be saturating. This is in deference
to CPUs like x86 which does not saturate the shift value.
- C does not enforce the definition of sign right shifting. This is because
of older machines that implemented ones complement.
- In the case of (signed int)a % (unsigned int)b, the cast value of a is
first promoted to an unsigned int, then the modulo is computed. This will
lead to unintended results whenever (signed int)a is negative (the result
will not be congruent to (signed int)a modulo (unsigned int)b).