From b9c928d66fa2ecd8fb61b67442341feeeae14966 Mon Sep 17 00:00:00 2001 From: Arthur Drobot Date: Mon, 7 Aug 2017 18:13:18 -0700 Subject: [PATCH] Modify exp to use the non-alternating series and take a reciprocal in the case of a negative argument. --- .../java/org/nwapw/abacus/plugin/StandardPlugin.java | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/nwapw/abacus/plugin/StandardPlugin.java b/src/main/java/org/nwapw/abacus/plugin/StandardPlugin.java index 3f2ce22..d30c265 100755 --- a/src/main/java/org/nwapw/abacus/plugin/StandardPlugin.java +++ b/src/main/java/org/nwapw/abacus/plugin/StandardPlugin.java @@ -303,14 +303,9 @@ public class StandardPlugin extends Plugin { protected NumberInterface applyInternal(NumberInterface[] params) { NumberInterface maxError = params[0].getMaxError(); int n = 0; - if (params[0].signum() <= 0) { - NumberInterface currentTerm = NaiveNumber.ONE.promoteTo(params[0].getClass()), sum = currentTerm; - while (FUNCTION_ABS.apply(currentTerm).compareTo(maxError) > 0) { - n++; - currentTerm = currentTerm.multiply(params[0]).divide((new NaiveNumber(n)).promoteTo(params[0].getClass())); - sum = sum.add(currentTerm); - } - return sum; + if (params[0].signum() < 0) { + NumberInterface[] negatedParams = {params[0].negate()}; + return fromInt(params[0].getClass(), 1).divide(applyInternal(negatedParams)); } else { //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.