1
0
mirror of https://github.com/DanilaFe/abacus synced 2026-01-26 16:45:21 +00:00

Revert "Remove the NumberInterface::intPow method."

0c16bb4e9b
This commit is contained in:
2017-08-05 18:22:43 -07:00
parent 4f94700aef
commit bae6ee5526
4 changed files with 57 additions and 4 deletions

View File

@@ -66,6 +66,23 @@ public class NaiveNumber extends NumberInterface {
return new NaiveNumber(-value);
}
@Override
public NumberInterface intPowInternal(int exponent) {
if (exponent == 0) {
return NaiveNumber.ONE;
}
boolean takeReciprocal = exponent < 0;
exponent = Math.abs(exponent);
NumberInterface power = this;
for (int currentExponent = 1; currentExponent < exponent; currentExponent++) {
power = power.multiply(this);
}
if (takeReciprocal) {
power = NaiveNumber.ONE.divide(power);
}
return power;
}
@Override
public int compareTo(NumberInterface number) {
NaiveNumber num = (NaiveNumber) number;