Quick start manual

Syntactic elements
4-7
Expressions
The operators @, not, and ^ are unary (taking one operand). All other operators are
binary (taking two operands), except that + and can function as either a unary or
binary operator. A unary operator always precedes its operand (for example, -B),
except for ^, which follows its operand (for example, P^). A binary operator is placed
between its operands (for example, A = 7).
Some operators behave differently depending on the type of data passed to them. For
example, not performs bitwise negation on an integer operand and logical negation
on a Boolean operand. Such operators appear below under multiple categories.
Except for ^, is, and in, all operators can take operands of type Variant. For details,
see “Variant types” on page 5-33.
The sections that follow assume some familiarity with Delphi data types. For
information about data types, see Chapter 5, “Data types, variables, and constants”.
For information about operator precedence in complex expressions, see “Operator
precedence rules” on page 4-13.
Arithmetic operators
Arithmetic operators, which take real or integer operands, include +, , *, /, div, and
mod.
The following rules apply to arithmetic operators.
•The value of x/y is of type Extended, regardless of the types of x and y. For other
arithmetic operators, the result is of type Extended whenever at least one operand
is a real; otherwise, the result is of type Int64 when at least one operand is of type
Int64; otherwise, the result is of type Integer. If an operand’s type is a subrange of
an integer type, it is treated as if it were of the integer type.
•The value of x div y is the value of x/y rounded in the direction of zero to the
nearest integer.
Table 4.4 Binary arithmetic operators
Operator Operation Operand types Result type Example
+ addition integer, real integer, real X + Y
subtraction integer, real integer, real Result - 1
* multiplication integer, real integer, real P * InterestRate
/ real division integer, real real X / 2
div integer division integer integer Total div UnitSize
mod remainder integer integer Y mod 6
Table 4.5 Unary arithmetic operators
Operator Operation Operand type Result type Example
+ sign identity integer, real integer, real +7
sign negation integer, real integer, real -X