Uploaded image for project: 'JBRULES'
  1. JBRULES
  2. JBRULES-3338

Accuracy lost when comparing numbers

This issue belongs to an archived project. You can view it, but you can't modify it. Learn more

    XMLWordPrintable

Details

    • Hide

      Run the code below with default settings:

      rule "out"
      when
      Msg(intVal == 5.5)
      then
      end

      The int value named 'intVal' in pojo object 'Msg' is '5'.
      I think the rule should not be fired cause 5 != 5.5 but it was.

      Show
      Run the code below with default settings: rule "out" when Msg(intVal == 5.5) then end The int value named 'intVal' in pojo object 'Msg' is '5'. I think the rule should not be fired cause 5 != 5.5 but it was.
    • Workaround Exists
    • Hide

      Write down the 'wider' type first in a comparison.

      Show
      Write down the 'wider' type first in a comparison.
    • Medium

    Description

      Accuracy lost when comparing two numbers which has different number types. for example:
      I have a pojo fact class 'Msg.java', and it has a int field named 'intVal', which value is inited 5.
      And I write down this rule and run with default settings:

      rule "out"
      when
      Msg(intVal == 5.5)
      then
      end

      this rule would fire! but it shouldn't, cause 5 != 5.5.

      It seems that drools converts the second operand of a comparison to the type of the first, no matter what the first number's type is. This definitely caused some accuracy lost in many cases.

      if I wrote Msg(5.5 == intVal), the code behaves correctly.

      Attachments

        Activity

          People

            mproctor@redhat.com Mark Proctor
            pf_miles Miles Wen (Inactive)
            Archiver:
            rhn-support-ceverson Clark Everson

            Dates

              Created:
              Updated:
              Archived:

              PagerDuty