Perform Arithmetic Expressions in Editor Macros

You can perform basic arithmetic operations between variables in an Editor macro. Basic operators available to you are:

+ addition
- subtraction
* multiplication
/ division
% division, returning only the whole number part of the result
// whole number division, returning only the remainder part of the result

An arithmetic expression performs operations with two or more terms. Terms in an arithmetic expression can include any combination of numeric constants, variables, and REXX functions. The result of the arithmetic expression must be assigned to a variable.

Some simple arithmetic expressions are:

   a = 10 + 12        - a is assigned a value of 22 
   b = 11 / 2         - b is assigned a value of 5.5
   c = 10 * abs(-10)  - c is assigned a value of 100 
   d = 11 % 2         - d is assigned a value of 5 
   e = 11 // 2        - e is assigned a value of 1 

More complex arithmetic expressions can mix several arithmetic operators in the same expression. In such expressions, the normal rules of arithmetic precedence apply, with arithmetic expressions inside parentheses evaluated first, and multiplication and division operations performed before addition and subtraction operations. For example:

   a = 8 + 12 / 4     - a is assigned a value of 11 
   b = (8 + 12) / 4   - b is assigned a value of 5 

Perform REXX Functions in Editor Macros