Hi,

We've run into an issue with using JEXL due to a combination of integer 
division on integer values and narrowing of BigDecimals to Integer. Not sure if 
this type of problem has come up before. This forum only seems to have 4 jexl 
issues and the Jira didn't have anything similar either.

We use JEXL to allow our end users to write simple "Excel" like expressions. 
All the numeric variables in our expressions are presented to JEXL as 
BigDecimals.

The problem was exposed by the simple expression "(a-12)/12".

  *   If BigDecimal a = 56.1
     *   Then 56.1 - 12 -> BigDecimal 44.1
     *   Then BigDecimal 44.1 / 12 -> BigDecimal 44.1 / BigDecimal 12 -> 
BigDecimal 3.675
  *   If BigDecimal a = 56
     *   Then BigDecimal 56 - 12 -> BigDecimal 44 -> narrows to Integer 44
     *   Then Integer 44 / Integer 12 -> Integer 3! Not 3.66666 recuring 
(because division of integer values is done as integer division)

So the value of the result becomes incorrect based on the initial value of "a" 
not it's type.

A work around is to change the expression to "(a-12)/12.0" to force Double 
arithmetic, but that use of 12.0 isn't natural to ordinary users used to Excel.

Also if you had an expression like "(a-12)/(b-3)" you wouldn't have any way to 
force the use of BigDecimal division instead of integer divisions as JEXL 
chooses which based on the narrowed result value.

Also you could have a case of "a * (7/8)", e.g. 7 8ths of 'a' where the users 
is more comfortable with expression 7/8 as a faction not a decimal. Here 7/8 -> 
0 as integer division.

It would be useful if there was a way to:

  *   Force BigDecimal division not integer division
  *   Disable the narrowing to keep the intermediate and result types as 
BigDecimal.

I haven't seem anything in the JexlArithmetic class that would allow the above. 
Is there any other way to force this?

Kind regards,
Robert Lucas

NICE Systems UK Limited ("NICE") is registered in England under company number, 
3403044. The registered office of NICE is at Tollbar Way, Hedge End, 
Southampton, Hampshire SO30 2ZP.

Confidentiality: This communication and any attachments are intended for the 
above-named persons only and may be confidential and/or legally privileged. Any 
opinions expressed in this communication are not necessarily those of NICE. If 
this communication has come to you in error you must take no action based on 
it, nor must you copy or show it to anyone; please delete/destroy and inform 
the sender by e-mail immediately.

Monitoring: NICE may monitor incoming and outgoing e-mails.
Viruses: Although we have taken steps toward ensuring that this e-mail and 
attachments are free from any virus, we advise that in keeping with good 
computing practice the recipient should ensure they are actually virus free.

Reply via email to