Re: [xslt] number() floated?
- From: Vincent Lefevre <vincent+gnome vinc17 org>
- To: xslt gnome org
- Subject: Re: [xslt] number() floated?
- Date: Tue, 3 Jan 2012 23:00:16 +0100
On 2012-01-03 20:53:40 +0000, Laurence Rowe wrote:
> On 16 December 2011 17:06, Konrad Korzeniowski <konrad pandur net> wrote:
> > I got following simple xslt file:
> >
> > <?xml version="1.0" encoding="UTF-8"?>
> >
> > <xsl:stylesheet version="1.0"
> > xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>
> > <xsl:template match="/">
> > <xsl:value-of select="number('8.95')"/>
> > </xsl:template>
> > </xsl:stylesheet>
> >
> >
> > running xsltproc with this xsl against any xml gives:
> > 8.949999999999999
> >
> > Is this expected? Shouldn't this be 8.85?
> >
> > Thanks for any explanation.
>
> Not all decimals may be exactly represented in binary floating point.
> See: http://en.wikipedia.org/wiki/Floating_point#Representable_numbers.2C_conversion_and_rounding
Except that this seems to be a bug here:
$ /usr/bin/printf "%a\n" 8.95
0x8.f33333333333333p+0
This is the binary value represented internally.
$ /usr/bin/printf "%a\n" 8.949999999999999
0x8.f33333333332eb2p+0
This is quite different!
Now, if the XSLT spec says that the value should be rounded *downward*
to decimal with a fixed number of decimal digits, this would be correct.
But this would be a quite surprising choice.
--
Vincent Lefèvre <vincent vinc17 net> - Web: <http://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <http://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / Arénaire project (LIP, ENS-Lyon)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]