Skip to content

Commit

Permalink
Fixed issue with last carry in non-repititive values.
Browse files Browse the repository at this point in the history
  • Loading branch information
mihxil committed Jan 2, 2025
1 parent ee2aa93 commit 1483346
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

Expand Down

0 comments on commit 1483346

Please sign in to comment.