Skip to content

Basic Arithmetic Operations🔗

See Table 1 for an overview of the available basic arithmetic operations.

All operations are left-associative, except for the right-associative unary minus operator. The evaluation usually is done from left to right. Parentheses can change the order of evaluation, and some operators have a higher precedence than others; see the section on operation precedence.

Table 1: Basic arithmetic operations
Operation Meaning HALCON operator
a1 / a2 division tuple_div
a1 * a2 multiplication tuple_mult
i1 % i2 modulus tuple_mod
a1 + a2 addition tuple_add
a1 - a2 subtraction tuple_sub
-a negation tuple_neg

The arithmetic operations in HDevelopEVO match the usual definitions. Expressions can have any number of parentheses.

The division operator (a1 / a2) can be applied to integer as well as to real. The result is of type real, if at least one of the operands is of type real. If both operands are of type integer, the division is an integer division.

The remaining arithmetic operators (multiplication, addition, subtraction, and negation) can be applied to either integer or real numbers. If at least one operand is of type real, the result will be a real number as well.

Example

Expression Result
4/3 1
4/3.0 1.3333333
(4/3) * 2.0 2.0

Simple examples can also be found in the program arithmetic.hdev.