Created
February 9, 2014 00:20
-
-
Save sephlietz/8892395 to your computer and use it in GitHub Desktop.
Check if two positive integers will result in an overflow
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
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