8.5.6   Basic Arithmetic Operations

See table 8.10 for an overview of the available basic arithmetic operations.

All operations are left-associative, except the right-associative unary minus operator. The evaluation usually is done from left to right. However, parentheses can change the order of evaluation and some operators have a higher precedence than others (see section “Operation Precedence”).

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

Table 8.10: Basic arithmetic operations.

The arithmetic operations in HDevelop 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.

Examples:

Expression Result

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

Table 8.11: Example Expressions.

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