You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Henri Biestro (Jira)" <ji...@apache.org> on 2023/10/10 07:31:00 UTC

[jira] [Resolved] (JEXL-407) Sum of values shows incorrect

     [ https://issues.apache.org/jira/browse/JEXL-407?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Henri Biestro resolved JEXL-407.
--------------------------------
    Fix Version/s: 3.3
       Resolution: Not A Bug

As surprising as it may be, the result is coherent with IEEE 754 computations on binary64 (used by most computers nowadays).

The following test illustrates Java vs JEXL (double) vs JEXL (BigDecimal); none of the 3 will return a 0.
{code:java}
@Test
public void test407() {
  // Java version
  double r = 99.0d + 7.82d -99.0d -7.82d;
  Assert.assertEquals(0d, r, 8.e-15); // Not zero, IEEE 754
  // jexl
  final JexlEngine jexl = new JexlBuilder().create();
  JexlScript script = jexl.createScript("a + b - a - b", "a", "b");
  // using doubles, same as Java
  Number result = (Number) script.execute(null, 99.0d, 7.82d);
  Assert.assertEquals(0d, result.doubleValue(), 8.e-15);
  // using BigdDecimal, more precise, still not zero
  result = (Number) script.execute(null, new BigDecimal(99.0d), new BigDecimal(7.82d));
  Assert.assertEquals(0d, result.doubleValue(), 3.e-32);
}{code}

> Sum of values shows incorrect
> -----------------------------
>
>                 Key: JEXL-407
>                 URL: https://issues.apache.org/jira/browse/JEXL-407
>             Project: Commons JEXL
>          Issue Type: Bug
>    Affects Versions: 3.0
>            Reporter: HAKR
>            Assignee: Henri Biestro
>            Priority: Major
>             Fix For: 3.3
>
>
> We are using JEXL expression in our project which is 3.0 version.
> When adding these values 
> *99.0 + 7.82 -99.0 -7.82*
> It should be zero but the result we are seeing is *-7.105427357601002E-15*



--
This message was sent by Atlassian Jira
(v8.20.10#820010)