1
0
mirror of https://github.com/DanilaFe/abacus synced 2024-12-22 15:30:09 -08:00

Merge branch 'inv-trig'

# Conflicts:
#	src/main/java/org/nwapw/abacus/plugin/StandardPlugin.java
This commit is contained in:
Danila Fedorin 2017-08-11 22:13:20 -07:00
commit 00c51c62fd

View File

@ -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) { public StandardPlugin(PluginManager manager) {
super(manager); super(manager);
} }
@ -714,16 +771,20 @@ public class StandardPlugin extends Plugin {
registerFunction("exp", FUNCTION_EXP); registerFunction("exp", FUNCTION_EXP);
registerFunction("ln", FUNCTION_LN); registerFunction("ln", FUNCTION_LN);
registerFunction("sqrt", FUNCTION_SQRT); registerFunction("sqrt", FUNCTION_SQRT);
registerFunction("sin", functionSin); registerFunction("sin", functionSin);
registerFunction("cos", functionCos); registerFunction("cos", functionCos);
registerFunction("tan", functionTan); registerFunction("tan", functionTan);
registerFunction("sec", functionSec); registerFunction("sec", functionSec);
registerFunction("csc", functionCsc); registerFunction("csc", functionCsc);
registerFunction("cot", functionCot); registerFunction("cot", functionCot);
registerFunction("arcsin", functionArcsin); registerFunction("arcsin", functionArcsin);
registerFunction("arccos", functionArccos); registerFunction("arccos", functionArccos);
registerFunction("arccsc", functionArccsc); registerFunction("arctan", functionArctan);
registerFunction("arcsec", functionArcsec); registerFunction("arcsec", functionArcsec);
registerFunction("arccsc", functionArccsc);
registerFunction("arccot", functionArccot);
registerFunction("random_int", FUNCTION_RAND_INT); registerFunction("random_int", FUNCTION_RAND_INT);