previous | start | next

Overflow for signed integer addition

We saw that overflow for unsigned integer addition is easy to check.

What about for signed integer addition?



Recall for two unsigned integers a and b, a + b can't be smaller than
a unless overflow has occurred. This is because unsigned integers are
always >= 0.


For signed integers x and y, either one can be negative, so it can
happen that x + y is smaller than x without overflow occurring.

Cases:                     Overflow if
x > 0 and y > 0      x + y < x
x > 0 and y < 0      no overflow
x < 0 and y > 0      no overflow
x < 0 and y < 0      x + y > x


previous | start | next