mirror of
https://github.com/DanilaFe/abacus
synced 2025-01-09 15:54:13 -08:00
Remove the NumberInterface::intPow method.
This commit is contained in:
parent
b7152da58d
commit
4f94700aef
@ -66,23 +66,6 @@ public class NaiveNumber extends NumberInterface {
|
|||||||
return new NaiveNumber(-value);
|
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
|
@Override
|
||||||
public int compareTo(NumberInterface number) {
|
public int compareTo(NumberInterface number) {
|
||||||
NaiveNumber num = (NaiveNumber) number;
|
NaiveNumber num = (NaiveNumber) number;
|
||||||
|
@ -134,27 +134,6 @@ public abstract class NumberInterface {
|
|||||||
return negateInternal();
|
return negateInternal();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Raises this number to an integer power.
|
|
||||||
*
|
|
||||||
* @param exponent the exponent to which to take the number.
|
|
||||||
* @return the resulting value.
|
|
||||||
*/
|
|
||||||
protected abstract NumberInterface intPowInternal(int exponent);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Raises this number to an integer power. Also, checks if the
|
|
||||||
* thread has been interrupted, and if so, throws
|
|
||||||
* an exception.
|
|
||||||
*
|
|
||||||
* @param exponent the exponent to which to take the number.
|
|
||||||
* @return the resulting value.
|
|
||||||
*/
|
|
||||||
public final NumberInterface intPow(int exponent){
|
|
||||||
checkInterrupted();
|
|
||||||
return intPowInternal(exponent);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Compares this number to another.
|
* Compares this number to another.
|
||||||
*
|
*
|
||||||
|
@ -71,23 +71,6 @@ public class PreciseNumber extends NumberInterface {
|
|||||||
return new PreciseNumber(value.subtract(((PreciseNumber) subtrahend).value));
|
return new PreciseNumber(value.subtract(((PreciseNumber) subtrahend).value));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public NumberInterface intPowInternal(int exponent) {
|
|
||||||
if (exponent == 0) {
|
|
||||||
return PreciseNumber.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 = PreciseNumber.ONE.divide(power);
|
|
||||||
}
|
|
||||||
return power;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int compareTo(NumberInterface number) {
|
public int compareTo(NumberInterface number) {
|
||||||
return value.compareTo(((PreciseNumber) number).value);
|
return value.compareTo(((PreciseNumber) number).value);
|
||||||
|
@ -311,7 +311,9 @@ public class StandardPlugin extends Plugin {
|
|||||||
//right and left refer to lhs and rhs in the above inequality.
|
//right and left refer to lhs and rhs in the above inequality.
|
||||||
NumberInterface sum = NaiveNumber.ONE.promoteTo(params[0].getClass());
|
NumberInterface sum = NaiveNumber.ONE.promoteTo(params[0].getClass());
|
||||||
NumberInterface nextNumerator = params[0];
|
NumberInterface nextNumerator = params[0];
|
||||||
NumberInterface left = params[0].multiply((new NaiveNumber(3)).promoteTo(params[0].getClass()).intPow(params[0].ceiling().intValue())), right = maxError;
|
NumberInterface left = params[0].multiply((new NaiveNumber(3)).promoteTo(params[0].getClass()));
|
||||||
|
left = intPow(left, left.getClass(), new NaiveNumber(params[0].ceiling().intValue()).promoteTo(left.getClass()));
|
||||||
|
NumberInterface right = maxError;
|
||||||
do {
|
do {
|
||||||
sum = sum.add(nextNumerator.divide(factorial(params[0].getClass(), n + 1)));
|
sum = sum.add(nextNumerator.divide(factorial(params[0].getClass(), n + 1)));
|
||||||
n++;
|
n++;
|
||||||
@ -470,7 +472,7 @@ public class StandardPlugin extends Plugin {
|
|||||||
* @return the maximum error.
|
* @return the maximum error.
|
||||||
*/
|
*/
|
||||||
private static NumberInterface getMaxError(NumberInterface number) {
|
private static NumberInterface getMaxError(NumberInterface number) {
|
||||||
return (new NaiveNumber(10)).promoteTo(number.getClass()).intPow(-number.getMaxPrecision());
|
return intPow(new NaiveNumber(10).promoteTo(number.getClass()), number.getClass(), new NaiveNumber(-number.getMaxPrecision()).promoteTo(number.getClass()));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user