Missing modulus in ChineseRemainder?
axkr opened this issue · 1 comments
axkr commented
I think there's a missing mod(m) in ChineseRemainders BigInteger[] algorithm:
diff --git a/rings/src/main/java/cc/redberry/rings/bigint/ChineseRemainders.java b/rings/src/main/java/cc/redberry/rings/bigint/ChineseRemainders.java
index c29b314..5bcc311 100644
--- a/rings/src/main/java/cc/redberry/rings/bigint/ChineseRemainders.java
+++ b/rings/src/main/java/cc/redberry/rings/bigint/ChineseRemainders.java
@@ -208,7 +208,7 @@
for (int i = 0; i < primes.length; i++) {
BigInteger mi = m.divide(primes[i]);
BigInteger eea = bezout0(mi, primes[i]);
- result = result.add(mi.multiply(eea.multiply(remainders[i]).mod(primes[i])));
+ result = result.add(mi.multiply(eea.multiply(remainders[i]).mod(primes[i]))).mod(m);
}
return result;
}
PoslavskySV commented
You are right. Thanks!