[rules-users] [rules user] different behavior on double type

Zeke xanadu860122 at gmail.com
Mon Mar 26 03:58:33 EDT 2012


Hi, guys:
  I am using Drools 4.0.7. I find a strange behavior. When my LHS is
"Message( varDouble == 99.9 )" and "varDouble" equals "new Double(99.9)",
the condition is true. But when my LHS is "Message( types.doubleType ==
99.9 )" and the "doubleType" field is also equal to "new Double(99.9)", the
condition is false. I debug the code, and find that:

  When the LHS is "Message( varDouble == 99.9 )", the logic will handle the
literal 99.9 as *Double.valueOf( “99.9” )*, and the comparison is between *(new
Double(99.9)).doubleValue(*) and *Double.valueOf( “99.9” ).doubleValue()*,
  When the LHS is "Message( types.doubleType == 99.9 )", the logic is
different from above. The comparison is between *new BigDecimal((Double)
99.9, MathContext.DECIMAL64)* (which double value is 99.90000000000001) and
*new BigDecimal(“99.9”, MathContext.DECIMAL64)* (which double value is
99.9).

  I think we need make things consistent. "varDouble" and
"types.doubleType" are of the same type and value. It doesn't make sense to
have different behavior just because of one field is nesting while the
other is not.  I know Drools is using MVEL to evaluate the condition. But I
am not sure it is a MVEL bug or Drools uses MVEL wrong. It will be much
appreciated if you can give me any comments!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20120326/b2988acb/attachment.html 


More information about the rules-users mailing list