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

intmod(int hash, int size)
mod
if (hash < 0) {
    return -hash % size;
} else {
    return hash % size;
intmod(int i, int n)
mod
return ((i % n) + n) % n;
intmod(int num, int div)
Returns the modulus of the input value (taking care of the sign of the value)
if (num < 0) {
    return div - (-num % div);
} else {
    return num % div;
intmod(int v, int m)
Return the (positive) remainder of the division of v by mod.
int r = v % m;
if (r < 0) {
    r += m;
return r;
intmod(int x, int y)
Perform (x mod y).
if ((x < 0) ^ (y < 0)) {
    return y + (x % y);
} else {
    return x % y;
intmod(int x, int y)
mod
int result = x % y;
if (result < 0) {
    result += y;
return result;
intmod(int x, int y)
mod handling negatives!
int result = x % y;
if (result < 0) {
    result += y;
return result;
int[]mod(int[]... vectors)
mod
int[] result = vectors[0].clone();
for (int d = 0; d < result.length; d++)
    for (int v = 1; v < vectors.length; v++)
        result[d] %= vectors[v][d];
return result;
intmod(long l, int m)
Computes l mod m , such that the result is always in [0,m-1], for any long value including negative values.
return ((int) (l % m) + m) % m;
intmod4(int a)
Positive modulo 4
int c = a % 4;
return c < 0 ? c + 4 : c;