diff --git a/src/main/java/org/nwapw/abacus/plugin/StandardPlugin.java b/src/main/java/org/nwapw/abacus/plugin/StandardPlugin.java index 932f90f..3705621 100755 --- a/src/main/java/org/nwapw/abacus/plugin/StandardPlugin.java +++ b/src/main/java/org/nwapw/abacus/plugin/StandardPlugin.java @@ -600,6 +600,63 @@ public class StandardPlugin extends Plugin { } }; + /** + * The arctangent function. + */ + public final Function functionArctan = new Function() { + @Override + protected boolean matchesParams(NumberInterface[] params) { + return params.length == 1; + } + + @Override + protected NumberInterface applyInternal(NumberInterface[] params) { + if(params[0].signum() == -1){ + NumberInterface[] negatedParams = {params[0].negate()}; + return applyInternal(negatedParams).negate(); + } + if(params[0].compareTo(fromInt(params[0].getClass(), 1)) > 0){ + NumberInterface[] reciprocalParams = {fromInt(params[0].getClass(), 1).divide(params[0])}; + return piFor(params[0].getClass()).divide(fromInt(params[0].getClass(), 2)) + .subtract(applyInternal(reciprocalParams)); + } + if(params[0].compareTo(fromInt(params[0].getClass(), 1)) == 0){ + return piFor(params[0].getClass()).divide(fromInt(params[0].getClass(), 4)); + } + if(params[0].compareTo(new NaiveNumber(0.9).promoteTo(params[0].getClass())) >= 0){ + NumberInterface[] newParams = {params[0].multiply(fromInt(params[0].getClass(),2 )) + .divide(fromInt(params[0].getClass(), 1).subtract(params[0].multiply(params[0])))}; + return applyInternal(newParams).divide(fromInt(params[0].getClass(), 2)); + } + NumberInterface currentPower = params[0], currentTerm = currentPower, sum = currentTerm, + maxError = params[0].getMaxError(), multiplier = currentPower.multiply(currentPower).negate(); + int n = 1; + while(FUNCTION_ABS.apply(currentTerm).compareTo(maxError) > 0){ + n += 2; + currentPower = currentPower.multiply(multiplier); + currentTerm = currentPower.divide(fromInt(currentPower.getClass(), n)); + sum = sum.add(currentTerm); + } + return sum; + } + }; + + /** + * The arccotangent function. Range: (0, pi). + */ + public final Function functionArccot = new Function() { + @Override + protected boolean matchesParams(NumberInterface[] params) { + return params.length == 1; + } + + @Override + protected NumberInterface applyInternal(NumberInterface[] params) { + return piFor(params[0].getClass()).divide(fromInt(params[0].getClass(), 2)) + .subtract(functionArctan.apply(params)); + } + }; + public StandardPlugin(PluginManager manager) { super(manager); } @@ -714,16 +771,20 @@ public class StandardPlugin extends Plugin { registerFunction("exp", FUNCTION_EXP); registerFunction("ln", FUNCTION_LN); registerFunction("sqrt", FUNCTION_SQRT); + registerFunction("sin", functionSin); registerFunction("cos", functionCos); registerFunction("tan", functionTan); registerFunction("sec", functionSec); registerFunction("csc", functionCsc); registerFunction("cot", functionCot); + registerFunction("arcsin", functionArcsin); registerFunction("arccos", functionArccos); - registerFunction("arccsc", functionArccsc); + registerFunction("arctan", functionArctan); registerFunction("arcsec", functionArcsec); + registerFunction("arccsc", functionArccsc); + registerFunction("arccot", functionArccot); registerFunction("random_int", FUNCTION_RAND_INT);