Fix and test ProgressionUtil
Arithmetical modulo implementation was incorrect (-10 mod 1 == 0, but was 1)
This commit is contained in:
@@ -22,11 +22,13 @@ public class ProgressionUtil {
|
||||
|
||||
// a mod b (in arithmetical sense)
|
||||
private static int mod(int a, int b) {
|
||||
return a >= 0 ? a % b : a % b + b;
|
||||
int mod = a % b;
|
||||
return mod >= 0 ? mod : mod + b;
|
||||
}
|
||||
|
||||
private static long mod(long a, long b) {
|
||||
return a >= 0 ? a % b : a % b + b;
|
||||
long mod = a % b;
|
||||
return mod >= 0 ? mod : mod + b;
|
||||
}
|
||||
|
||||
// (a - b) mod c
|
||||
|
||||
Reference in New Issue
Block a user