Skip to content

Instantly share code, notes, and snippets.

Created February 9, 2014 00:20
What would you like to do?
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