From ca6d8d2ba2689db3a45cacdec2dc7732ae8c5df3 Mon Sep 17 00:00:00 2001 From: Arthur Drobot Date: Wed, 9 Aug 2017 12:47:43 -0700 Subject: [PATCH] Add arcsin. --- .../nwapw/abacus/plugin/StandardPlugin.java | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/main/java/org/nwapw/abacus/plugin/StandardPlugin.java b/src/main/java/org/nwapw/abacus/plugin/StandardPlugin.java index d30c265..cad9445 100755 --- a/src/main/java/org/nwapw/abacus/plugin/StandardPlugin.java +++ b/src/main/java/org/nwapw/abacus/plugin/StandardPlugin.java @@ -451,6 +451,40 @@ public class StandardPlugin extends Plugin { } }; + /** + * The arcsin function (return type in radians). + * @param manager + */ + public final Function functionArcsin = new Function() { + @Override + protected boolean matchesParams(NumberInterface[] params) { + return params.length == 1 + && FUNCTION_ABS.apply(params[0]).compareTo(fromInt(params[0].getClass(), 1)) <= 0; + } + + @Override + protected NumberInterface applyInternal(NumberInterface[] params) { + if(FUNCTION_ABS.apply(params[0]).compareTo(new NaiveNumber(0.8).promoteTo(params[0].getClass())) >= 0){ + NumberInterface[] newParams = {FUNCTION_SQRT.apply(fromInt(params[0].getClass(), 1).subtract(params[0].multiply(params[0])))}; + return piFor(params[0].getClass()).divide(fromInt(params[0].getClass(), 2)) + .subtract(applyInternal(newParams)).multiply(fromInt(params[0].getClass(), params[0].signum())); + } + NumberInterface currentTerm = params[0], sum = currentTerm, + multiplier = currentTerm.multiply(currentTerm), summandBound = sum.getMaxError().multiply(fromInt(sum.getClass(), 1).subtract(multiplier)), + power = currentTerm, coefficient = fromInt(params[0].getClass(), 1); + int exponent = 1; + while(FUNCTION_ABS.apply(currentTerm).compareTo(summandBound) > 0){ + exponent += 2; + power = power.multiply(multiplier); + coefficient = coefficient.multiply(fromInt(params[0].getClass(), exponent-2)) + .divide(fromInt(params[0].getClass(), exponent - 1)); + currentTerm = power.multiply(coefficient).divide(fromInt(power.getClass(), exponent)); + sum = sum.add(currentTerm); + } + return sum; + } + }; + public StandardPlugin(PluginManager manager) { super(manager); } @@ -568,6 +602,7 @@ public class StandardPlugin extends Plugin { registerFunction("sec", functionSec); registerFunction("csc", functionCsc); registerFunction("cot", functionCot); + registerFunction("arcsin", functionArcsin); } @Override