use of org.matheclipse.parser.client.eval.DoubleEvaluator in project symja_android_library by axkr.
the class EvalDoubleCallbackTestCase method testEval006.
public void testEval006() {
try {
DoubleEvaluator engine = new DoubleEvaluator();
BooleanVariable vb = new BooleanVariable(true);
engine.defineVariable("$1", vb);
BooleanVariable vb2 = new BooleanVariable(true);
engine.defineVariable("$2", vb2);
double d = engine.evaluate("If[$1 && $2, 1, 0]");
Assert.assertEquals(d, 1d, DoubleEvaluator.EPSILON);
vb.setValue(false);
d = engine.evaluate();
Assert.assertEquals(d, 0d, DoubleEvaluator.EPSILON);
} catch (Exception e) {
e.printStackTrace();
Assert.assertEquals("", e.getMessage());
}
}
use of org.matheclipse.parser.client.eval.DoubleEvaluator in project symja_android_library by axkr.
the class EvalDoubleCallbackTestCase method testEval003.
public void testEval003() {
try {
DoubleEvaluator engine = new DoubleEvaluator();
double d = engine.evaluate("Sin[Pi/2*Cos[Pi]]");
assertEquals(Double.toString(d), "-1.0");
} catch (Exception e) {
e.printStackTrace();
assertEquals("", e.getMessage());
}
}
use of org.matheclipse.parser.client.eval.DoubleEvaluator in project symja_android_library by axkr.
the class EvalDoubleCallbackTestCase method testEval007.
public void testEval007() {
try {
DoubleEvaluator engine = new DoubleEvaluator();
// IDoubleValue vdi = new DoubleVariable(1.0);
// engine.defineVariable("$i", vdi);
IDoubleValue vd = new DoubleVariable(3.0);
engine.defineVariable("$1", vd);
IDoubleValue vd2 = new DoubleVariable(-4.0);
engine.defineVariable("$2", vd2);
double d = engine.evaluate("$i = $1+$2; If[$i>0, 1, -1]");
Assert.assertEquals(d, -1d, DoubleEvaluator.EPSILON);
vd2.setValue(4.0);
d = engine.evaluate();
Assert.assertEquals(d, 1d, DoubleEvaluator.EPSILON);
} catch (Exception e) {
e.printStackTrace();
Assert.assertEquals("", e.getMessage());
}
}
use of org.matheclipse.parser.client.eval.DoubleEvaluator in project symja_android_library by axkr.
the class Console method interpreter.
/**
* Evaluates the given string-expression and returns the result in string form.
*
* @param strEval
* @return the result in string for
*/
public String interpreter(final String strEval) {
try {
DoubleEvaluator engine = new DoubleEvaluator(true);
double d = engine.evaluate(strEval);
return Double.toString(d);
} catch (MathException e) {
System.err.println();
System.err.println(e.getMessage());
} catch (RuntimeException e) {
e.printStackTrace();
}
return "";
}
Aggregations