W3C home > Mailing lists > Public > public-qt-comments@w3.org > October 2002

RE: XPath 2.0 -- Question about decimal arithmetic

From: Kay, Michael <Michael.Kay@softwareag.com>
Date: Mon, 7 Oct 2002 19:58:09 +0200
Message-ID: <DFF2AC9E3583D511A21F0008C7E621060453DC46@daemsg02.software-ag.de>
To: Jeff Kenton <jkenton@datapower.com>, public-qt-comments@w3.org

We made good progress in the August drafts in specifying the behavior of
integer arithmetic, but we are aware that decimal arithmetic is still
underspecified, and this remains "work in progress".

Note that the "div" operator is at present defined to return a double. This
was done partly for backwards compatibility with XPath 1.0 (10 div 4 returns
2.5, not 2), and partly to side-step the problem of defining the decimal
precision of the result, but I'm not sure it's adequate as a final solution.

I think we also still have work to do in defining exactly how
"backwards-compatible" mode works. We have the option, for example, to say
in the XSLT specification that in backwards-compatible mode numbers like 3.5
should be interpreted as doubles rather than decimals. I hope we can avoid
this, though.

Michael Kay

> 
> 
> I have looked at the XPath 2.0 WD, the XML Schema 
> Recommendation (Part 2: 
> Datatypes), and the XQuery 1.0 and XPath 2.0 Functions and 
> Operators WD.
> 
> I have questions about decimal arithmetic:
> 
> It is clear what the intent is if you have an infinite precision 
> representation of decimals.  However, if you limit yourself to a real 
> implementation (18 decimal digits conforms to the Schema 
> Recommendation), you 
> run into questions when you start doing arithmetic.  For example:
> 
> Addition:  a + b -- if a has 15 digits before the decimal 
> point and b has 15 
> digits after the decimal, which 18 digits do you keep? Do you 
> round the 
> result? Subtraction and multipl;ication have similar questions.
> 
> Division:  this is the biggest problem.  If you divide 1.0 
> div 3.0, is the 
> answer 0.3 or 0.333333333333333333? If the latter, this will 
> propagate through 
> any following operations, including output.
> 
> Since all numbers in existing (pre 2.0) stylesheets that 
> would have been 
> doubles will now default to decimal (was this intended?), 
> this is a serious 
> question.
> 
> Thanks.
> 
> -- 
> --------------------------
> Jeff Kenton
> DataPower Technology, Inc.
> 
> 
> 
Received on Monday, 7 October 2002 13:58:20 UTC

This archive was generated by hypermail 2.4.0 : Friday, 17 January 2020 16:56:43 UTC