[rules-users] OT:Order of operations

Hehl, Thomas Thomas.Hehl at acs-inc.com
Wed Apr 9 14:40:47 EDT 2008


Anyone else use Please Excuse My Dear Aunt Sally? (Parentheses,
Exponentiation, Multiplication, Division, Addition, Subtraction)

 

 

  _____  

From: rules-users-bounces at lists.jboss.org
[mailto:rules-users-bounces at lists.jboss.org] On Behalf Of Edson Tirelli
Sent: Wednesday, April 09, 2008 2:39 PM
To: Rules Users List
Subject: Re: [rules-users] Order of operations

 


   Hi Joe,

   It seems someone skipped the elementary math lessons at school... :(

   Will open a JIRA for that.

   []s
   Edson

2008/4/9 Joe White <Joe.White at recondotech.com
<mailto:Joe.White at recondotech.com> >:

I have a question regarding order of operations in the consequence of a rule
when using the mvel dialect. When executed the Drl below provides Right
=30.0 and Wrong =140.0. The only difference is the parens around the
multiplying expressions, which shouldn't be necessary given order of
operations. Is this a problem with the drools/mvel interaction or is it
completely an issue with mvel? 

 

Is the general expectation that all expressions must be completely scoped by
parens when using mvel? 

 

package test;

dialect "mvel"

rule "test 11"

    when

 

    then

        double rightVal=((10-5)*2) + (5*(8-4));

        double wrongVal=(10-5)*2 + 5*(8-4);

 

        System.out.println("Right ="+rightVal);

        System.out.println("Wrong ="+wrongVal);

End

 

After execution:

Right =30.0 

Wrong =140.0

 

 

Thank you for all of your help. We are using drools 4.0.4. <http://4.0.4.> 

 

Joe

 

Also, I haven't figured out how it arrives at 140. The following format also
produces 140, which seems a little more strange.

        double wrongVal=10-5*2 + 5*8-4;

 

 

 


_______________________________________________
rules-users mailing list
rules-users at lists.jboss.org <mailto:rules-users at lists.jboss.org> 
https://lists.jboss.org/mailman/listinfo/rules-users
<https://lists.jboss.org/mailman/listinfo/rules-users> 




-- 
Edson Tirelli
JBoss Drools Core Development
Office: +55 11 3529-6000
Mobile: +55 11 9287-5646
JBoss, a division of Red Hat @ www.jboss.com <http://www.jboss.com>  

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20080409/058f77ab/attachment.html 


More information about the rules-users mailing list