Skip to main content
Version: 7.0

Arithmetic operators (+, -, *, ...)

Arithmetic operators create properties whose value is the result of an arithmetic operation. They primarily operate on values of number classes. In addition, the sum and difference also operate on date/time values (described below), and the sum also concatenates strings (see String operators). The platform currently supports the following arithmetic operators:

OperatorNameDescriptionExampleResult
+SummationTakes two input operands and returns their sum3 + 58
-DifferenceAccepts two input operands and returns their difference
This operator also has a unary form, in which case the first operand is considered equal to 0
5 - 32
*MultiplicationAccepts two input operands and returns their product3 * 515
/RatioTakes two input operands and returns their ratio15 / 35

All of these operators return NULL if one of the operands is NULL . Division by zero also returns NULL. It is also possible to use a special form of summation and difference operators with brackets, in which case NULL will be equivalent to 0. The reverse is also true for these type of operators: if the result of an operator in such form is 0, then NULL is returned (e. g., 5 (-) 5 = NULL):

OperatorNameDescriptionExampleResult
(+)SummationTakes two input operands and returns their sum, treating NULL as 03 (+) 5
3 (+) NULL
8
3
(-)DifferenceTakes two input operands and returns their difference, treating NULL as 05 (-) 3
5 (-) NULL
5 (-) 5
2
5
NULL

Determining the result class

The result class is determined as:

OperatorResult
+, -Common ancestor ("Numbers" family)
*NUMERIC[p1.IntegerPart + p1.Precision + p2.IntegerPart + p2.Precision, p1.Precision + p2.Precision]
/NUMERIC[p1.IntegerPart + p2.Precision + s, s]

The NUMERIC[ , ] formulas for the product and the ratio apply only when at least one operand belongs to NUMERIC[ , ]; otherwise the result is the common ancestor ("Numbers" family) of the two operand classes, so the product or ratio of two integers is itself an integer — the ratio being integer (truncating) division. In the ratio formula s is the maximum NUMERIC scale (32 by default).

The sum and the difference also operate on date/time values, where a whole number is counted in base units — days for DATE, seconds for DATETIME, ZDATETIME, and TIME:

OperandsResult
date/time value + / - a whole numberthe same date/time class
DATE - DATEINTEGER (number of days)
DATETIME / ZDATETIME / TIME - a value of the same classLONG (number of base units)

Language

Description of arithmetic operators.

Examples

sum(a, b) = a + b;
transform(a, b, c) = -a * (b (+) c);