IBM SC34-5764-01 Server User Manual


 
an operation, when a number is rounded to the required precision.) The operation is then carried out under
up to double that precision, as described under the individual operations that follow. When the operation is
completed, the result is rounded if necessary to the precision specified by the NUMERIC DIGITS
instruction.
Rounding is done in the traditional manner. The digit to the right of the least significant digit in the result
(the “guard digit”) is inspected and values of 5 through 9 are rounded up, and values of 0 through 4 are
rounded down. Even/odd rounding would require the ability to calculate to arbitrary precision at all times
and is, therefore, not the mechanism defined for REXX.
A conventional zero is supplied in front of the decimal point if otherwise there would be no digit before it.
Significant trailing zeros are retained for addition, subtraction, and multiplication, according to the rules that
follow, except that a result of zero is always expressed as the single digit 0. For division, insignificant
trailing zeros are removed after rounding.
The FORMAT built-in function (see page 185) allows a number to be represented in a particular format if
the standard result provided does not meet your requirements.
Arithmetic Operation Rules—Basic Operators
The basic operators (addition, subtraction, multiplication, and division) operate on numbers as follows.
Addition and Subtraction
If either number is 0, the other number, rounded to NUMERIC DIGITS digits, if necessary, is used as the
result (with sign adjustment as appropriate). Otherwise, the two numbers are extended on the right and left
as necessary, up to a total maximum of DIGITS + 1 digits (the number with the smaller absolute value
may, therefore, lose some or all of its digits on the right) and are then added or subtracted as appropriate.
Example:
xxx.xxx + yy.yyyyy
becomes:
xxx.xxx00
+ 0yy.yyyyy
─────────────
zzz.zzzzz
The result is then rounded to the current setting of NUMERIC DIGITS if necessary (taking into account
any extra “carry digit” on the left after addition, but otherwise counting from the position corresponding to
the most significant digit of the terms being added or subtracted). Finally, any insignificant leading zeros
are removed.
The prefix operators are evaluated using the same rules; the operations +number and -number are
calculated as 0+number and 0-number, respectively.
Multiplication
The numbers are multiplied together (“long multiplication”) resulting in a number that may be as long as
the sum of the lengths of the two operands.
Example:
xxx.xxx * yy.yyyyy
becomes:
zzzzz.zzzzzzzz
Numbers and Arithmetic
Chapter 16. Numbers and Arithmetic 219