On 3 January 2012 22:33, Vincent Lefevre <[email protected]> wrote: > On 2012-01-03 23:00:16 +0100, Vincent Lefevre wrote: >> On 2012-01-03 20:53:40 +0000, Laurence Rowe wrote: >> > On 16 December 2011 17:06, Konrad Korzeniowski <[email protected]> wrote: > [...] >> > > <xsl:value-of select="number('8.95')"/> > [...] >> >> Except that this seems to be a bug here: > > After looking at the spec, I confirm this is a bug. The XPath spec > says for number(): "a string that consists of optional whitespace > followed by an optional minus sign followed by a Number followed > by whitespace is converted to the IEEE 754 number that is nearest > (according to the IEEE 754 round-to-nearest rule) to the mathematical > value represented by the string" > > The nearest value X is the following one (represented exactly in > radix 16, thanks to %a): > >> $ /usr/bin/printf "%a\n" 8.95 >> 0x8.f33333333333333p+0 > > But actually (see below) the internal representation doesn't matter > here. > > Concerning xsl:value-of, the XSLT spec says that for a number, the > XPath string() fucntion is used, and the XPath spec says for the > above value: "otherwise, the number is represented in decimal form > as a Number including [...]; beyond the one required digit after > the decimal point there must be as many, but only as many, more > digits as are needed to uniquely distinguish the number from all > other IEEE 754 numeric values." (FYI, that's the IEEE 754 rule for > conversions.) > > As a consequence, the output value should be "8.95" (like the input) > because 8.95 rounds to X and has less than 17 digits.
You're right, xpath.c just prints DBL_DIG digits (a constant from float.h). However, doing this properly is difficult, see: http://bugs.python.org/issue1580. Laurence _______________________________________________ xslt mailing list, project page http://xmlsoft.org/XSLT/ [email protected] http://mail.gnome.org/mailman/listinfo/xslt
