XPath2 Type Promotion

Hi,

I've noticed an inconsistency in defining type promotion for XPath 2.

In F&O 6.2 Operators on Numeric Values, we have that xs:decimal can be 
promoted to xs:float, and xs:float can be promoted to xs:double :

-- "If the two operands are not of the same type, subtype substitution and
type promotion may be used to obtain two operands of the same type.  
Appendix B of [XQuery 1.0: An XML Query Language] describes the semantics
of these operations in detail.

1. Subtype substitution: A derived type may substitute for its base type.  
In particular, xs:integer may be used where xs:decimal is expected.

2. Type promotion: xs:decimal may be promoted to xs:float, and xs:float
may be promoted to xs:double." --

However, Appendix B of [XQuery 1.0: An XML Query Language] seems to allow
for xs:decimal to be promoted directly to xs:double, without going trough
xs:float :

-- "The following type promotions are permitted:

1. A value of type xs:float (or any type derived by restriction from 
xs:float) can be promoted to the type xs:double. The result is the 
xs:double value that is the same as the original value. This kind of 
promotion may cause loss of precision.

2. A value of type xs:decimal (or any type derived by restriction from 
xs:decimal) can be promoted to either of the types xs:float or xs:double. 
The result is the value of the target type that is closest to the original 
value." --

Note that also in F&O 6.2 :

-- "For this operation, xs:int must be converted to xs:double. This can be 
done, since by the rules above: xs:int can be substituted for xs:integer, 
xs:integer can be promoted to xs:decimal, xs:decimal can be promoted to 
xs:float, and xs:float can be promoted to xs:double. As far as possible, 
the promotions should be done in a single step. Specifically, when a 
decimal is promoted to a double, it must not be converted to a float and 
then to double, as this risks loss of precision." --

[As a side note, shouldn't that say "xs:integer can be substituted for
xs:decimal" instead of "xs:integer can be promoted to xs:decimal"?]

So, which one is correct?  When converting an xs:decimal to an xs:double, 
should we go trough xs:float?

Thanks,
Caroline

-- 
Caroline Rioux, Software Engineer           +44-1865-203192
DecisionSoft Limited                        http://www.decisionsoft.com
XML Development and Services

Received on Monday, 16 June 2003 07:12:55 UTC