xsl-list
[Top] [All Lists]

RE: [xsl] Implicit casting from double to float

2009-01-07 17:48:25
My first thoughts are that XSLT should raise an error on this, and if Saxon
isn't raising an error then it's a bug. But I need to investigate a bit more
deeply.

Yes, it's totally ridiculous to allow decimal->float promotion but not
double->float, but that's what the spec says.

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

-----Original Message-----
From: Mukul Gandhi [mailto:gandhi(_dot_)mukul(_at_)gmail(_dot_)com] 
Sent: 07 January 2009 07:02
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] Implicit casting from double to float

Hi all,
   When I ran the following XSLT 2.0 code, with Saxon 9.x

<xsl:variable name="num1" select="xs:double('1e4')" 
as="xs:double" /> <xsl:variable name="num2" select="$num1" 
as="xs:float" /> <xsl:value-of select="$num2" />

I get the output,

10000

The XSLT 2.0 processor has no problem doing this operation. 
No warning is produced either.

But a similar operation in Java is a serious compile time error,

Please consider this Java fragment,

float num = (double)1e4;
System.out.println(num);

This Java fragment doesn't compile, and following error is generated,

test.java:3: possible loss of precision
found   : double
required: float

float num = (double)1e4;
                 ^

Could somebody please explain this behavior with the XSLT 2.0 system.


--
Regards,
Mukul Gandhi

--~------------------------------------------------------------------
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>
--~--