Binary Operators

Binary expressions are expressions where an Operator is used to operate ion two expressions, one provided on its left, and one on its right (commonly refered to as the left-hand and right-hand expression).

Examples:

if a < b then ...

if SomeVariable is not String then writeLn(not a String)

Operator Precedence

When used in more complex expressions, binary operators will be evaluated according to their order of precedence, starrting with the highest order. For example in the expression 5 + 10 * 2, the multiplication will happen before the addition, resulting in 25. Operators of the same precedence will be executed from lef to right, so for the expression 10 - 3 + 8, the subtraction will happen first, then the addition, resulting in 15.

The , <, and > operators can also be used in Double Boolean Comparisons. Here, the middle operand will be compared both to the first and to the last operand, in order. Boolean Short-Circuit will apply for the second comparison:

var y := 10;
if 10 ≤ x ≤ 15 then 
  writeLn("x is between 10 and 15").

When mixed with Unary Operators, the unary operatores take full precedence. So for the expression 5 + -3 + 8, the value 3 will be negated first, and the additions are then performed, resulting in 10.

Operators

The table below lists all available binary operators.

Operator Precedence Description
0 (Also >=) Greater than or equal
0 (Also <=) Less than or equal
> 0 Greater than
< 0 Less than
= 0 Equal
0 (Also <>) Not equal
in 0 Check if the left-hand value side is in the Array, Set or Flags Enum on the right..
not in 0 Returns the oposite of in
is 0 The Type Check Operator. Checks if the left-hand-side object is of the right-hand-side type.
is not 0 Returns the oposite of is
implies 0 a implies b, translates to not a or b
+ 1 Add two values
- 1 Substract two values
or 1 Logical or binary or
xor 1 Exclusive or
** 2 Power of
* 2 Multiply
/ 2 Divide; When the Delphi Compatible Division option is set this always results in a float
div 2 Divide
mod 2 Modulus
and 2 Logical or binary AND
shl 2 Shift left
shr 2 Shift right
as 2 The Type Cast Operator. Casts left side to the type on the right, or fails with an Exception. nil results in a nil.
+= 3 Add an event handler to an Event
-= 3 Remove an event handler from an Event

For the +, -, * /, div, mod, and, or, xor, shl, shr, =, , <, , >, , in and not operators, Custom Types can implement Custom Operators that provide type-specific behavior.

See Also