Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if ((int) ((unsigned) a + (unsigned) b) < 0 )
- complain();
- if (a^b < 0) overflow=0; /* opposite signs can't overflow */
- else if (a>0) overflow=(b>INT_MAX-a);
- else overflow=(b<INT_MIN-a);
- overflow = (a+b<a);
- -4,294,967,295 < sum < 4,294,967,295
- 4,294,967,295 + 1 = -4,294,967,295
- Do the addition normally, then check the result (e.g. if (a+23<23) overflow).
Add Comment
Please, Sign In to add comment