Last active
February 28, 2017 05:03
-
-
Save shinhirota/9519bed19fae631f1f1444872bbe7924 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <limits.h> | |
BOOL is_sum_overflow(long a, long b) { | |
if (a < LONG_MAX / 2) { | |
if (b < LONG_MAX / 2) | |
return FALSE; | |
else | |
return ((b - LONG_MAX / 2) + a > LONG_MAX / 2); | |
} | |
else { | |
if (b < LONG_MAX / 2) | |
return TRUE; | |
else | |
return ((a - LONG_MAX / 2) + b > LONG_MAX / 2); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment