Building Queries and Data Views
|
Numeric Operators
XQuery has operators that are specific to numeric operations. The following numeric operators are available:
* (multiply)
Returns the arithmetic product of the operands: ($operand1*$operand2).
Data Types
- Parameter1 data type: xs:anyValue?
- Parameter2 data type: xs:anyValue?
- Returned data type: xs:anyValue?
Notes
This is a numeric operator that you can use as if it were a function to compute numeric results.
The operator accepts two numeric values as parameters, computes their product, and returns the result.
Liquid Data applies the following rules:
- If both parameters are promotable to xs:decimal, the operator returns their product as a decimal value.
- If both parameters are promotable to xs:float, the operator returns their product as a floating point value.
- If both parameters are promotable to xs:double, the operator returns their product as a double precision value.
- Otherwise, an error occurs because one of the parameters is not a number.
XQuery Specification Compliance
- Liquid Data supports only numeric multiplication (op:numeric-multiply) and no other backup functions. It does not support values, such as xs:yearMonthDuration and xs:dayTimeDuration.
- Liquid Data does not support not-a-number (NaN), -0, or the negative and positive infinity values -INF and INF.
Examples
- 12 * 3 returns the decimal value 36.
- xf:integer("1") * 3.1 returns the decimal value 3.1.
- "abc" * "cde" generates a compile-time error because the operator can be used only with numbers.
+ (add)
Returns the arithmetic sum of the operands: ($operand1+$operand2).
Data Types
- Parameter1 data type: xs:anyValue?
- Parameter2 data type: xs:anyValue?
- Returned data type: xs:anyValue?
Notes
This is a numeric operator that you can use as if it were a function to compute numeric results.
The operator accepts two numeric values as parameters, computes their sum, and returns the result.
Liquid Data applies the following rules:
- If both parameters are promotable to xs:decimal, the operator returns their sum as a decimal value.
- If both parameters are promotable to xs:float, the operator returns their sum as a floating point value.
- If both parameters are promotable to xs:double, the operator returns their sum as a double precision value.
- Otherwise, an error occurs because one of the parameters is not a number.
XQuery Specification Compliance
- Liquid Data supports only numeric multiplication (op:numeric-add) and no other backup functions. It does not support values, such as xs:yearMonthDuration and xs:dayTimeDuration.
- Liquid Data does not support not-a-number (NaN), -0, or the negative and positive infinity values -INF and INF.
Examples
- 20 + 1 returns the decimal value 21.
- xf:integer("1") + 3.1 returns the decimal value 4.1.
- "abc" + "cde" generates a compile-time error because the operator can only be used with numbers.
- (subtract)
Returns the arithmetic difference of the operands: ($operand1-$operand2).
Data Types
- Parameter1 data type: xs:anyValue?
- Parameter2 data type: xs:anyValue?
- Returned data type: xs:anyValue?
Notes
This is a numeric operator that you can use as if it were a function to compute numeric results.
Liquid Data applies the following rules:
- If both parameters are promotable to xs:decimal, the operator returns their difference as a decimal value.
- If both parameters are promotable to xs:float, the operator returns their difference as a floating point value.
- If both parameters are promotable to xs:double, the operator returns their difference as a double precision value.
- Otherwise, an error occurs because one of the parameters is not a number.
XQuery Specification Compliance
- Liquid Data supports only numeric multiplication (op:numeric-subtract) and no other backup functions. It does not support values, such as xs:yearMonthDuration and xs:dayTimeDuration.
- Liquid Data does not support not-a-number (NaN), -0, or the negative and positive infinity values -INF and INF.
Examples
- 20 - 1 returns the decimal value 19.
- xf:integer("1") - 3.1 returns the decimal value -2.1.
- "abc" - "cde" generates a compile-time error because the operator can only be used with numbers.
div
Returns the arithmetic quotient of the operands ($operand1/$operand2).
Data Types
- Parameter1 data type: xs:anyValue?
- Parameter2 data type: xs:anyValue?
- Returned data type: xs:anyValue?
Notes
This is a numeric operator that you can use as if it were a function to compute numeric results.
Liquid Data applies the following rules:
- If both parameters are promotable to xs:decimal, the operator returns their quotient as a decimal value.
- If both parameters are promotable to xs:float, the operator returns their quotient as a floating point value.
- If both parameters are promotable to xs:double, the operator returns their quotient as a double precision value.
- Otherwise, an error occurs because one of the parameters is not a number.
XQuery Specification Compliance
- Liquid Data supports only numeric multiplication (op:numeric-divide) and no other backup functions. It does not support values, such as xs:yearMonthDuration and xs:dayTimeDuration.
- Liquid Data does not support not-a-number (NaN), -0, or the negative and positive infinity values -INF and INF.
Examples
- 2 div 5 returns the decimal value 0.
- 3 div 5 returns the decimal value 1.
- 4 div "abc" generates a compile-time error because the operator can only be used with numbers.
mod
Returns the remainder after dividing the first operand by the second operand:
($operand1 mod $operand2).
Data Types
- Parameter1 data type: xs:anyValue?
- Parameter2 data type: xs:anyValue?
- Returned data type: xs:anyValue?
Notes
This is a numeric operator that you can use as if it were a function to compute numeric results.
Liquid Data applies the following rules:
- If both parameters are promotable to xs:decimal, the operator returns the remainder as a decimal value.
- If both parameters are promotable to xs:float, the operator returns the remainder as a floating point value.
- If both parameters are promotable to xs:double, the operator returns the remainder as a double precision value.
- Otherwise, an error occurs because one of the parameters is not a number.
XQuery Specification Compliance
Liquid Data does not support not-a-number (NaN), -0, or the negative and positive infinity values -INF and INF.
Examples
- 2 mod 5 returns the decimal value 2.
- 3 mod 5 returns the decimal value -2.
- 4 mod "abc" generates a compile-time error because the operator can only be used with numbers.