[
https://issues.jboss.org/browse/JBRULES-1322?page=com.atlassian.jira.plug...
]
Edson Tirelli commented on JBRULES-1322:
----------------------------------------
Geoffrey,
Just for documentation purposes for possible readers of this thread, I will state here
what we discussed before:
* the problem you describe is inherent to the accumulate function implementation of the
default functions that ship with drools. On the other hand, anyone dealing with data that
requires precision can easily implement their own accumulate functions using BigDecimal,
BigIntegers or whatever data type best fits their requirement and they will have no
rounding problems at all.
* the automatic selection of different functions based on the result type of the
expression is tricky as it is not always possible to determine the result type. It would
also be dangerous to those same users that you mention (like those doing financial
calculations) as they must guarantee that a given function implementation is being used
and not let the engine chose based on types that can mutate due to inheritance. Finally,
it also requires users to always provide multiple function implementations for each
datatype supported. I still intend to add a feature to do that, but at the moment I am not
convinced this is the best way of doing it, so I haven't prioritized this ticket yet.
If anyone has a better suggestion, I am open to ideas.
Edson
Build in accumulate functions are highly unreliable for long's
and BigDecimals
------------------------------------------------------------------------------
Key: JBRULES-1322
URL:
https://issues.jboss.org/browse/JBRULES-1322
Project: Drools
Issue Type: Bug
Security Level: Public(Everyone can see)
Components: drools-compiler
Affects Versions: 4.0.3
Reporter: Geoffrey De Smet
Assignee: Edson Tirelli
Priority: Critical
Fix For: 5.2.0.CR1
Attachments: JBRULES-1322-testcase.patch
When dealing with financial data, one should never ever use double's. Instead
BigDecimal should be used.
Not because BigDecimal is bigger (that's rarely a problem) but because it doesn't
do any decimal to binary transformation.
For example, it's impossible for a double to correctly represent "0.2", aka
1/5.
Summing many doubles (or even a few differing in scale), can easily give wrong results
(and for financial data this tends to be important).
Using doubles to sum longs have the exact same problem.
Attached is a testcase patch which proves this by checking if (MAX_LONG - 4L) and 3L sum
up to be (MAX_LONG - 1L).
Currently they don't.
One possible way to solve this is to fix JBRULES-1075,
which just happens to give drools-solver 3% more performance ;) what a coincidence ^^
--
This message is automatically generated by JIRA.
For more information on JIRA, see:
http://www.atlassian.com/software/jira