Skip to content

Instantly share code, notes, and snippets.

@sephlietz
Created February 9, 2014 00:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sephlietz/8892395 to your computer and use it in GitHub Desktop.
Save sephlietz/8892395 to your computer and use it in GitHub Desktop.
Check if two positive integers will result in an overflow
public boolean willPositiveIntegerAdditionOverflow(int a, int b) {
if (a < 0 || b < 0) {
throw new IllegalArgumentException("this only works with two positive integers");
}
return (a > (Integer.MAX_VALUE - b));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment