*From*: Bjorn Reese <breese mail1 stofanet dk>*To*: xml gnome org*Subject*: Re: [xml] XPath numbers and exponential notation*Date*: Tue, 24 Apr 2001 07:04:34 +0000

Thomas Broyer wrote:

since April 21, libxml supports exponential notation of XPath numbers both at parsing and writing (conversion to string). In the xmlXPathStringEvalNumber comment was added a [30a] production, where does it come from? I can't find anything on W3C's site.

Out of nowhere. The production was only added to document how the actual code behaves.

Since then, illegal expressions such as "75.2E-12" became legal in libxml view and some expressions don't produce expected result anymore (the above example is converted to the string "7.52e-11" whereas "0.0000000000752" is expected) Any explaination about the why and the goal of such a transformation?

Very simple. XPath uses ANSI/IEEE Std 754 (1985) for floating point numbers. This standard uses a fixed numbers of digits (bits, actually) to represent numbers, which means that it cannot accurately represent, say, the number pi as it would require an infinite number of digits. It also means that big numbers cannot be represented accurately with the regular 9.9 floating point notation. If we were going to try this, the least significant digit would be garbage. It such cases it is customary to use scientific notation instead, and this is what we did. It is not 100% standard compliant, but the standard would generate garbage, so we chose the lesser of the two evils. I believe that this is a sound choice, given that W3C has realized the problem, and added a requirement for scientific notation in XPath 2.0. Anybody who disagrees are welcome to contribute a patch.

I came to that while translating XML in a Nutshell's XPath Refence chapter where it is stated that exponential notation is allowed. That chocked me and I used testXPath to check, which achieved confusing my mind. I decided to check the XPath spec and errata and didn't find anything related.

Scientific notation is not allowed in XPath 1.0, but it has been added to the requirements for XPath 2.0.

**Follow-Ups**:**Re: [xml] XPath numbers and exponential notation***From:*Daniel Veillard

**References**:**[xml] XPath numbers and exponential notation***From:*Thomas Broyer

[Date Prev][Date Next] [Thread Prev][Thread Next] [Thread Index] [Date Index] [Author Index]