Java Utililty Methods Integer Mod

List of utility methods to do Integer Mod

Description

The list of methods to do Integer Mod are organized into topic(s).

Method

intmodulo(int a, int b)
modulo
return a - fQuotient(a, b) * b;
intmodulo(int dividend, int divisor)
Modulo Fix for negative numbers
return (dividend % divisor + divisor) % divisor;
intmodulo(int x, int m)
modulo
azzert(m > 0, "m must be > 0");
int y = x % m;
if (y < 0) {
    y += m;
return y;
intmodulo(int x, int mod)
The so-called 'euclidean' modulo, a modulo which won't yield negative results
if (x >= 0) {
    return x % mod;
int n = 1 + (-x / mod);
x += n * mod;
return x % mod;
intmodulo(int x, int y)
modulo
int z = x % y;
return z < 0 ? z + y : z;
intmoduloPositive(final int value, final int size)
modulo Positive
int wrappedValue = value % size;
wrappedValue += wrappedValue < 0 ? size : 0;
return wrappedValue;
intmoduloPowerOfTwo(final int x, final int powerOfTwoY)
modulo Power Of Two
return x & (powerOfTwoY - 1);
intmodulus(int a, int b)
modulus
return (a % b + b) % b;
intmodulus(int a, int b)
modulus
if (b == 0)
    return 0x7fffffff;
if (a == 0x80000000 && b == -1) {
    return 0x7fffffff;
return a % b;
intmodulus(int value, int truncate, boolean flag)
modulus
int newValue = value % truncate;
while (newValue < 0) {
    newValue += truncate;
return newValue;