Next: Data Type Conversions Up: Arithmetic Expressions Previous: Arithmetic Expressions

### General Rules

Arithmetic expressions can contain arithmetic operands, arithmetic operators, and parentheses. There must always be at least one operand. The operands can belong to any of the four arithmetic data types (integer, real, double precision, or complex); the result also has an arithmetic data type. Operands can be any of the following:

• unsigned literal constants
• named constants
• variables
• array elements
• function references
• complete expressions enclosed in parentheses.
The rules for forming more complicated arithmetic expressions are as follows. An arithmetic expression can have any of the following forms:
 operand +operand -operand arithmetic-expression   arith-op   operand
where the arith-op can be any of these operators:
 `+` addition `-` subtraction `*` multiplication `/` division `**` exponentiation

The effect of these rules is that an expression consists of a string of operands separated by operators and, optionally, a plus or minus at the start. A leading plus sign has no effect; a leading minus sign negates the value of the expression.

All literal arithmetical constants used in expressions must be unsigned: this is to prevent the use of two consecutive operators which is confusing and possibly ambiguous:
` 4 / -3.0**-1 ` (illegal).
The way around this is to use parentheses, for example:
` 4 / (-3.0)**(-1)`
which makes the order of evaluation explicit.
The order of evaluation of an expression is:

1.
sub-expressions in parentheses
2.
function references
3.
exponentiation, i.e. raising to a power
4.
multiplication and division
5.
` X * FUNC(G)`