xsl-list
[Top] [All Lists]

RE: [xsl] negative double, very small absolute value: strange string conversion

2010-03-18 07:37:54
Looks like a bug. Saxon handles double-to-string conversion for common
values itself, but for very small values it delegates the job to Java
(simply to save coding effort for a complex but rare case), and it looks as
if Java and Saxon are both adding the minus sign.

Regards,

Michael Kay
http://www.saxonica.com/
http://twitter.com/michaelhkay 

-----Original Message-----
From: Wolfgang Laun [mailto:wolfgang(_dot_)laun(_at_)gmail(_dot_)com] 
Sent: 18 March 2010 12:24
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] negative double, very small absolute value: 
strange string conversion

Just playing with double arithmetic (xsl is below), I notice 
that the end of the output of this artless stylesheet is this:
...
-9.556619453472961E-299
-9.332636185032189E-302
-9.113902524445497E-305
-8.900295434028806E-308
--8.6916947597938E-311
--8.4879831639E-314
--8.289046E-317
--8.0948E-320
--7.9E-323
-0
-0
...

So why are there double '-' in front of the last few values != -0 ?

$ java -version
java version "1.6.0_0"
OpenJDK Runtime Environment (IcedTea6 1.4.1) 
(6b14-1.4.1-0ubuntu12) OpenJDK Server VM (build 14.0-b08, mixed mode)

java -cp /extra/saxon/saxon9he.jar net.sf.saxon.Transform 
-it:iter -xsl:foo.xsl count=120 start=-1.0

<?xml version="1.0"?><!--foo.xsl-->
<xsl:stylesheet version="2.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
    xmlns:xs="http://www.w3.org/2001/XMLSchema";
    xmlns:wl="wolfgang.laun">

<xsl:param name="start" as="xs:double"/> <xsl:param 
name="count" as="xs:integer"/>

<xsl:function name="wl:div2">
  <xsl:param name="num"  as="xs:double"/>
  <xsl:param name="count" as="xs:integer"/>
  <xsl:if test="$count > 0">
    <xsl:value-of select="$num"/><xsl:text> </xsl:text>
    <xsl:value-of select="wl:div2($num div 1024,$count - 1)"/>
  </xsl:if>
</xsl:function>

<xsl:template name="iter">
  <xsl:value-of select="wl:div2($start,$count)"/> </xsl:template>

</xsl:stylesheet>

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>