Skip to content

Commit 9bb38a4

Browse files
committed
Move the operator mapping tables, etc
1 parent 30a911b commit 9bb38a4

File tree

5 files changed

+306
-128
lines changed

5 files changed

+306
-128
lines changed

specifications/xpath-functions-40/src/function-catalog.xml

Lines changed: 71 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -3062,8 +3062,8 @@ compare($N * $arg2, 0) eq compare($arg1, 0).</eg>
30623062
<p>The <code>$value</code> argument may be of any numeric data type
30633063
(<code>xs:double</code>, <code>xs:float</code>, <code>xs:decimal</code>, or their
30643064
subtypes including <code>xs:integer</code>). Note that if an <code>xs:decimal</code> is
3065-
supplied, it is not automatically promoted to an <code>xs:double</code>, as such
3066-
promotion can involve a loss of precision.</p>
3065+
supplied, it is not automatically converted to an <code>xs:double</code>, as such
3066+
conversion can involve a loss of precision.</p>
30673067
<p>If the supplied value of the <code>$value</code> argument is an empty sequence, the
30683068
function behaves as if the supplied value were the <code>xs:double</code> value
30693069
<code>NaN</code>.</p>
@@ -3928,8 +3928,8 @@ translate(value := '٢٠٢٣', replace := '٠١٢٣٤٥٦٧٨٩', with := '01234
39283928
ref="ieee754-2019"
39293929
/> specification of the <code>pown</code> function applied to a
39303930
64-bit binary floating point value and an integer.</p>
3931-
<p>Otherwise <code>$y</code> is converted to an <code>xs:double</code> by numeric
3932-
promotion, and the result is <code>$x</code> raised to the power of
3931+
<p>Otherwise <code>$y</code> is cast to an <code>xs:double</code>,
3932+
and the result is <code>$x</code> raised to the power of
39333933
<code>$y</code> as defined in the <bibref
39343934
ref="ieee754-2019"
39353935
/> specification of the
@@ -8373,7 +8373,7 @@ xs:dayTimeDuration($arg2) div xs:dayTimeDuration('PT1S')
83738373
<p>The result of <code>seconds($n)</code> is approximately equal to the result of
83748374
the expression <code>xs:dayTimeDuration('PT1S') * $n</code>. The equivalence is only
83758375
approximate, because <code>seconds($n)</code> uses the exact <code>xs:decimal</code>
8376-
value supplied, whereas multiplying a duration by a number first promotes the number
8376+
value supplied, whereas multiplying a duration by a number first converts the number
83778377
to an <code>xs:double</code> value, which may lose precision.</p>
83788378
</fos:notes>
83798379
<fos:examples>
@@ -14428,29 +14428,9 @@ return exists($break)
1442814428
</ulist>
1442914429

1443014430

14431-
<p diff="del" at="A"
14432-
>If the input sequence contains values of different numeric types that differ from each
14433-
other by small amounts, then the eq operator is not transitive, because of rounding
14434-
effects occurring during type promotion. In the situation where the input contains three
14435-
values <code>A</code>, <code>B</code>, and <code>C</code> such that <code>A eq B</code>,
14436-
<code>B eq C</code>, but <code>A ne C</code>, then the number of items in the result
14437-
of the function (as well as the choice of which items are returned) is <termref
14438-
def="implementation-dependent"
14439-
>implementation-dependent</termref>, subject only to the constraints that (a) no two
14440-
items in the result sequence compare equal to each other, and (b) every input item that
14441-
does not appear in the result sequence compares equal to some item that does appear in
14442-
the result sequence.</p>
14443-
14444-
<p diff="del" at="A">For example, this arises when computing:</p>
14445-
14446-
<eg diff="del" at="A"><![CDATA[ distinct-values(
14447-
(xs:float('1.0'),
14448-
xs:decimal('1.0000000000100000000001',
14449-
xs:double('1.00000000001'))]]></eg>
14431+
1445014432

14451-
<p diff="del" at="A"
14452-
>because the values of type <code>xs:float</code> and <code>xs:double</code> both compare
14453-
equal to the value of type <code>xs:decimal</code> but not equal to each other. </p>
14433+
1445414434
</fos:rules>
1445514435
<fos:notes>
1445614436
<p>If <code>$values</code> is the empty sequence, the function returns the empty sequence.</p>
@@ -17152,26 +17132,21 @@ declare function equal-strings(
1715217132
</fos:summary>
1715317133
<fos:rules>
1715417134
<p>If <code>$values</code> is the empty sequence, the empty sequence is returned.</p>
17155-
<p>If <code>$values</code> contains values of type <code>xs:untypedAtomic</code> they are cast
17156-
to <code>xs:double</code>. </p>
17157-
<p>Duration values must either all be <code>xs:yearMonthDuration</code> values or must all
17158-
be <code>xs:dayTimeDuration</code> values. For numeric values, the numeric promotion
17159-
rules defined in <specref
17160-
ref="op.numeric"
17161-
/> are used to promote all values to a single
17162-
common type. After these operations, <code>$values</code> must satisfy the following condition:</p>
17163-
<p>There must be a type <var>T</var> such that:</p>
17135+
<p>Any item in <code>$values</code> that is an instance of <code>xs:untypedAtomic</code>
17136+
is cast to <code>xs:double</code>. </p>
17137+
<p>After this conversion, one of the following conditions must be true:</p>
1716417138
<olist>
17165-
<item><p>every item in <code>$values</code> is an instance of <var>T</var>.</p></item>
17166-
<item><p><var>T</var> is one of <code>xs:double</code>, <code>xs:float</code>,
17167-
<code>xs:decimal</code>, <code>xs:yearMonthDuration</code>, or
17168-
<code>xs:dayTimeDuration</code>.</p></item>
17139+
<item><p>Every item in <code>$values</code> is an instance of <code>xs:yearMonthDuration</code>.</p></item>
17140+
<item><p>Every item in <code>$values</code> is an instance of <code>xs:dayTimeDuration</code>.</p></item>
17141+
<item><p>Every item in <code>$values</code> is an instance of <code>xs:numeric</code>.</p></item>
1716917142
</olist>
17170-
17143+
1717117144

1717217145
<p>The function returns the average of the values as <code>sum($values) div
1717317146
count($values)</code>; but the implementation may use an otherwise equivalent algorithm
17174-
that avoids arithmetic overflow.</p>
17147+
that avoids arithmetic overflow. Note that the <function>fn:sum</function> function
17148+
allows the input sequence to be reordered, which may affect the result in edge cases
17149+
when the sequence contains a mixture of different numeric types.</p>
1717517150

1717617151
</fos:rules>
1717717152
<fos:errors>
@@ -17219,6 +17194,16 @@ declare function equal-strings(
1721917194
code="0006"/>. </p>
1722017195
</fos:example>
1722117196
</fos:examples>
17197+
<fos:changes>
17198+
<fos:change issue="1682" date="2025-01-27">
17199+
<p>In 3.1, given a mixed input sequence such as (1, 3, 4.2e0), the specification
17200+
was unclear whether it was permitted to add the first two integer items using
17201+
integer arithmetic, rather than converting all items to doubles before
17202+
performing any arithmetic. The 4.0 specification is clear that this is
17203+
permitted; but since the items can be reordered before being added, this
17204+
is not required.</p>
17205+
</fos:change>
17206+
</fos:changes>
1722217207
</fos:function>
1722317208

1722417209
<fos:function name="max" prefix="fn">
@@ -17558,34 +17543,36 @@ declare function equal-strings(
1755817543
<p>Returns a value obtained by adding together the values in <code>$values</code>.</p>
1755917544
</fos:summary>
1756017545
<fos:rules>
17561-
<p>Any values of type <code>xs:untypedAtomic</code> in <code>$values</code> are cast to
17546+
<p>The result of the function when a single argument
17547+
is supplied is the result of the expression: <code>fn:sum($arg, 0)</code>.</p>
17548+
<p>Any value of type <code>xs:untypedAtomic</code> in <code>$values</code> is cast to
1756217549
<code>xs:double</code>. The items in the resulting sequence may be reordered in an
1756317550
arbitrary order. The resulting sequence is referred to below as the converted
1756417551
sequence.</p>
17565-
<p diff="chg" at="2023-01-17">If the converted sequence is empty, then the function returns
17552+
<p>If the converted sequence is empty, then the function returns
1756617553
the value of the argument <code>$zero</code>, which defaults to
1756717554
the <code>xs:integer</code> value <code>0</code>.</p>
17568-
<p>If the converted sequence contains the value <code>NaN</code>, <code>NaN</code> is
17569-
returned.</p>
17570-
<p>All items in <code>$values</code> must be numeric or derived from a single base type. In
17571-
addition, the type must support addition. Duration values must either all be
17572-
<code>xs:yearMonthDuration</code> values or must all be
17573-
<code>xs:dayTimeDuration</code> values. For numeric values, the numeric promotion
17574-
rules defined in <specref
17575-
ref="op.numeric"
17576-
/> are used to promote all values to a single
17577-
common type. The sum of a sequence of integers will therefore be an integer, while the
17578-
sum of a numeric sequence that includes at least one <code>xs:double</code> will be an
17579-
<code>xs:double</code>. </p>
17580-
<p>The result of the function is the value of the
17555+
<p>In other cases the items in the converted sequence are added pairwise according
17556+
the rules of the <code>+</code> operator.</p>
17557+
17558+
<p>Specifically, the result of the function is the value of the
1758117559
expression:</p>
1758217560
<eg xml:space="preserve">
1758317561
if (empty($c)) then $zero
1758417562
else if (count($c) eq 1) then $c
1758517563
else head($c) + sum(tail($c))</eg>
1758617564
<p>where <code>$c</code> is the converted sequence.</p>
17587-
<p>The result of the function <phrase diff="chg" at="2023-01-17">when a single argument is supplied</phrase> is the result of the expression:
17588-
<code>fn:sum($arg, 0)</code>.</p>
17565+
17566+
<p>This has the effect that a type error will occur unless one of the following
17567+
conditions is satisfied:</p>
17568+
17569+
<olist>
17570+
<item><p>Every item in <code>$values</code> is an instance of <code>xs:yearMonthDuration</code>.</p></item>
17571+
<item><p>Every item in <code>$values</code> is an instance of <code>xs:dayTimeDuration</code>.</p></item>
17572+
<item><p>Every item in <code>$values</code> is an instance of <code>xs:numeric</code>.</p></item>
17573+
</olist>
17574+
17575+
1758917576

1759017577
</fos:rules>
1759117578
<fos:errors>
@@ -17604,7 +17591,20 @@ else head($c) + sum(tail($c))</eg>
1760417591
the <code>$zero</code> argument is used only when the input sequence is empty, not
1760517592
when a non-empty sequence sums to zero. For example, <code>sum((-1, +1), xs:double('NaN'))</code>
1760617593
returns the <code>xs:integer</code> value <code>0</code>, not <code>NaN</code>.</p>
17607-
<p> If the converted sequence contains exactly one value then that value is returned.</p>
17594+
<p>The sum of a sequence of integers will be an integer, while the
17595+
sum of a numeric sequence that includes at least one <code>xs:double</code> will be an
17596+
<code>xs:double</code>.</p>
17597+
<p>If the converted sequence contains exactly one value then that value is returned.</p>
17598+
<p>If the converted sequence contains the value <code>NaN</code>, <code>NaN</code> is
17599+
returned.</p>
17600+
<p>In edge cases the fact that the input sequence may be reordered makes the result
17601+
slightly unpredictable. For example, if the input contains two <code>xs:decimal</code>
17602+
values and an <code>xs:float</code>, then the decimal values might be added using
17603+
decimal arithmetic, or they might both be converted to <code>xs:float</code>
17604+
(potentially losing precision) before any arithmetic is performed.
17605+
</p>
17606+
17607+
1760817608
</fos:notes>
1760917609
<fos:examples>
1761017610
<fos:variable name="d1" id="v-sum-d1" select="xs:yearMonthDuration(&quot;P20Y&quot;)"/>
@@ -17678,6 +17678,16 @@ else head($c) + sum(tail($c))</eg>
1767817678
/>. </p>
1767917679
</fos:example>
1768017680
</fos:examples>
17681+
<fos:changes>
17682+
<fos:change issue="1682" date="2025-01-27">
17683+
<p>In 3.1, given a mixed input sequence such as (1, 3, 4.2e0), the specification
17684+
was unclear whether it was permitted to add the first two integer items using
17685+
integer arithmetic, rather than converting all items to doubles before
17686+
performing any arithmetic. The 4.0 specification is clear that this is
17687+
permitted; but since the items can be reordered before being added, this
17688+
is not required.</p>
17689+
</fos:change>
17690+
</fos:changes>
1768117691
</fos:function>
1768217692
<!--<fos:function name="to" prefix="op">
1768317693
<fos:signatures>
@@ -18249,7 +18259,7 @@ return tokenize(normalize-space($s), ' ')[. castable as xs:IDREF]</eg>
1824918259
<p>If <code>$source</code> is the empty sequence, the result is an empty sequence.</p>
1825018260
<p>If <code>$source</code> is a relative URI reference, it is resolved relative to the value
1825118261
of the <term>static base URI</term> property from the static context. The resulting absolute URI is
18252-
promoted to an <code>xs:string</code>.</p>
18262+
cast to an <code>xs:string</code>.</p>
1825318263
<p>If the <term>available documents</term> described in <xspecref spec="XP31"
1825418264
ref="eval_context"
1825518265
/> provides a mapping from this string to a document node, the

specifications/xpath-functions-40/src/xpath-functions.xml

Lines changed: 13 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -692,33 +692,17 @@ Michael Sperberg-McQueen (1954–2024).</p>
692692
<div2 id="id-function-calls">
693693
<head>Function calls</head>
694694

695-
<p>Rules for passing parameters to operators are described in the relevant sections
695+
<p>Rules for evaluating the operands of operators are described in the relevant sections
696696
of <bibref ref="xquery-40"/> and <bibref ref="xpath-40"/>. For example, the rules for
697-
passing parameters to arithmetic operators are described in <xspecref spec="XP31" ref="id-arithmetic"/>. Specifically, rules for parameters of
697+
evaluating the operands of arithmetic operators are described in <xspecref spec="XP31" ref="id-arithmetic"/>.
698+
Specifically, rules for parameters of
698699
type <code>xs:untypedAtomic</code> and the empty sequence are specified in this section.</p>
699-
<p>As is customary, the parameter type name indicates that the function or operator
700-
accepts arguments of that type, or types derived from it, in that position. This
701-
is called <emph>subtype substitution</emph> (See <xspecref spec="XP31" ref="id-sequencetype-matching"/>). In addition, numeric type instances and
702-
instances of type <code>xs:anyURI</code> can be promoted to produce an argument
703-
of the required type. (See <xspecref spec="XP31" ref="promotion"/>).</p>
704-
<olist>
705-
<item>
706-
<p><emph>Subtype Substitution</emph>: A derived type may substitute for
707-
its base type. In particular, <code>xs:integer</code> may be used
708-
where <code>xs:decimal</code> is expected.</p>
709-
</item>
710-
<item>
711-
<p><emph>Numeric Type Promotion</emph>: <code>xs:decimal</code> may be
712-
promoted to <code>xs:float</code> or <code>xs:double</code>.
713-
Promotion to <code>xs:double</code> should be done directly, not via
714-
<code>xs:float</code>, to avoid loss of precision.</p>
715-
</item>
716-
<item>
717-
<p><emph>anyURI Type Promotion</emph>: A value of
718-
type <code>xs:anyURI</code> can be promoted to the
719-
type <code>xs:string</code>. </p>
720-
</item>
721-
</olist>
700+
<p>For function calls, the required type of an argument is defined in the function
701+
signature of each function, and the way in which a supplied value is converted to the
702+
required type (or rejected if it cannot be converted) is defined by the
703+
<xtermref spec="XP40" ref="dt-coercion-rules"/>.</p>
704+
705+
722706

723707
<p>Some functions accept a single value or the empty sequence as an argument and
724708
some may return a single value or the empty sequence. This is indicated in the
@@ -1655,10 +1639,8 @@ This differs from <bibref ref="xmlschema-2"/>, which defines
16551639
The exceptions are <code>op:numeric-divide</code>, which returns
16561640
an <code>xs:decimal</code> if called with two <code>xs:integer</code> operands,
16571641
and <code>op:numeric-integer-divide</code> which always returns an <code>xs:integer</code>.</p>
1658-
<p>If the two operands of an arithmetic expression are not of the same type, <emph>subtype substitution</emph>
1659-
and <emph>numeric type promotion</emph> are used to obtain two operands of the
1660-
same type. <xspecref spec="XP31" ref="promotion"/> and <xspecref spec="XP31" ref="mapping"/> describe the semantics of these operations in
1661-
detail. </p>
1642+
<p>If the two operands of an arithmetic expression are not of the same type, they
1643+
may be converted to a common type as described in <xspecref spec="XP40" ref="id-arithmetic-expressions"/>. </p>
16621644
<p>The result type of operations depends on their argument datatypes and is defined
16631645
in the following table:</p>
16641646
<table role="no-code-break data">
@@ -1735,7 +1717,7 @@ This differs from <bibref ref="xmlschema-2"/>, which defines
17351717
</tr>
17361718
</tbody>
17371719
</table>
1738-
<p>These rules define any operation on any pair of arithmetic types. Consider the
1720+
<!--<p>These rules define any operation on any pair of arithmetic types. Consider the
17391721
following example:</p>
17401722
<eg xml:space="preserve"><![CDATA[op:operation(xs:int, xs:double) => op:operation(xs:double, xs:double)]]></eg>
17411723
<p>For this operation, <code>xs:int</code> must be converted to
@@ -1755,7 +1737,7 @@ This differs from <bibref ref="xmlschema-2"/>, which defines
17551737
<code>fenceHeight</code> can be substituted for its base type
17561738
<code>height</code> and <code>height</code> can be substituted for its base type
17571739
<code>xs:integer</code>. </p>
1758-
1740+
-->
17591741
<p>The basic rules for addition, subtraction, and multiplication
17601742
of ordinary numbers are not set out in this specification; they are taken as given. In the case of <code>xs:double</code>
17611743
and <code>xs:float</code> the rules are as defined in <bibref ref="ieee754-2019"/>. The rules for handling

specifications/xquery-40/src/back-matter.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<div1 id="id-type-promotion-and-operator-mapping">
2+
<!--<div1 id="id-type-promotion-and-operator-mapping">
33
<head>Type Promotion and Operator Mapping</head>
44
55
<div2 id="promotion">
@@ -315,7 +315,7 @@ operand must be of type <code>xs:gDay</code>.)</p>
315315
</div2>
316316
317317
318-
</div1>
318+
</div1>-->
319319

320320

321321
<div1 role="xquery" id="id-xq-context-components">

0 commit comments

Comments
 (0)