Arithmetic Expressions
Introduction
This document describes the arithmetic operators which are supported in expressions. These all work on numeric data types (Integer/Long and Decimal).
Multiplication (*)
Multiplies two numbers.
Input parameters
The input parameters are described in the table below:
| Value | Type |
|---|---|
| First number | Integer/Long, Decimal |
| Second number | Integer/Long, Decimal |
Output
If the two inputs are both of type Integer/Long, the result is of type Integer/Long.
If either of the two inputs is of type Decimal, the result is of type Decimal.
Example
If you use the following input:
2*3The output is:
6Division (div or :)
Divides two numbers. You can use either the div or colon ( : ) syntax, as can be seen below in the examples. The colon ( : ) syntax is inspired by the divide symbol ÷. We cannot use the more conventional slash ( / ) syntax because that would conflict with the slash which is used for separating objects and members.
Input Parameters
The input parameters are described in the table below:
| Value | Type |
|---|---|
| First number | Integer/Long, Decimal |
| Second number | Integer/Long, Decimal |
Output
The result is always of type Decimal, regardless of the types for the inputs.
Example
Find the example of usages below:
-
The
divsyntax example: if you use the following input:3 div 5the output is:
0.6 -
:syntax example: if you use the following input:12 : 3the output is:
4.0
Remarks
The result of a division is only an approximation if it has an infinite decimal expansion. The two examples below illustrate this approximation:
-
If you use the following input:
3 : 7the output is:
0.4285714285714285714285714285714286If you continue a calculation with the results of a division, the results might be unexpected. The following input:
(3 : 7) * 7results in the output below:
3.0000000000000000000000000000000002 -
If you use the following input:
ceil((3 : 7) * 7)the output is:
4
Therefore, it is recommended to do division operations last.
Modulo (mod)
Calculates the remainder of the division of one number by another. In other words, m modulo n corresponds to: m = p + k*n, where p is the result of the operation m modulo n.
Input Parameters
The input parameters are described in the table below:
| Value | Type |
|---|---|
| First number | Integer/Long, Decimal |
| Second number | Integer/Long, Decimal |
Output
If the two inputs are both of type Integer/Long, the result is of type Integer/Long.
If either of the two inputs is of type Decimal, the result is of type Decimal.
Example
If you use the following input:
23 mod 5the output is:
3Addition (+)
Adds two numbers.
For the use of the addition symbol for string concatenation, see String function calls.
Input Parameters
The input parameters are described in the table below:
| Value | Type |
|---|---|
| First number | Integer/Long, Decimal |
| Second number | Integer/Long, Decimal |
Output
If the two inputs are both of type Integer/Long, the result is of type Integer/Long.
If either of the two inputs is of type Decimal, the result is of type Decimal.
Example
If you use the following input:
-3 + 4the output is:
1Subtraction (-)
Subtracts the second input from the first.
Input Parameters
The input parameters are described in the table below:
| Value | Type |
|---|---|
| First number | Integer/Long, Decimal |
| Second number | Integer/Long, Decimal |
Output
If the two inputs are both of type Integer/Long, the result is of type Integer/Long.
If either of the two inputs is of type Decimal, the result is of type Decimal.
Example
If you use the following input:
5 - 4the output is:
1