diff --git a/specifications/xpath-functions-40/src/function-catalog.xml b/specifications/xpath-functions-40/src/function-catalog.xml index 171236f78..12a99114f 100644 --- a/specifications/xpath-functions-40/src/function-catalog.xml +++ b/specifications/xpath-functions-40/src/function-catalog.xml @@ -3062,8 +3062,8 @@ compare($N * $arg2, 0) eq compare($arg1, 0).

The $value argument may be of any numeric data type (xs:double, xs:float, xs:decimal, or their subtypes including xs:integer). Note that if an xs:decimal is - supplied, it is not automatically promoted to an xs:double, as such - promotion can involve a loss of precision.

+ supplied, it is not automatically converted to an xs:double, as such + conversion can involve a loss of precision.

If the supplied value of the $value argument is an empty sequence, the function behaves as if the supplied value were the xs:double value NaN.

@@ -3928,8 +3928,8 @@ translate(value := '٢٠٢٣', replace := '٠١٢٣٤٥٦٧٨٩', with := '01234 ref="ieee754-2019" /> specification of the pown function applied to a 64-bit binary floating point value and an integer.

-

Otherwise $y is converted to an xs:double by numeric - promotion, and the result is $x raised to the power of +

Otherwise $y is cast to an xs:double, + and the result is $x raised to the power of $y as defined in the specification of the @@ -8373,7 +8373,7 @@ xs:dayTimeDuration($arg2) div xs:dayTimeDuration('PT1S')

The result of seconds($n) is approximately equal to the result of the expression xs:dayTimeDuration('PT1S') * $n. The equivalence is only approximate, because seconds($n) uses the exact xs:decimal - value supplied, whereas multiplying a duration by a number first promotes the number + value supplied, whereas multiplying a duration by a number first converts the number to an xs:double value, which may lose precision.

@@ -14428,29 +14428,9 @@ return exists($break) -

If the input sequence contains values of different numeric types that differ from each - other by small amounts, then the eq operator is not transitive, because of rounding - effects occurring during type promotion. In the situation where the input contains three - values A, B, and C such that A eq B, - B eq C, but A ne C, then the number of items in the result - of the function (as well as the choice of which items are returned) is implementation-dependent, subject only to the constraints that (a) no two - items in the result sequence compare equal to each other, and (b) every input item that - does not appear in the result sequence compares equal to some item that does appear in - the result sequence.

- -

For example, this arises when computing:

- - + -

because the values of type xs:float and xs:double both compare - equal to the value of type xs:decimal but not equal to each other.

+

If $values is the empty sequence, the function returns the empty sequence.

@@ -17152,26 +17132,21 @@ declare function equal-strings(

If $values is the empty sequence, the empty sequence is returned.

-

If $values contains values of type xs:untypedAtomic they are cast - to xs:double.

-

Duration values must either all be xs:yearMonthDuration values or must all - be xs:dayTimeDuration values. For numeric values, the numeric promotion - rules defined in are used to promote all values to a single - common type. After these operations, $values must satisfy the following condition:

-

There must be a type T such that:

+

Any item in $values that is an instance of xs:untypedAtomic + is cast to xs:double.

+

After this conversion, one of the following conditions must be true:

-

every item in $values is an instance of T.

-

T is one of xs:double, xs:float, - xs:decimal, xs:yearMonthDuration, or - xs:dayTimeDuration.

+

Every item in $values is an instance of xs:yearMonthDuration.

+

Every item in $values is an instance of xs:dayTimeDuration.

+

Every item in $values is an instance of xs:numeric.

- +

The function returns the average of the values as sum($values) div count($values); but the implementation may use an otherwise equivalent algorithm - that avoids arithmetic overflow.

+ that avoids arithmetic overflow. Note that the fn:sum function + allows the input sequence to be reordered, which may affect the result in edge cases + when the sequence contains a mixture of different numeric types.

@@ -17219,6 +17194,16 @@ declare function equal-strings( code="0006"/>.

+ + +

In 3.1, given a mixed input sequence such as (1, 3, 4.2e0), the specification + was unclear whether it was permitted to add the first two integer items using + integer arithmetic, rather than converting all items to doubles before + performing any arithmetic. The 4.0 specification is clear that this is + permitted; but since the items can be reordered before being added, this + is not required.

+
+
@@ -17558,34 +17543,36 @@ declare function equal-strings(

Returns a value obtained by adding together the values in $values.

-

Any values of type xs:untypedAtomic in $values are cast to +

The result of the function when a single argument + is supplied is the result of the expression: fn:sum($arg, 0).

+

Any value of type xs:untypedAtomic in $values is cast to xs:double. The items in the resulting sequence may be reordered in an arbitrary order. The resulting sequence is referred to below as the converted sequence.

-

If the converted sequence is empty, then the function returns +

If the converted sequence is empty, then the function returns the value of the argument $zero, which defaults to the xs:integer value 0.

-

If the converted sequence contains the value NaN, NaN is - returned.

-

All items in $values must be numeric or derived from a single base type. In - addition, the type must support addition. Duration values must either all be - xs:yearMonthDuration values or must all be - xs:dayTimeDuration values. For numeric values, the numeric promotion - rules defined in are used to promote all values to a single - common type. The sum of a sequence of integers will therefore be an integer, while the - sum of a numeric sequence that includes at least one xs:double will be an - xs:double.

-

The result of the function is the value of the +

In other cases the items in the converted sequence are added pairwise according + the rules of the + operator.

+ +

Specifically, the result of the function is the value of the expression:

if (empty($c)) then $zero else if (count($c) eq 1) then $c else head($c) + sum(tail($c))

where $c is the converted sequence.

-

The result of the function when a single argument is supplied is the result of the expression: - fn:sum($arg, 0).

+ +

This has the effect that a type error will occur unless one of the following + conditions is satisfied:

+ + +

Every item in $values is an instance of xs:yearMonthDuration.

+

Every item in $values is an instance of xs:dayTimeDuration.

+

Every item in $values is an instance of xs:numeric.

+
+ +
@@ -17604,7 +17591,20 @@ else head($c) + sum(tail($c)) the $zero argument is used only when the input sequence is empty, not when a non-empty sequence sums to zero. For example, sum((-1, +1), xs:double('NaN')) returns the xs:integer value 0, not NaN.

-

If the converted sequence contains exactly one value then that value is returned.

+

The sum of a sequence of integers will be an integer, while the + sum of a numeric sequence that includes at least one xs:double will be an + xs:double.

+

If the converted sequence contains exactly one value then that value is returned.

+

If the converted sequence contains the value NaN, NaN is + returned.

+

In edge cases the fact that the input sequence may be reordered makes the result + slightly unpredictable. For example, if the input contains two xs:decimal + values and an xs:float, then the decimal values might be added using + decimal arithmetic, or they might both be converted to xs:float + (potentially losing precision) before any arithmetic is performed. +

+ + @@ -17678,6 +17678,16 @@ else head($c) + sum(tail($c)) />.

+ + +

In 3.1, given a mixed input sequence such as (1, 3, 4.2e0), the specification + was unclear whether it was permitted to add the first two integer items using + integer arithmetic, rather than converting all items to doubles before + performing any arithmetic. The 4.0 specification is clear that this is + permitted; but since the items can be reordered before being added, this + is not required.

+
+

The basic rules for addition, subtraction, and multiplication of ordinary numbers are not set out in this specification; they are taken as given. In the case of xs:double and xs:float the rules are as defined in . The rules for handling diff --git a/specifications/xquery-40/src/back-matter.xml b/specifications/xquery-40/src/back-matter.xml index c895cbbbb..e7cd87618 100644 --- a/specifications/xquery-40/src/back-matter.xml +++ b/specifications/xquery-40/src/back-matter.xml @@ -1,5 +1,5 @@ - + diff --git a/specifications/xquery-40/src/expressions.xml b/specifications/xquery-40/src/expressions.xml index 281f35c72..6ff9f6e49 100644 --- a/specifications/xquery-40/src/expressions.xml +++ b/specifications/xquery-40/src/expressions.xml @@ -4207,6 +4207,13 @@ types (such as xs:integer) and function types enumeration types cannot be used as the target for schema validation.

+

The type xs:numeric + is defined as a union type with member types xs:double, + xs:float, and xs:decimal. An item that + is an instance of any of these types is referred to as a numeric value, + and a type that is a subtype of xs:numeric is referred to + as a numeric type.

+ Namespace-sensitive Types @@ -12891,6 +12898,7 @@ multiplication, division, and modulus, in their usual binary and unary forms.

+

A subtraction operator must be preceded by whitespace if it could otherwise be interpreted as part of the previous token. For @@ -12916,7 +12924,9 @@ is equivalent to Similarly, the operands of a MultiplicativeExpr are grouped from left to right.

-

The first step in evaluating an arithmetic expression is to evaluate its operands. The order in which the operands are evaluated is The first step in evaluating an arithmetic expression is to evaluate its operand (for + a unary operator) or operands (for a binary operator). + The order in which the operands are evaluated is implementation-dependent.

If XPath 1.0 compatibility mode is true, each operand is evaluated by applying the following steps, in order:

@@ -12990,23 +13000,130 @@ error is raised. -

After evaluation of the operands, if the types of the operands are a valid combination -for the given arithmetic operator, the operator is applied to the operands, -resulting in an atomic item or a dynamic error (for example, an error -might result from dividing by zero). The combinations of atomic types -that are accepted by the various arithmetic operators, and their -respective result types, are listed in -together with the operator functions -that define the semantics of the operator for each -type combination, including the dynamic errors that can be raised by the operator. The definitions of the operator functions are found in If, after this process, both operands of a binary arithmetic operator + are instances of xs:numeric + but have different primitive types, they are coerced to a common type by applying + the following rules:

+ + +

If either of the items is of type xs:double, then + both the values are cast to type xs:double.

+

Otherwise, if either of the items is of type xs:float, then + both the values are cast to type xs:float.

+

Otherwise, no casting takes place: the values remain as xs:decimal.

+
+ +

After this preparation, the arithmetic expression is evaluated by applying the appropriate + function listed in the table below. The definitions of these functions are found in .

-

If the types of the operands, after evaluation, are not a valid combination for the given operator, according to the rules in , a type error is raised .

+ + + + + + + + + + + + + + + + + + + +
Unary Arithmetic Operators
ExpressionType of AFunctionResult type
+ Axs:numericop:numeric-unary-plus(A)xs:numeric
- Axs:numericop:numeric-unary-minus(A)xs:numeric
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Binary Arithmetic Operators
ExpressionType of AType of BFunctionResult type
A + Bxs:numericxs:numericop:numeric-add(A, B)xs:numeric
A + Bxs:datexs:yearMonthDurationop:add-yearMonthDuration-to-date(A, B)xs:date
A + Bxs:yearMonthDurationxs:dateop:add-yearMonthDuration-to-date(B, A)xs:date
A + Bxs:datexs:dayTimeDurationop:add-dayTimeDuration-to-date(A, B)xs:date
A + Bxs:dayTimeDurationxs:dateop:add-dayTimeDuration-to-date(B, A)xs:date
A + Bxs:timexs:dayTimeDurationop:add-dayTimeDuration-to-time(A, B)xs:time
A + Bxs:dayTimeDurationxs:timeop:add-dayTimeDuration-to-time(B, A)xs:time
A + Bxs:dateTimexs:yearMonthDurationop:add-yearMonthDuration-to-dateTime(A, B)xs:dateTime
A + Bxs:yearMonthDurationxs:dateTimeop:add-yearMonthDuration-to-dateTime(B, A)xs:dateTime
A + Bxs:dateTimexs:dayTimeDurationop:add-dayTimeDuration-to-dateTime(A, B)xs:dateTime
A + Bxs:dayTimeDurationxs:dateTimeop:add-dayTimeDuration-to-dateTime(B, A)xs:dateTime
A + Bxs:yearMonthDurationxs:yearMonthDurationop:add-yearMonthDurations(A, B)xs:yearMonthDuration
A + Bxs:dayTimeDurationxs:dayTimeDurationop:add-dayTimeDurations(A, B)xs:dayTimeDuration
A - Bxs:numericxs:numericop:numeric-subtract(A, B)xs:numeric
A - Bxs:datexs:dateop:subtract-dates(A, B)xs:dayTimeDuration
A - Bxs:datexs:yearMonthDurationop:subtract-yearMonthDuration-from-date(A, B) +xs:date
A - Bxs:datexs:dayTimeDurationop:subtract-dayTimeDuration-from-date(A, B)xs:date
A - Bxs:timexs:timeop:subtract-times(A, B)xs:dayTimeDuration
A - Bxs:timexs:dayTimeDurationop:subtract-dayTimeDuration-from-time(A, B)xs:time
A - Bxs:dateTimexs:dateTimeop:subtract-dateTimes(A, B)xs:dayTimeDuration
A - Bxs:dateTimexs:yearMonthDurationop:subtract-yearMonthDuration-from-dateTime(A, B)xs:dateTime
A - Bxs:dateTimexs:dayTimeDurationop:subtract-dayTimeDuration-from-dateTime(A, B)xs:dateTime
A - Bxs:yearMonthDurationxs:yearMonthDurationop:subtract-yearMonthDurations(A, B)xs:yearMonthDuration
A - Bxs:dayTimeDurationxs:dayTimeDurationop:subtract-dayTimeDurations(A, B)xs:dayTimeDuration
A * Bxs:numericxs:numericop:numeric-multiply(A, B)xs:numeric
A * Bxs:yearMonthDurationxs:numericop:multiply-yearMonthDuration(A, B)xs:yearMonthDuration
A * Bxs:numericxs:yearMonthDurationop:multiply-yearMonthDuration(B, A)xs:yearMonthDuration
A * Bxs:dayTimeDurationxs:numericop:multiply-dayTimeDuration(A, B)xs:dayTimeDuration
A * Bxs:numericxs:dayTimeDurationop:multiply-dayTimeDuration(B, A)xs:dayTimeDuration
A idiv Bxs:numericxs:numericop:numeric-integer-divide(A, B)xs:integer
A div Bxs:numericxs:numericop:numeric-divide(A, B)numeric; but xs:decimal if both operands are xs:integer
A div Bxs:yearMonthDurationxs:numericop:divide-yearMonthDuration(A, B)xs:yearMonthDuration
A div Bxs:dayTimeDurationxs:numericop:divide-dayTimeDuration(A, B)xs:dayTimeDuration
A div Bxs:yearMonthDurationxs:yearMonthDurationop:divide-yearMonthDuration-by-yearMonthDuration(A, B)xs:decimal
A div Bxs:dayTimeDurationxs:dayTimeDurationop:divide-dayTimeDuration-by-dayTimeDuration(A, B)xs:decimal
A mod Bxs:numericxs:numericop:numeric-mod(A, B)xs:numeric
+ +

The operator symbol × is a synonym of *, while ÷ is +a synonym of div.

+ +

If there is no entry in the table for the combination of operator and operands, + then a is raised .

+ +

Errors may also occur during coercion of the operands, or during evaluation of the + identified function (for example, an error +might result from dividing by zero).

+ + + +

&language; provides three division operators:

The div and ÷ operators are synonyms, and implement @@ -13015,6 +13132,7 @@ type combination, including the dynamic errors that can be raised by the operato

The idiv operator implements integer division; the semantics are defined in

+

Here are some examples of arithmetic expressions:

@@ -13487,33 +13605,101 @@ length greater than one, a

+ + +

Expressions using operators other than eq and lt + are rewritten as follows:

+ + A ne B becomes not(A eq B) + A le B becomes A lt B or A eq B + A gt B becomes B lt A + A ge B becomes B lt A or B eq A + +

Finally, if the types of the operands are a valid combination for the given operator, the operator is applied to the - operands.

+ operands by applying the appropriate function from the table below.

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + -

The combinations of atomic types that are accepted by the various -value comparison operators, and their respective result types, are -listed in together with the operator functions that define -the semantics of the operator for each type combination. The -definitions of the operator functions are found in

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Value Comparison Operators
ExpressionType(A)Type(B)FunctionResult type
A eq Bxs:numericxs:numericop:numeric-equal(A, B)xs:boolean
A eq Bxs:booleanxs:booleanop:boolean-equal(A, B)xs:boolean
A eq Bxs:stringxs:stringop:numeric-equal(fn:compare(A, B), 0)xs:boolean
A eq Bxs:datexs:dateop:date-equal(A, B)xs:boolean
A eq Bxs:timexs:timeop:time-equal(A, B)xs:boolean
A eq Bxs:dateTimexs:dateTimeop:dateTime-equal(A, B)xs:boolean
A eq Bxs:durationxs:durationop:duration-equal(A, B)xs:boolean
A eq Bxs:gYearxs:gYearop:gYear-equal(A, B)xs:boolean
A eq Bxs:gYearMonthxs:gYearMonthop:gYearMonth-equal(A, B)xs:boolean
A eq Bxs:gMonthxs:gMonthop:gMonth-equal(A, B)xs:boolean
A eq Bxs:gMonthDayxs:gMonthDayop:gMonthDay-equal(A, B)xs:boolean
A eq Bxs:gDayxs:gDayop:gDay-equal(A, B)xs:boolean
A eq B(xs:hexBinary | xs:base64Binary)(xs:hexBinary | xs:base64Binary)op:binary-equal(A, B)xs:boolean
A eq Bxs:QNamexs:QNameop:QName-equal(A, B)xs:boolean
A eq Bxs:NOTATIONxs:NOTATIONop:NOTATION-equal(A, B)xs:boolean
A lt Bxs:numericxs:numericop:numeric-less-than(A, B)xs:boolean
A lt Bxs:booleanxs:booleanop:boolean-less-than(A, B)xs:boolean
A lt Bxs:stringxs:stringop:numeric-less-than(fn:compare(A, B), 0)xs:boolean
A lt Bxs:datexs:dateop:date-less-than(A, B)xs:boolean
A lt Bxs:timexs:timeop:time-less-than(A, B)xs:boolean
A lt Bxs:dateTimexs:dateTimeop:dateTime-less-than(A, B)xs:boolean
A lt Bxs:yearMonthDurationxs:yearMonthDurationop:yearMonthDuration-less-than(A, B)xs:boolean
A lt Bxs:dayTimeDurationxs:dayTimeDurationop:dayTimeDuration-less-than(A, B)xs:boolean
A lt B(xs:hexBinary | xs:base64Binary)(xs:hexBinary | xs:base64Binary)op:binary-less-than(A, B)xs:boolean
+ + +

The definitions of the operator functions are found in .

-

Informally, if both atomized operands consist of exactly one atomic -item, then the result of the comparison is true if the value of the -first operand is (equal, not equal, less than, less than or equal, -greater than, greater than or equal) to the value of the second -operand; otherwise the result of the comparison is false.

+ -

If the types of the operands, after evaluation, are not a valid -combination for the given operator, according to the rules in , a If the table contains no entry corresponding to the types of the operands, + after evaluation, then a type error is raised .

diff --git a/style/xmlspec-2016.xsl b/style/xmlspec-2016.xsl index 7b720b2a2..9606b0473 100644 --- a/style/xmlspec-2016.xsl +++ b/style/xmlspec-2016.xsl @@ -742,7 +742,7 @@ func-array- func-map- func-math- - func-op- + func-