commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Дмитрий Белавенцев <>
Subject [JEXL] Evaluating math expression
Date Sun, 27 Nov 2011 14:49:35 GMT
Hi! I try to use JEXL to compute math expressions like this:


But here is the problem - "^" mean xor, but not Math.pow() function. So, I
want to use the following code to compute a math expressions:

JexlEngine jexl = new JexlEngine();
Expression func = jexl.createExpression("(x1-2)^4+(x1-2*x2)^2");
MapContext mc = new MapContext();
mc.set("x1", 2);
mc.set("x2", 1);
System.out.println(func.evaluate(mc)); // prints "6" - WRONG ANSWER!

The question is the following. How can I use JEXL as math interpreter (so
"^" will be and Math.pow(), etc...)? Or it's impossible?

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message