Performing Arithmetic Operations

In queries, a number represents a floating-point number. A number can have any double-precision 64-bit format IEEE 754 value. This includes

l A special not-a-number (NaN) value
l Positive and negative infinity
l Positive and negative zero

The numeric operators convert their operands to numbers as if by calling the number() function. See Converting an Object to a Number.

You can use the following arithmetic operators in queries:

l + performs addition
l - performs subtraction
XML allows hyphens (-) in names. Consequently, the subtraction operator (-) typically needs to be preceded by white space. For example, foo-bar evaluates to a node set that contains the child elements named foo-bar. However, foo - bar evaluates to the difference between the result of converting the string value of the first foo child element to a number and the result of converting the string value of the first bar child to a number.
l * performs multiplication
l mod returns the remainder from a truncating division. For example:
m 5 mod 2 returns 1.
m 5 mod -2 returns 1.
m -5 mod 2 returns -1.
m -5 mod -2 returns -1.
The mod operator is the same as the % operator in Java and ECMAScript. But it does not perform the same operation as the IEEE remainder operation, which returns the remainder from a rounding division.
l div performs floating-point division according to IEEE 754.
 
Free Stylus Studio XML Training: