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:
parent
67f8c648db
commit
dbf7d587ed
|
@ -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;
|
||||||
|
|
|
@ -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();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user