Definition
A precise definition of the arithmetic facilities of the REXX language is given here.
Numbers
A number in REXX is a character string that includes one or more decimal digits, with an optional decimal
point. (See section “Exponential Notation” on page 222 for an extension of this definition.) The decimal
point may be embedded in the number, or may be a prefix or suffix. The group of digits (and optional
decimal point) constructed this way can have leading or trailing blanks and an optional sign (+ or -) that
must come before any digits or decimal point. The sign can also have leading or trailing blanks.
Therefore, number is defined as:
blanks sign
blanks
digits
digits.digits
.digits
digits.
blanks
blanks
are one or more spaces
sign
is either + or −
digits
are one or more of the decimal digits 0–9.
Note that a single period alone is not a valid number.
Precision
Precision is the maximum number of significant digits that can result from an operation. This is controlled
by the instruction:
NUMERIC DIGITS
expression
;
The expression is evaluated and must result in a positive whole number. This defines the precision
(number of significant digits) to which calculations are carried out. Results are rounded to that precision, if
necessary.
If you do not specify expression in this instruction, or if no NUMERIC DIGITS instruction has been
processed since the start of a program, the default precision is used. The REXX standard for the default
precision is 9.
Note that NUMERIC DIGITS can set values below the default of nine. However, use small values with
care—the loss of precision and rounding thus requested affects all REXX computations, including, for
example, the computation of new values for the control variable in DO loops.
Arithmetic Operators
REXX arithmetic is performed by the operators +, -, *, /, %, //, and ** (add, subtract, multiply, divide,
integer divide, remainder, and power), which all act on two terms, and the prefix plus and minus operators,
which both act on a single term. This section describes the way in which these operations are carried out.
Before every arithmetic operation, the term or terms being operated upon have leading zeros removed
(noting the position of any decimal point, and leaving only one zero if all the digits in the number are
zeros). They are then truncated (if necessary) to DIGITS + 1 significant digits before being used in the
computation. (The extra digit is a “guard” digit. It improves accuracy because it is inspected at the end of
Numbers and Arithmetic
218
CICS TS for VSE/ESA: REXX Guide