diff --git a/mihxil-algebra/src/main/java/org/meeuw/math/abstractalgebra/padic/impl/Utils.java b/mihxil-algebra/src/main/java/org/meeuw/math/abstractalgebra/padic/impl/Utils.java index 2d9489e6..1bd3ea9d 100644 --- a/mihxil-algebra/src/main/java/org/meeuw/math/abstractalgebra/padic/impl/Utils.java +++ b/mihxil-algebra/src/main/java/org/meeuw/math/abstractalgebra/padic/impl/Utils.java @@ -102,11 +102,13 @@ public static AdicDigits sumAdicDigits(byte base, AdicDigits... summands) { r += byteAndIndex.get().value; } } - if (! anyPresent) { - break; - } + detectRepetition &= anyPresent; + result = DigitUtils.ensureCapacity(i, result); result[i] = (byte) (r % base); + if (! anyPresent && carry == 0) { + break; + } i++; if (detectRepetition) { DigitUtils.CarryAndIndices check = new DigitUtils.CarryAndIndices( diff --git a/mihxil-algebra/src/test/java/org/meeuw/test/math/abstractalgebra/padic/PadicIntegersTest.java b/mihxil-algebra/src/test/java/org/meeuw/test/math/abstractalgebra/padic/PadicIntegersTest.java index 140b0e20..985270de 100644 --- a/mihxil-algebra/src/test/java/org/meeuw/test/math/abstractalgebra/padic/PadicIntegersTest.java +++ b/mihxil-algebra/src/test/java/org/meeuw/test/math/abstractalgebra/padic/PadicIntegersTest.java @@ -26,9 +26,13 @@ public void simple() { PAdicInteger b = p5.of("0", "340"); PAdicInteger c = a.p(b); - System.out.printf("\n %s\n %s\n---------+\n%s%n", a, b, c); + assertThat(c.bigIntegerValue().intValue()).isEqualTo((4 + 3 * 5 + 2 * 5 * 5 ) + (4 * 5 + 3 * 5 * 5)); + + + assertThat(c.toString()).isEqualTo("...0 1124₅"); + log.info("{} + {} = {}", a.bigIntegerValue(), b.bigIntegerValue(), c.bigIntegerValue()); }