Important Notice
The pages on this site contain documentation for very old MS-DOS software,
purely for historical purposes.
If you're looking for up-to-date documentation, particularly for programming,
you should not rely on the information found here, as it will be woefully
out of date.
Arithmetic Expressions
◄Up► ◄Contents► ◄Index► ◄Back►
─────Arithmetic Expressions─────────────────────────────────────────────────
An arithmetic expression produces a value that is an integer, a
real or complex number, or an array of those types. Basic operands
used in arithmetic expressions are
■ Arithmetic constants or variables
■ Variables
■ Arrays or array elements
■ Function references
Arithmetic expressions are built from basic operands and arithmetic
operators.
Arithmetic Operators
Operator Operation Precedence
** Exponentiation 1 (highest)
/ Division 2
* Multiplication 2
- Subtraction (binary) 3
or negative (unary
+ Addition (binary) or 3
identity (unary)
Arithmetic operators are binary operators, appearing between two
operands. The plus and minus operators are also unary operators,
which precede a single operand.
When consecutive operations are of equal precedence, the leftmost
operation is performed first except exponentiation. With two or
more consecutive exponents, the rightmost operation is performed
first.
Integer Division
Integer division returns the truncated quotient of the two
operands.
Sample results of integer divisions:
-7/3 evaluates to 2
9/10 evaluates to 0
1/4 + 1/4 evaluates to 0
Type Conversion of Arithmetic Operands
When all operands of an arithmetic expression are of the same data
type, the value returned by the expression is also of that type.
When the operands are of different data types, the type of the
value returned by the expression is the type of the highest-ranked
operand.
The exception to the rule is operations involving both REAL*8
numbers and COMPLEX*8 numbers, which yield COMPLEX*16 results.
Ranking of arithmetic operands:
Operand Precedence
DOUBLE COMPLEX or COMPLEX*16 1 (highest rank)
COMPLEX[*8] 2
DOUBLE PRECISION or REAL*8 3
REAL[*4] 4
INTEGER*4 5
INTEGER*2 6
INTEGER*1 (lowest rank) 7
Example: An operation performed on an INTEGER*2 and a REAL*4, the
INTEGER*2 operand is first converted to REAL*4. The result is a
value of data type REAL*4.
In an operation on a real number and a complex number, the real
number is converted to a complex number, and the result is also
complex.
-♦-