Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

## Re: [saxon] Casting of untyped values and type promotion

 Re: [saxon] Casting of untyped values and type promotion From: Ludovic Kuty - 2014-02-16 20:23:10 ```I think I misunderstood the automatic type conversion that happens with the casting of untyped values to the right type to perform the operation. I thought that the xs:untypedAtomic value would be cast to xs:integer to perform the addition but in fact it is cast to xs:double (the rules you mentioned) and I guess the xs:integer is type promoted to xs:double and then we have an addition between xs:double values. Thanks for clarifying the matter. On 16 Feb 2014, at 19:48, Michael Kay wrote: > > On 16 Feb 2014, at 12:04, Ludovic Kuty wrote: > >> Dear ML users, >> >> I have tried a little example with Saxon-EE 9.5.1.4J and thought that the untyped value would be converted to xs:integer instead of xs:double. > > I'm not sure why you expected that. The rules for arithmetic operations in XPath 2.0 are: > > • Atomization is applied to the operand. The result of this operation is called the atomized operand. > • If the atomized operand is an empty sequence, the result of the arithmetic expression is an empty sequence, and the implementation need not evaluate the other operand or apply the operator. However, an implementation may choose to evaluate the other operand in order to determine whether it raises an error. > • If the atomized operand is a sequence of length greater than one, a type error is raised [err:XPTY0004]. > • If the atomized operand is of type xs:untypedAtomic, it is cast to xs:double. If the cast fails, a dynamic error is raised. [err:FORG0001] > > The fourth rule kicks in here, and converts the untyped operand to double. You're then adding integer plus double, which returns a double. > > Michael Kay > Saxonica > ------------------------------------------------------------------------------ > Android apps run on BlackBerry 10 > Introducing the new BlackBerry 10.2.1 Runtime for Android apps. > Now with support for Jelly Bean, Bluetooth, Mapview and more. > Get your Android app in front of a whole new audience. Start now. > http://pubads.g.doubleclick.net/gampad/clk?id=124407151&iu=/4140/ostg.clktrk > _______________________________________________ > saxon-help mailing list archived at http://saxon.markmail.org/ > saxon-help@... > https://lists.sourceforge.net/lists/listinfo/saxon-help ```

 [saxon] Casting of untyped values and type promotion From: Ludovic Kuty - 2014-02-16 12:24:33 ```Dear ML users, I have tried a little example with Saxon-EE 9.5.1.4J and thought that the untyped value would be converted to xs:integer instead of xs:double. I declared the element untypedValue with mixed complex type to be able to get an xs:untypedAtomic even with schema validation turned on. I don't know if there are other ways to accomplish that. The examples are below. Could you explain what is going on ? This specific test is part of a more general test sequence on automatic type conversions hence the different elements in my document with different types. You can see below in the XQUERY TEST section that the query execution plan mentions a conversion to xs:double with and that in the wrapped output we have a xs:double type with I posted here on saxon-help because even if it could be a general XPath 2.0 question, the behavior I observe is with Saxon. I hope it doesn't bother you. TIA Ludovic Kuty XML document ------------ 100 100.0 100 XSD --- ; XQUERY TEST ----------- java net.sf.saxon.Query -val:strict -sa -explain -wrap -qs:"50 + /root/untypedValue" -s:http://xml.khi.be/xpath2/types/automatic-type-conversions.xml 150mac:slides ludo\$ ```
 Re: [saxon] Casting of untyped values and type promotion From: Michael Kay - 2014-02-16 18:48:28 ```On 16 Feb 2014, at 12:04, Ludovic Kuty wrote: > Dear ML users, > > I have tried a little example with Saxon-EE 9.5.1.4J and thought that the untyped value would be converted to xs:integer instead of xs:double. I'm not sure why you expected that. The rules for arithmetic operations in XPath 2.0 are: • Atomization is applied to the operand. The result of this operation is called the atomized operand. • If the atomized operand is an empty sequence, the result of the arithmetic expression is an empty sequence, and the implementation need not evaluate the other operand or apply the operator. However, an implementation may choose to evaluate the other operand in order to determine whether it raises an error. • If the atomized operand is a sequence of length greater than one, a type error is raised [err:XPTY0004]. • If the atomized operand is of type xs:untypedAtomic, it is cast to xs:double. If the cast fails, a dynamic error is raised. [err:FORG0001] The fourth rule kicks in here, and converts the untyped operand to double. You're then adding integer plus double, which returns a double. Michael Kay Saxonica ```
 Re: [saxon] Casting of untyped values and type promotion From: Ludovic Kuty - 2014-02-16 20:23:10 ```I think I misunderstood the automatic type conversion that happens with the casting of untyped values to the right type to perform the operation. I thought that the xs:untypedAtomic value would be cast to xs:integer to perform the addition but in fact it is cast to xs:double (the rules you mentioned) and I guess the xs:integer is type promoted to xs:double and then we have an addition between xs:double values. Thanks for clarifying the matter. On 16 Feb 2014, at 19:48, Michael Kay wrote: > > On 16 Feb 2014, at 12:04, Ludovic Kuty wrote: > >> Dear ML users, >> >> I have tried a little example with Saxon-EE 9.5.1.4J and thought that the untyped value would be converted to xs:integer instead of xs:double. > > I'm not sure why you expected that. The rules for arithmetic operations in XPath 2.0 are: > > • Atomization is applied to the operand. The result of this operation is called the atomized operand. > • If the atomized operand is an empty sequence, the result of the arithmetic expression is an empty sequence, and the implementation need not evaluate the other operand or apply the operator. However, an implementation may choose to evaluate the other operand in order to determine whether it raises an error. > • If the atomized operand is a sequence of length greater than one, a type error is raised [err:XPTY0004]. > • If the atomized operand is of type xs:untypedAtomic, it is cast to xs:double. If the cast fails, a dynamic error is raised. [err:FORG0001] > > The fourth rule kicks in here, and converts the untyped operand to double. You're then adding integer plus double, which returns a double. > > Michael Kay > Saxonica > ------------------------------------------------------------------------------ > Android apps run on BlackBerry 10 > Introducing the new BlackBerry 10.2.1 Runtime for Android apps. > Now with support for Jelly Bean, Bluetooth, Mapview and more. > Get your Android app in front of a whole new audience. Start now. > http://pubads.g.doubleclick.net/gampad/clk?id=124407151&iu=/4140/ostg.clktrk > _______________________________________________ > saxon-help mailing list archived at http://saxon.markmail.org/ > saxon-help@... > https://lists.sourceforge.net/lists/listinfo/saxon-help ```