1
0
mirror of https://github.com/DanilaFe/abacus synced 2024-12-22 15:30:09 -08:00

Add intPow to Number intefrace and NaiveNumber.

This commit is contained in:
Arthur Drobot 2017-07-25 11:46:15 -07:00
parent 67f8c648db
commit dbf7d587ed
2 changed files with 10 additions and 0 deletions

View File

@ -41,6 +41,15 @@ public class NaiveNumber implements Number {
return new NaiveNumber(-value); return new NaiveNumber(-value);
} }
@Override
public Number intPow(int exponent) {
Number power = this;
for(int currentExponent = 1; currentExponent <= exponent; currentExponent++){
power = power.multiply(this);
}
return power;
}
@Override @Override
public int compareTo(Number number) { public int compareTo(Number number) {
NaiveNumber num = (NaiveNumber) number; NaiveNumber num = (NaiveNumber) number;

View File

@ -8,6 +8,7 @@ public interface Number {
Number add(Number summand); Number add(Number summand);
Number subtract(Number subtrahend); Number subtract(Number subtrahend);
Number negate(); Number negate();
Number intPow(int exponent);
int compareTo(Number number); int compareTo(Number number);
int signum(); int signum();