1
0
mirror of https://github.com/DanilaFe/abacus synced 2024-11-13 14:19:53 -08:00

Add support for non-positive ints in intPow for NaiveNumber.

This commit is contained in:
Arthur Drobot 2017-07-25 14:36:46 -07:00
parent dd8d62608c
commit 7aedbd5e20

View File

@ -43,10 +43,18 @@ public class NaiveNumber implements NumberInterface {
@Override
public NumberInterface intPow(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;
}