Numerical operands can be combined, by using the binary operators listed in the following table.
Operator | Description |
---|---|
+ | Addition |
- | Subtraction |
* | Multiplication |
/ | Real division (for example, 7 / 3 = 2.33333333333333) |
div | Integer division (division with truncation; for example, 7 div 3 = 2) |
^ | Exponentiation (for example, x^3 is x cubed) |
mod | Modulus (remainder after integer division) |
The code fragments in the following examples show the use of arithmetic binary operators.
if (shift div 2) mod 2 = 1 then // test if Ctrl key is pressed
while result > 0 do remainder := result mod 16; result := result div 16; outString := hexVals[remainder + 1] & outString; endwhile;
The operands of the div operator can be any mix of
If either operand of a div operation is of type Integer64, the result is also of type Integer64.
You can make arithmetic operations between numeric expressions that have a different type, as shown in the following example.
vars int : Integer; dec : Decimal[4,2]; begin int := 7; dec := 5.2; write int + dec; end;
Before the operation is carried out, the expression with the lower numeric type is converted to the type of the other expression. In the following list of the order of numeric types, the
In the previous example, the int operand is converted to Decimal (the same type as the dec operand) before the comparison is made.