[rules-users] Issues with float/double constants

Andrey Grin andrey.grin at gmail.com
Sat Mar 1 07:39:59 EST 2008


Hi,

I have two issues with float/double constants. In both cases dialect is set
to MVEL

Issue 1

If I use a comparison operator with the Double value it doesn't seem to work
correctly w/o brackets in the right part of the expression:

Example:
I have a condition like:
NumberVariable( owner == $a, name == "PTI", value > 0.5)

In the class NumberVariable the method getValue() is declared as follows:
public Number getValue();

In the working memory I have an instance with name == "PTI" and value ==
0.9633716684527102 ( actual type of the value is  Double).

And the rule consequence is not executed.

If I change it and add brackets around the constant everything works
correctly:

NumberVariable( owner == $a, name == "PTI", value > (0.5) )

There is similar example in drools documentation (w/o brackets):

Cheese( type == "stilton", price < 10, age == "mature" )

I assume that in this example the property has a primitive type and in my
case autoboxing is involved, but why brackets are necessary in my case?


Issue 2

I have a rule:

rule "Determine min PRI for for PROD2"  ruleflow-group
"budget_calculated_variables_appl"
    when
        $a: RetailApplication( )
        StringVariable(name=="prodid", value matches CONST.PROD2)
    then
        insert(new NumberVariable("minPTI", 0.6, $a));
end

Initially I had only one constructor for NumberVariable:

public NumberVariable(String pName, Number pValue, Object pOwner)

But MVEL couldn't find this constructor when "then" part was executed
(runtime exception).
The problem was solved when I added another constructor:

public NumberVariable(String pName, float pValue, Object pOwner)

Java compiler accepts identical code when only first constructor is there:

NumberVariable nv = new NumberVariable("minPTI", 0.6, null);

Drools version: 4.04, Java version: 1.6

Thanks,
Andrey.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20080301/737b0516/attachment.html 


More information about the rules-users mailing list