You may be better asking on the MVEL mailing list for this. My best guess is that it is a combination from the compiler knowing that the result of the + is
being assigned to a string and because all your variables are strings it uses string operations. You’d have to check but I’d also imagine that the expression string1 * string2 probably compiles to something like (String)( (number)string1 * (number)string2
) ie while within the calculation the strings are converted to numbers the result may still be a string.
Either way I think the expression is vary ambiguous and putting casts in there don’t make it messy they make it obvious what exactly your wish is.
Thomas
From: rules-users-bounces@lists.jboss.org [mailto:rules-users-bounces@lists.jboss.org]
On Behalf Of Kinshuk Adhikary
Sent: 21 December 2009 10:12
To: Rules Users List
Subject: Re: [rules-users] Re-sending : Unexpected MVEL plus operatorbehavior(string-to-double), in consequence block
Hi,
My gut instinct would say that this is possibly correct. I’ve not looked at the mvel code but if all your types are strings then it makes sense for it to pick the most type specific operator
first. Multiplication only works on numbers so it attempts to convert them but the + operator is defined on strings and therefore is a closer match for strings as you are assigning the result to a string. I haven’t tried it but you could liberally sprinkling in brackets and type casts to get what you want, eg: t.out = (double)(t.in2*t.in3) + (double)(t.in3*t.in4) + (double)(t.in2*t.in4); Thomas From: rules-users-bounces@lists.jboss.org [mailto:rules-users-bounces@lists.jboss.org]
On Behalf Of Kinshuk Adhikary
This message is confidential and intended only for the addressee. If you have received this message in error, please immediately notify the postmaster@nds.com
and delete it from your system as well as any copies. The content of e-mails as well as traffic data may be monitored by NDS for employment and security purposes.
_______________________________________________ |