Skip to content

Instantly share code, notes, and snippets.

@jarodwen
Created August 6, 2012 18:45
Show Gist options
  • Save jarodwen/3277461 to your computer and use it in GitHub Desktop.
Save jarodwen/3277461 to your computer and use it in GitHub Desktop.
Handle Java integer overflowing
// 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