commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Дмитрий Белавенцев <dizp...@gmail.com>
Subject Re: [JEXL] Evaluating math expression
Date Mon, 28 Nov 2011 13:09:54 GMT
Hm, I steel have wrong answer. Here is my code:

1. Test class http://pastebin.com/92ufGBW1
2. NelderMead class http://pastebin.com/Y7tP80Gd
3. Class overriding XOR with Math.pow() http://pastebin.com/BGaX4g7R

Could you point me on my mistake?

TIA!

---
Best regards,
Dmitry!

2011/11/27 henrib <henrib@apache.org>

> Hi;
> You can use JEXL as a math interpreter but you need to derive
> JexlArithmetic
> to fit your purpose.
> this means, create your own JexlArithmeticWithPow class, overload the
> method
> bitwiseXor to perform pow and create your JexlEngine instance with an
> instance of that class.
> For example:
> <code>
>    public static class WithPow extends
> org.apache.commons.jexl2.JexlArithmetic {
>        public WithPow(boolean lenient) {
>            super(lenient);
>        }
>
>        public Object bitwiseXor(Object left, Object right) {
>            double l = toDouble(left);
>            double r = toDouble(right);
>            return Math.pow(l, r);
>        }
>    }
>
>    public void test120() throws Exception {
>        JexlEngine jexl = new JexlEngine(null, new WithPow(true), null,
> null);
>         Expression func = jexl.createExpression("(x1-2)^4+(x1-2*x2)^2");
>        MapContext mc = new MapContext();
>        mc.set("x1", 2);
>        mc.set("x2", 1);
>         assertEquals(0, func.evaluate(mc));
>    }
> </code>
> Hope this helps,
> Regards
> Henrib
>
> --
> View this message in context:
> http://apache-commons.680414.n4.nabble.com/JEXL-Evaluating-math-expression-tp4112606p4112799.html
> Sent from the Commons - User mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
>
>

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