mirror of
https://github.com/DanilaFe/abacus
synced 2024-12-22 23:40:08 -08:00
Modify exp to use the non-alternating series and take a reciprocal in the case of a negative argument.
This commit is contained in:
parent
ed92b382f0
commit
68fbcd2d7c
|
@ -303,14 +303,9 @@ public class StandardPlugin extends Plugin {
|
||||||
protected NumberInterface applyInternal(NumberInterface[] params) {
|
protected NumberInterface applyInternal(NumberInterface[] params) {
|
||||||
NumberInterface maxError = params[0].getMaxError();
|
NumberInterface maxError = params[0].getMaxError();
|
||||||
int n = 0;
|
int n = 0;
|
||||||
if (params[0].signum() <= 0) {
|
if (params[0].signum() < 0) {
|
||||||
NumberInterface currentTerm = NaiveNumber.ONE.promoteTo(params[0].getClass()), sum = currentTerm;
|
NumberInterface[] negatedParams = {params[0].negate()};
|
||||||
while (FUNCTION_ABS.apply(currentTerm).compareTo(maxError) > 0) {
|
return fromInt(params[0].getClass(), 1).divide(applyInternal(negatedParams));
|
||||||
n++;
|
|
||||||
currentTerm = currentTerm.multiply(params[0]).divide((new NaiveNumber(n)).promoteTo(params[0].getClass()));
|
|
||||||
sum = sum.add(currentTerm);
|
|
||||||
}
|
|
||||||
return sum;
|
|
||||||
} else {
|
} else {
|
||||||
//We need n such that x^(n+1) * 3^ceil(x) <= maxError * (n+1)!.
|
//We need n such that x^(n+1) * 3^ceil(x) <= maxError * (n+1)!.
|
||||||
//right and left refer to lhs and rhs in the above inequality.
|
//right and left refer to lhs and rhs in the above inequality.
|
||||||
|
|
Loading…
Reference in New Issue
Block a user