Created
August 6, 2012 18:45
-
-
Save jarodwen/3277461 to your computer and use it in GitHub Desktop.
Handle Java integer overflowing
This file contains hidden or 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
// a is a very large integer so that after being multiplied, it would | |
// cause integer overflowing | |
int a = Integer.MAX_VALUE; | |
int b = 9; | |
int c = 47; | |
// modular | |
int mod = (((a % c) * b) % c); | |
// division | |
int div = (a / c * b + a % c * b / c); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment