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.
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
.
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
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.
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
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.
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 $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.
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.
+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 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:
where $c
is the converted sequence.
The result of the function 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
.
$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.
+
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 xs:integer
) and function types
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 xs:numeric
is referred to
+ as a
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
If true
, each operand is evaluated by applying the following steps, in order:
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 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
Expression | +Type of A | +Function | +Result type | +
---|---|---|---|
+ A | xs:numeric | (A) | xs:numeric |
- A | xs:numeric | (A) | xs:numeric |
Expression | +Type of A | +Type of B | +Function | +Result type | +
---|---|---|---|---|
A + B | xs:numeric | xs:numeric | (A, B) | xs:numeric |
A + B | xs:date | xs:yearMonthDuration | (A, B) | xs:date |
A + B | xs:yearMonthDuration | xs:date | (B, A) | xs:date |
A + B | xs:date | xs:dayTimeDuration | (A, B) | xs:date |
A + B | xs:dayTimeDuration | xs:date | (B, A) | xs:date |
A + B | xs:time | xs:dayTimeDuration | (A, B) | xs:time |
A + B | xs:dayTimeDuration | xs:time | (B, A) | xs:time |
A + B | xs:dateTime | xs:yearMonthDuration | (A, B) | xs:dateTime |
A + B | xs:yearMonthDuration | xs:dateTime | (B, A) | xs:dateTime |
A + B | xs:dateTime | xs:dayTimeDuration | (A, B) | xs:dateTime |
A + B | xs:dayTimeDuration | xs:dateTime | (B, A) | xs:dateTime |
A + B | xs:yearMonthDuration | xs:yearMonthDuration | (A, B) | xs:yearMonthDuration |
A + B | xs:dayTimeDuration | xs:dayTimeDuration | (A, B) | xs:dayTimeDuration |
A - B | xs:numeric | xs:numeric | (A, B) | xs:numeric |
A - B | xs:date | xs:date | (A, B) | xs:dayTimeDuration |
A - B | xs:date | xs:yearMonthDuration | (A, B)
+ | xs:date |
A - B | xs:date | xs:dayTimeDuration | (A, B) | xs:date |
A - B | xs:time | xs:time | (A, B) | xs:dayTimeDuration |
A - B | xs:time | xs:dayTimeDuration | (A, B) | xs:time |
A - B | xs:dateTime | xs:dateTime | (A, B) | xs:dayTimeDuration |
A - B | xs:dateTime | xs:yearMonthDuration | (A, B) | xs:dateTime |
A - B | xs:dateTime | xs:dayTimeDuration | (A, B) | xs:dateTime |
A - B | xs:yearMonthDuration | xs:yearMonthDuration | (A, B) | xs:yearMonthDuration |
A - B | xs:dayTimeDuration | xs:dayTimeDuration | (A, B) | xs:dayTimeDuration |
A * B | xs:numeric | xs:numeric | (A, B) | xs:numeric |
A * B | xs:yearMonthDuration | xs:numeric | (A, B) | xs:yearMonthDuration |
A * B | xs:numeric | xs:yearMonthDuration | (B, A) | xs:yearMonthDuration |
A * B | xs:dayTimeDuration | xs:numeric | (A, B) | xs:dayTimeDuration |
A * B | xs:numeric | xs:dayTimeDuration | (B, A) | xs:dayTimeDuration |
A idiv B | xs:numeric | xs:numeric | (A, B) | xs:integer |
A div B | xs:numeric | xs:numeric | (A, B) | numeric; but xs:decimal if both operands are xs:integer |
A div B | xs:yearMonthDuration | xs:numeric | (A, B) | xs:yearMonthDuration |
A div B | xs:dayTimeDuration | xs:numeric | (A, B) | xs:dayTimeDuration |
A div B | xs:yearMonthDuration | xs:yearMonthDuration | (A, B) | xs:decimal |
A div B | xs:dayTimeDuration | xs:dayTimeDuration | (A, B) | xs:decimal |
A mod B | xs:numeric | xs:numeric | (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
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 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
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, aExpressions 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.Expression | +Type(A) | +Type(B) | +Function | +Result type | +
---|---|---|---|---|
A eq B | xs:numeric | xs:numeric | (A, B) | xs:boolean |
A eq B | xs:boolean | xs:boolean | (A, B) | xs:boolean |
A eq B | xs:string | xs:string | ( (A, B), 0) | xs:boolean |
A eq B | xs:date | xs:date | (A, B) | xs:boolean |
A eq B | xs:time | xs:time | (A, B) | xs:boolean |
A eq B | xs:dateTime | xs:dateTime | (A, B) | xs:boolean |
A eq B | xs:duration | xs:duration | (A, B) | xs:boolean |
A eq B | xs:gYear | xs:gYear | (A, B) | xs:boolean |
A eq B | xs:gYearMonth | xs:gYearMonth | (A, B) | xs:boolean |
A eq B | xs:gMonth | xs:gMonth | (A, B) | xs:boolean |
A eq B | xs:gMonthDay | xs:gMonthDay | (A, B) | xs:boolean |
A eq B | xs:gDay | xs:gDay | (A, B) | xs:boolean | A eq B | (xs:hexBinary | xs:base64Binary) | (xs:hexBinary | xs:base64Binary) | (A, B) | xs:boolean | + + +
A eq B | xs:QName | xs:QName | (A, B) | xs:boolean |
A eq B | xs:NOTATION | xs:NOTATION | (A, B) | xs:boolean |
A lt B | xs:numeric | xs:numeric | (A, B) | xs:boolean |
A lt B | xs:boolean | xs:boolean | (A, B) | xs:boolean |
A lt B | xs:string | xs:string | ( (A, B), 0) | xs:boolean |
A lt B | xs:date | xs:date | (A, B) | xs:boolean |
A lt B | xs:time | xs:time | (A, B) | xs:boolean |
A lt B | xs:dateTime | xs:dateTime | (A, B) | xs:boolean |
A lt B | xs:yearMonthDuration | xs:yearMonthDuration | (A, B) | xs:boolean |
A lt B | xs:dayTimeDuration | xs:dayTimeDuration | (A, B) | xs:boolean |
A lt B | (xs:hexBinary | xs:base64Binary) | (xs:hexBinary | xs:base64Binary) | (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