mirror of
https://github.com/DanilaFe/abacus
synced 2024-12-22 15:30:09 -08:00
Add support for non-positive ints in intPow for NaiveNumber.
This commit is contained in:
parent
38255b1219
commit
5f60110385
|
@ -43,10 +43,18 @@ public class NaiveNumber implements NumberInterface {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public NumberInterface intPow(int exponent) {
|
public NumberInterface intPow(int exponent) {
|
||||||
|
if(exponent == 0){
|
||||||
|
return NaiveNumber.ONE;
|
||||||
|
}
|
||||||
|
boolean takeReciprocal = exponent < 0;
|
||||||
|
exponent = Math.abs(exponent);
|
||||||
NumberInterface power = this;
|
NumberInterface power = this;
|
||||||
for(int currentExponent = 1; currentExponent < exponent; currentExponent++){
|
for(int currentExponent = 1; currentExponent < exponent; currentExponent++){
|
||||||
power = power.multiply(this);
|
power = power.multiply(this);
|
||||||
}
|
}
|
||||||
|
if(takeReciprocal){
|
||||||
|
power = NaiveNumber.ONE.divide(power);
|
||||||
|
}
|
||||||
return power;
|
return power;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user