It's not a bug: v1.0 is doing double-precision floating point arithmetic, while v2.0 is doing decimal arithmetic. Double-precision arithmetic converts the values 70 and 0.01 to the nearest doubles, and then multiplies them. The decimal value 0.01 cannot be represented exactly by a double, so a rounding error occurs.
 
The simplest remedy for this is to display the result to a suitable number of decimal places by using format-number().
 
Michael Kay
http://www.saxonica.com/


From: Ryan Puddephatt [mailto:rpuddephatt@latentzero.com]
Sent: 23 March 2009 17:05
To: Mailing list for the SAXON XSLT and XQuery processor
Subject: [saxon] XSL 1.0 Math Bug

Hi,

                I’ve been struggling with a problem I found when using the latest Saxon-B with an XSLT 1.0 stylesheet (pasted below).

 

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

  <xsl:template match="in">

    <xsl:copy>

      <xsl:value-of select="70 * 0.01" />

    </xsl:copy>

  </xsl:template>

</xsl:stylesheet>

 

I found that the result of this was unexpectedly

 

<in>0.7000000000000001</in>

 

But with version as 2.0 I get the expected

 

<in>0.7</in>

 

Any ideas why there is a difference, is there a quick work around? I’d prefer not to change the XSL if possible. Also will there be a bug fix for this?

 

Thanks

 

Ryan

 

-----------------------------------------------

Ryan Puddephatt

Connectivity Developer

Fidessa LatentZero

1 Old Jewry

London EC2R 8DN

Office: +44 (0) 20 7105 1000

Direct: +44 (0) 20 7105 1821

Blackberry: +44 (0) 79 8539 2458

Fax: +44 (0) 20 7105 1818

Email: rpuddephatt@latentzero.com

Web: http://www.latentzero.com

 


_______________________________________________________________________
The information transmitted is intended only for the person or entity to which it is addressed and may contain confidential and/or privileged material. Any review, retransmission, dissemination or other use of, or taking of any action in reliance upon, this information by persons or entities other than the intended recipient is prohibited. If you received this in error, please contact the sender and delete the material from any computer.

_____________________________________________________________________
This e-mail has been scanned for viruses by Verizon Business Internet Managed Scanning Services - powered by MessageLabs. For further information visit http://www.mci.com