GNOME Bugzilla – Bug 704528
Scientific notation and leading whitespaces
Last modified: 2013-07-22 05:25:31 UTC
$ cat testLarge.xml <?xml version="1.0" encoding="utf-8"?> <Refrigerator> <Apples>5000000000</Apples> <Bananas>10000000000000000</Bananas> </Refrigerator> $ cat testSmall.xml <?xml version="1.0" encoding="utf-8"?> <Refrigerator> <Apples>5</Apples> <Bananas>10</Bananas> </Refrigerator> $ cat collect.xslt <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="xml" indent="yes"/> <xsl:template match="Refrigerator"> <xsl:value-of select="Apples * Bananas" /> </xsl:template> </xsl:stylesheet> $ xsltproc collect.xslt testLarge.xml <?xml version="1.0"?> 5e+25 $ xsltproc collect.xslt testSmall.xml <?xml version="1.0"?> 50 The problem is that when I use testLarge.xml the resulting value contains a leading whitespace, i.e. it is something like " 5e+25". Instead, with small numbers I obtain "50" without leading whitespace. The bug is not regarding the "extension" for the scientific notation but instead regarding the leading whitespace which is not consistent. $ xsltproc --version Using libxml 20900, libxslt 10127 and libexslt 816 xsltproc was compiled against libxml 20900, libxslt 10127 and libexslt 816 libxslt 10127 was compiled against libxml 20900 libexslt 816 was compiled against libxml 20900
$ xmllint empty.xml --xpath 'concat("val=", 2e12)' val= 2e+12 Probably a bug in xmlXPathFormatNumber.
Yes I don't know why snprintf adds it: 2866 integer_place = DBL_DIG + EXPONENT_DIGITS + 1; (gdb) 2867 fraction_place = DBL_DIG - 1; (gdb) 2868 size = snprintf(work, sizeof(work),"%*.*e", (gdb) 2870 while ((size > 0) && (work[size] != 'e')) size--; (gdb) p size $1 = 21 (gdb) p work $2 = " 2.", '0' <repeats 14 times>, "e+12\000\000\000\000\000\000\242" (gdb) p integer_place $3 = 21 (gdb) p fraction_place $4 = 14 (gdb) p absolute_value $5 = 2000000000000 weird, simplest is to remove the leading spaces when they appear, crude but effective little patch applied and pushed: https://git.gnome.org/browse/libxml2/commit/?id=b9e4d5b6395f9aa0a34cb74e9a3672a20d37b943 thanks ! Daniel