Issue with double in FuncSum

Bhuvan Mohan <[email protected]> Fri, 28 Nov 2014 16:00:09 +0530
Newsgroups gmane.text.xml.xalan.java.user
Message-ID <[email protected]>
This is a multi-part message in MIME format.
--------------010106010409080105030907
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit

Hi Everyone,

We are using xalan 2.7.0 in our product. I recently faced an issue which 
I found exists in Java Double.
In nodeset summation using double the output is not precise

Ref: 
http://stackoverflow.com/questions/5257166/java-floats-and-doubles-how-to-avoid-that-0-0-0-1-0-1-0-9000001

In class org.apache.xpath.functions.FuncSum#execute, double is being 
used. It all works perfectly fine but when I debugged the source I found 
the problem occurs after summation is done in the line after returning 
from toDouble() in

sum += s.toDouble();

when I did a test on a seperate Java sample I faced a similar result. It 
appears that using BigInteger could help resolve the problem.

Thanks & Regards,
Bhuvan Rawal


--------------010106010409080105030907
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: 7bit

<html>
  <head>

    <meta http-equiv="content-type" content="text/html; charset=utf-8">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    Hi Everyone,<br>
    <br>
    We are using xalan 2.7.0 in our product. I recently faced an issue
    which I found exists in Java Double.<br>
    In nodeset summation using double the output is not precise <br>
    <br>
    Ref:
<a class="moz-txt-link-freetext" href="http://stackoverflow.com/questions/5257166/java-floats-and-doubles-how-to-avoid-that-0-0-0-1-0-1-0-9000001">http://stackoverflow.com/questions/5257166/java-floats-and-doubles-how-to-avoid-that-0-0-0-1-0-1-0-9000001</a><br>
    <br>
    In class org.apache.xpath.functions.FuncSum#execute, double is being
    used. It all works perfectly fine but when I debugged the source I
    found the problem occurs after summation is done in the line after
    returning from toDouble() in <br>
    <br>
    sum += s.toDouble()<span style="color:#cc7832;">;</span><br>
    <br>
    when I did a test on a seperate Java sample I faced a similar
    result. It appears that using BigInteger could help resolve the
    problem.<br>
    <br>
    Thanks &amp; Regards,<br>
    Bhuvan Rawal<br>
    <br>
    <meta http-equiv="content-type" content="text/html; charset=utf-8">
  </body>
</html>

--------------010106010409080105030907--