The result is then rounded, counting from the first significant digit of the result, to the current setting of
NUMERIC DIGITS.
Division
For the division:
yyy / xxxxx
the following steps are taken: First the number yyy is extended with zeros on the right until it is larger than
the number xxxxx (with note being taken of the change in the power of ten that this implies). Thus, in this
example, yyy might become yyy00. Traditional long division then takes place. This might be written:
zzzz
┌─────────
xxxxx │ yyy00
The length of the result (zzzz) is such that the rightmost z is at least as far right as the rightmost digit of
the (extended) y number in the example. During the division, the y number is extended further as
necessary. The z number may increase up to NUMERIC DIGITS+1 digits, at which point the division stops
and the result is rounded. Following completion of the division (and rounding if necessary), insignificant
trailing zeros are removed.
Basic Operator Examples
Following are some examples that illustrate the main implications of the rules just described.
/* With: Numeric digits 5 */
12+7.00 -> 19.00
1.3-1.07 -> 0.23
1.3-2.07 -> -0.77
1.20*3 -> 3.60
7*3 -> 21
0.9*0.8 -> 0.72
1/3 -> 0.33333
2/3 -> 0.66667
5/2 -> 2.5
1/10 -> 0.1
12/12 -> 1
8.0/2 -> 4
Note: With all the basic operators, the position of the decimal point in the terms being operated upon is
arbitrary. The operations may be carried out as integer operations with the exponent being
calculated and applied afterward. Therefore, the significant digits of a result are not in any way
dependent on the position of the decimal point in either of the terms involved in the operation.
Arithmetic Operation Rules—Additional Operators
The operation rules for the power (**), integer divide (%), and remainder (//) operators follow.
Power
The ** (power) operator raises a number to a power, which may be positive, negative, or 0. The power
must be a whole number. (The second term in the operation must be a whole number and is rounded to
DIGITS digits, if necessary, as described under “Numbers Used Directly by REXX” on page 224.) If
negative, the absolute value of the power is used, and then the result is inverted (divided into 1). For
calculating the power, the number is effectively multiplied by itself for the number of times expressed by
the power, and finally trailing zeros are removed (as though the result were divided by 1).
In practice (see Note 1 on page 221 for the reasons), the power is calculated by the process of left-to-right
binary reduction. For a**n: n is converted to binary, and a temporary accumulator is set to 1. If n = 0 the
initial calculation is complete. (Thus, a**0 = 1 for all a, including 0**0.) Otherwise each bit (starting at the
first nonzero bit) is inspected from left to right. If the current bit is 1, the accumulator is multiplied by a.If
Numbers and Arithmetic
220
CICS TS for VSE/ESA: REXX Guide