[xquery-talk] operations on derived numeric type

Michael Kay mike at saxonica.com
Fri Aug 30 06:24:45 PDT 2013

On 30 Aug 2013, at 12:11, Benito van der Zander wrote:

> Hi,
> is it true that *all* operations on types derived from the numeric types return a value of one of the four base numeric types?
> For example xs:byte(1) + xs:byte(1) or abs(xs:byte(1)).

Certainly for all arithmetic operations, yes. (Obviously not for operations like (a gt b).
> What's the point of even having these sub types then?

In my view there's very little point in having these subtypes, but they are there in XSD so XQuery supports them.
> And why does the XQuery 1 test suite have two different output files for the "abs(xs:byte(<e>0</e>)) instance of xs:byte" case (K2-ABSFunc-46)?
> One is "true", the other is "false"

The specification says that abs() applied to an xs:byte value returns an xs:integer. An implementation that returns an xs:byte conforms to that rule, because every xs:byte is an xs:integer. So some implementations might return an xs:integer that is an xs:byte, others might return an xs:integer that is not an xs:byte. Note that there is one case where the result cannot be an xs:byte, namely where the input is xs:byte(-128).

(I suspect that Saxon returns the original value unchanged, including type annotation, if it is positive, and returns a value with type annotation xs:integer if it is negative. That's a permitted and in my view reasonable implementation).

Michael Kay

More information about the talk mailing list