sqrt + log10 + ln
This commit is contained in:
parent
cb5b4665cf
commit
e5f6822240
@ -33,18 +33,17 @@ public class Functions {
|
|||||||
public final static String ATANH = "atanh";
|
public final static String ATANH = "atanh";
|
||||||
|
|
||||||
public final static String LN = "ln";
|
public final static String LN = "ln";
|
||||||
public final static String LN_JSCL = "log";
|
public final static String LOG = "log";
|
||||||
|
|
||||||
public final static String MOD = "mod";
|
public final static String MOD = "mod";
|
||||||
public final static String EXP = "exp";
|
public final static String EXP = "exp";
|
||||||
|
|
||||||
public final static String SQRT = "√";
|
public final static String SQRT = "√";
|
||||||
public final static String SQRT_JSCL = "sqrt";
|
|
||||||
|
|
||||||
public static final List<String> allPrefix;
|
public static final List<String> allPrefix;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
final List<String> functions = new ArrayList<String>(Arrays.asList(SIN, SINH, ASIN, ASINH, COS, COSH, ACOS, ACOSH, TAN, TANH, ATAN, ATANH, LN, LN_JSCL, MOD, SQRT, SQRT_JSCL, EXP));
|
final List<String> functions = new ArrayList<String>(Arrays.asList(SIN, SINH, ASIN, ASINH, COS, COSH, ACOS, ACOSH, TAN, TANH, ATAN, ATANH, LN, LOG, MOD, SQRT, EXP));
|
||||||
Collections.sort(functions, new MathEntityComparator());
|
Collections.sort(functions, new MathEntityComparator());
|
||||||
allPrefix = functions;
|
allPrefix = functions;
|
||||||
}
|
}
|
||||||
|
@ -129,37 +129,7 @@ public enum MathType {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
function(1000, true, true, Functions.allPrefix) {
|
function(1000, true, true, Functions.allPrefix),
|
||||||
@Override
|
|
||||||
protected String getSubstituteToJscl(@NotNull String match) {
|
|
||||||
final String result;
|
|
||||||
|
|
||||||
if (match.equals(Functions.LN)) {
|
|
||||||
result = Functions.LN_JSCL;
|
|
||||||
} else if (match.equals(Functions.SQRT)) {
|
|
||||||
result = Functions.SQRT_JSCL;
|
|
||||||
} else {
|
|
||||||
result = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected String getSubstituteFromJscl(@NotNull String match) {
|
|
||||||
final String result;
|
|
||||||
|
|
||||||
if (match.equals(Functions.LN_JSCL)) {
|
|
||||||
result = Functions.LN;
|
|
||||||
} else if (match.equals(Functions.SQRT_JSCL)) {
|
|
||||||
result = Functions.SQRT;
|
|
||||||
} else {
|
|
||||||
result = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
constant(1100, true, true) {
|
constant(1100, true, true) {
|
||||||
@NotNull
|
@NotNull
|
||||||
@ -317,7 +287,7 @@ public enum MathType {
|
|||||||
public final static String POWER_10_JSCL = "10^";
|
public final static String POWER_10_JSCL = "10^";
|
||||||
|
|
||||||
public static final String IMAGINARY_NUMBER = "i";
|
public static final String IMAGINARY_NUMBER = "i";
|
||||||
public static final String IMAGINARY_NUMBER_JSCL = "sqrt(-1)";
|
public static final String IMAGINARY_NUMBER_JSCL = "√(-1)";
|
||||||
|
|
||||||
public static final String PI = "π";
|
public static final String PI = "π";
|
||||||
public static final String E = "e";
|
public static final String E = "e";
|
||||||
|
@ -79,7 +79,7 @@ public enum CalculatorEngine {
|
|||||||
private ThreadKiller threadKiller = new AndroidThreadKiller();
|
private ThreadKiller threadKiller = new AndroidThreadKiller();
|
||||||
|
|
||||||
// calculation thread timeout in milliseconds, after timeout thread would be interrupted
|
// calculation thread timeout in milliseconds, after timeout thread would be interrupted
|
||||||
private int timeout = 2000;
|
private int timeout = 3000;
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public String format(@NotNull Double value) {
|
public String format(@NotNull Double value) {
|
||||||
|
@ -67,12 +67,12 @@ public class CalculatorEngineTest {
|
|||||||
Assert.assertEquals("-0.757", cm.evaluate(JsclOperation.numeric, "sin(4)").getResult());
|
Assert.assertEquals("-0.757", cm.evaluate(JsclOperation.numeric, "sin(4)").getResult());
|
||||||
Assert.assertEquals("0.524", cm.evaluate(JsclOperation.numeric, "asin(0.5)").getResult());
|
Assert.assertEquals("0.524", cm.evaluate(JsclOperation.numeric, "asin(0.5)").getResult());
|
||||||
Assert.assertEquals("-0.396", cm.evaluate(JsclOperation.numeric, "sin(4)asin(0.5)").getResult());
|
Assert.assertEquals("-0.396", cm.evaluate(JsclOperation.numeric, "sin(4)asin(0.5)").getResult());
|
||||||
Assert.assertEquals("-0.56", cm.evaluate(JsclOperation.numeric, "sin(4)asin(0.5)sqrt(2)").getResult());
|
Assert.assertEquals("-0.56", cm.evaluate(JsclOperation.numeric, "sin(4)asin(0.5)√(2)").getResult());
|
||||||
Assert.assertEquals("-0.56", cm.evaluate(JsclOperation.numeric, "sin(4)asin(0.5)√(2)").getResult());
|
Assert.assertEquals("-0.56", cm.evaluate(JsclOperation.numeric, "sin(4)asin(0.5)√(2)").getResult());
|
||||||
Assert.assertEquals("7.389", cm.evaluate(JsclOperation.numeric, "e^2").getResult());
|
Assert.assertEquals("7.389", cm.evaluate(JsclOperation.numeric, "e^2").getResult());
|
||||||
Assert.assertEquals("7.389", cm.evaluate(JsclOperation.numeric, "exp(1)^2").getResult());
|
Assert.assertEquals("7.389", cm.evaluate(JsclOperation.numeric, "exp(1)^2").getResult());
|
||||||
Assert.assertEquals("7.389", cm.evaluate(JsclOperation.numeric, "exp(2)").getResult());
|
Assert.assertEquals("7.389", cm.evaluate(JsclOperation.numeric, "exp(2)").getResult());
|
||||||
Assert.assertEquals("2+i", cm.evaluate(JsclOperation.numeric, "2*1+sqrt(-1)").getResult());
|
Assert.assertEquals("2+i", cm.evaluate(JsclOperation.numeric, "2*1+√(-1)").getResult());
|
||||||
Assert.assertEquals("0.921+3.142i", cm.evaluate(JsclOperation.numeric, "ln(5cosh(38π√(2cos(2))))").getResult());
|
Assert.assertEquals("0.921+3.142i", cm.evaluate(JsclOperation.numeric, "ln(5cosh(38π√(2cos(2))))").getResult());
|
||||||
Assert.assertEquals("7.389i", cm.evaluate(JsclOperation.numeric, "iexp(2)").getResult());
|
Assert.assertEquals("7.389i", cm.evaluate(JsclOperation.numeric, "iexp(2)").getResult());
|
||||||
Assert.assertEquals("2+7.389i", cm.evaluate(JsclOperation.numeric, "2+iexp(2)").getResult());
|
Assert.assertEquals("2+7.389i", cm.evaluate(JsclOperation.numeric, "2+iexp(2)").getResult());
|
||||||
@ -118,12 +118,12 @@ public class CalculatorEngineTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
/* try {
|
||||||
cm.setTimeout(5000);
|
cm.setTimeout(5000);
|
||||||
Assert.assertEquals("2", cm.evaluate(JsclOperation.numeric, "2!").getResult());
|
Assert.assertEquals("2", cm.evaluate(JsclOperation.numeric, "2!").getResult());
|
||||||
} finally {
|
} finally {
|
||||||
cm.setTimeout(2000);
|
cm.setTimeout(3000);
|
||||||
}
|
}*/
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,8 +58,8 @@ public class FromJsclSimplifyTextProcessorTest {
|
|||||||
Assert.assertEquals("(te+2k)e[k+2te]", tp.process("(t*e+2*k)*e*[k+2*t*e]"));
|
Assert.assertEquals("(te+2k)e[k+2te]", tp.process("(t*e+2*k)*e*[k+2*t*e]"));
|
||||||
|
|
||||||
|
|
||||||
Assert.assertEquals("tln(3)", tp.process("t*log(3)"));
|
Assert.assertEquals("tlog(3)", tp.process("t*log(3)"));
|
||||||
Assert.assertEquals("t√(3)", tp.process("t*sqrt(3)"));
|
Assert.assertEquals("t√(3)", tp.process("t*√(3)"));
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -42,16 +42,16 @@ public class ToJsclTextProcessorTest {
|
|||||||
Assert.assertEquals( "(0)*(1*10^-1)", preprocessor.process("[0][1E-1]").toString());
|
Assert.assertEquals( "(0)*(1*10^-1)", preprocessor.process("[0][1E-1]").toString());
|
||||||
Assert.assertEquals( "(0)*(1.*10^-1)", preprocessor.process("[0][1.E-1]").toString());
|
Assert.assertEquals( "(0)*(1.*10^-1)", preprocessor.process("[0][1.E-1]").toString());
|
||||||
Assert.assertEquals( "(0)*(2*10^-1)", preprocessor.process("[0][2*E-1]").toString());
|
Assert.assertEquals( "(0)*(2*10^-1)", preprocessor.process("[0][2*E-1]").toString());
|
||||||
Assert.assertEquals( "(0)*log(1)*(2*10^-1)", preprocessor.process("[0]ln(1)[2*E-1]").toString());
|
Assert.assertEquals( "(0)*ln(1)*(2*10^-1)", preprocessor.process("[0]ln(1)[2*E-1]").toString());
|
||||||
Assert.assertEquals( "sin(4)*asin(0.5)*sqrt(2)", preprocessor.process("sin(4)asin(0.5)sqrt(2)").toString());
|
Assert.assertEquals( "sin(4)*asin(0.5)*√(2)", preprocessor.process("sin(4)asin(0.5)√(2)").toString());
|
||||||
Assert.assertEquals( "sin(4)*cos(5)", preprocessor.process("sin(4)cos(5)").toString());
|
Assert.assertEquals( "sin(4)*cos(5)", preprocessor.process("sin(4)cos(5)").toString());
|
||||||
Assert.assertEquals( "3.141592653589793*sin(4)*3.141592653589793*cos(sqrt(5))", preprocessor.process("πsin(4)πcos(√(5))").toString());
|
Assert.assertEquals( "3.141592653589793*sin(4)*3.141592653589793*cos(√(5))", preprocessor.process("πsin(4)πcos(√(5))").toString());
|
||||||
Assert.assertEquals( "3.141592653589793*sin(4)+3.141592653589793*cos(sqrt(5))", preprocessor.process("πsin(4)+πcos(√(5))").toString());
|
Assert.assertEquals( "3.141592653589793*sin(4)+3.141592653589793*cos(√(5))", preprocessor.process("πsin(4)+πcos(√(5))").toString());
|
||||||
Assert.assertEquals( "3.141592653589793*sin(4)+3.141592653589793*cos(sqrt(5+sqrt(-1)))", preprocessor.process("πsin(4)+πcos(√(5+i))").toString());
|
Assert.assertEquals( "3.141592653589793*sin(4)+3.141592653589793*cos(√(5+√(-1)))", preprocessor.process("πsin(4)+πcos(√(5+i))").toString());
|
||||||
Assert.assertEquals( "3.141592653589793*sin(4.01)+3.141592653589793*cos(sqrt(5+sqrt(-1)))", preprocessor.process("πsin(4.01)+πcos(√(5+i))").toString());
|
Assert.assertEquals( "3.141592653589793*sin(4.01)+3.141592653589793*cos(√(5+√(-1)))", preprocessor.process("πsin(4.01)+πcos(√(5+i))").toString());
|
||||||
Assert.assertEquals( "2.718281828459045^3.141592653589793*sin(4.01)+3.141592653589793*cos(sqrt(5+sqrt(-1)))", preprocessor.process("e^πsin(4.01)+πcos(√(5+i))").toString());
|
Assert.assertEquals( "2.718281828459045^3.141592653589793*sin(4.01)+3.141592653589793*cos(√(5+√(-1)))", preprocessor.process("e^πsin(4.01)+πcos(√(5+i))").toString());
|
||||||
Assert.assertEquals( "2.718281828459045^3.141592653589793*sin(4.01)+3.141592653589793*cos(sqrt(5+sqrt(-1)))*10^2", preprocessor.process("e^πsin(4.01)+πcos(√(5+i))E2").toString());
|
Assert.assertEquals( "2.718281828459045^3.141592653589793*sin(4.01)+3.141592653589793*cos(√(5+√(-1)))*10^2", preprocessor.process("e^πsin(4.01)+πcos(√(5+i))E2").toString());
|
||||||
Assert.assertEquals( "2.718281828459045^3.141592653589793*sin(4.01)+3.141592653589793*cos(sqrt(5+sqrt(-1)))*10^-2", preprocessor.process("e^πsin(4.01)+πcos(√(5+i))E-2").toString());
|
Assert.assertEquals( "2.718281828459045^3.141592653589793*sin(4.01)+3.141592653589793*cos(√(5+√(-1)))*10^-2", preprocessor.process("e^πsin(4.01)+πcos(√(5+i))E-2").toString());
|
||||||
Assert.assertEquals( "10^2", preprocessor.process("E2").toString());
|
Assert.assertEquals( "10^2", preprocessor.process("E2").toString());
|
||||||
Assert.assertEquals( "10^-2", preprocessor.process("E-2").toString());
|
Assert.assertEquals( "10^-2", preprocessor.process("E-2").toString());
|
||||||
Assert.assertEquals( "10^-1/2", preprocessor.process("E-1/2").toString());
|
Assert.assertEquals( "10^-1/2", preprocessor.process("E-1/2").toString());
|
||||||
|
Loading…
Reference in New Issue
Block a user