A DESCRIPTION OF THE PROBLEM :
The current implementation of Math.floorMod(int, int) reads:
public static int floorMod(int x, int y) {
int mod = x % y;
// if the signs are different and modulo not zero, adjust result
if ((mod ^ y) < 0 && mod != 0) {
mod += y;
}
return mod;
}
while Math.floorMod(long, long) reads:
public static int floorMod(long x, long y) {
long mod = x % y;
// if the signs are different and modulo not zero, adjust result
if ((x ^ y) < 0 && mod != 0) {
mod += y;
}
return mod;
}
There's a difference in how the signs are checked.
Prefer the floorMod(long, long) variant even for floorMod(int, int), that is, rewrite
public static int floorMod(int x, int y) {
int mod = x % y;
// if the signs are different and modulo not zero, adjust result
if ((x ^ y) < 0 && mod != 0) {
mod += y;
}
return mod;
}
The current implementation of Math.floorMod(int, int) reads:
public static int floorMod(int x, int y) {
int mod = x % y;
// if the signs are different and modulo not zero, adjust result
if ((mod ^ y) < 0 && mod != 0) {
mod += y;
}
return mod;
}
while Math.floorMod(long, long) reads:
public static int floorMod(long x, long y) {
long mod = x % y;
// if the signs are different and modulo not zero, adjust result
if ((x ^ y) < 0 && mod != 0) {
mod += y;
}
return mod;
}
There's a difference in how the signs are checked.
Prefer the floorMod(long, long) variant even for floorMod(int, int), that is, rewrite
public static int floorMod(int x, int y) {
int mod = x % y;
// if the signs are different and modulo not zero, adjust result
if ((x ^ y) < 0 && mod != 0) {
mod += y;
}
return mod;
}