I was reading about this function:
int tadd_ok ( int x, int y ) {
int sum = x + y;
int negative_overflow = x < 0 && y < 0 && sum >= 0;
int positive_overflow = x >=0 && y >= 0 && sum < 0;
return !negative_overflow && !positive_overflow;
}
This function has a problem when we pass as argument for y the TMin (i.e. the smallest 2's complement).
In this case -y will be -y when passed in i.e. still will be TMin the first condition will show we have negative overflow for values of x that are negative.
Then I read that in fact "x - y does not overflow" in these cases.
My understanding is that the problem of this function is that it does not take into account the corner case of passing the minimum negative number. I can see that it will return a negative_overflow I can not see/understand why that is wrong.
Can anyone help me understand this?