Division; Order Of Evaluation - IBM TSO/E REXX User Manual

Table of Contents

Advertisement

Using numeric constants and arithmetic operators, you can write arithmetic
expressions as follows:
7 + 2
7 - 2
7 * 2
7 ** 2
7 ** 2.5

Division

Notice that three operators represent division. Each operator displays the result of a
division expression in a different way.
/
Divide and express the answer possibly as a decimal number. For example:
7 / 2
6 / 2
%
Divide and express the answer as a whole number. The remainder is
ignored. For example:
7 % 2
//
Divide and express the answer as the remainder only. For example:
7 // 2

Order of Evaluation

When you have more than one operator in an arithmetic expression, the order of
numbers and operators can be critical. For example, in the following expression,
which operation does the language processor perform first?
7 + 2 * (9 / 3) - 1
Proceeding from left to right, it is evaluated as follows:
v Expressions within parentheses are evaluated first.
v Expressions with operators of higher priority are evaluated before expressions
with operators of lower priority.
Arithmetic operator priority is as follows, with the highest first:
Arithmetic Operator Priority
- +
Prefix operators
**
Power (exponential)
* / % //
Multiplication and division
+ -
Addition and subtraction
Thus the preceding example would be evaluated in the following order:
1. Expression in parentheses
7 + 2 * (9 / 3) - 1
\___/
3
2. Multiplication
7 + 2 * 3 - 1
\___/
6
3. Addition and subtraction from left to right
7 + 6 - 1 = 12
/* result is 9
*/
/* result is 5
*/
/* result is 14
*/
/* result is 49
*/
/* result is an error */
/* result is 3.5
/* result is 3
/* result is 3
/* result is 1
Chapter 3. Using Variables and Expressions
Using Expressions
*/
*/
*/
*/
29

Hide quick links:

Advertisement

Table of Contents
loading

Table of Contents