Arithmetic Operations

The arithmetic statements are ADD, COMPUTE, DIVIDE, MULTIPLY, and SUBTRACT. They have several common features.

  1. The data descriptions of the operands need not be the same. Any necessary conversion and decimal point alignment is supplied throughout the calculation.
  2. The maximum size of each operand is 18 digits. This increases to 31 if 31-digit support (-Dd31) is in effect. If the composite of operands contains more than 18 digits, the results will be undefined. The composite of operands is a hypothetical data item resulting from the superposition of the operands aligned on their decimal point.
  3. A calculation may result in the compiler's constructing a temporary data item to hold an intermediate result. The temporary item holds the 20 most significant digits of the intermediate result. (If 31-digit support (-Dd31) is in effect, the temporary data item holds 33 digits.) The truncated low-order digits (if any) are treated as zeros.
  4. When the final value of the operation is stored in the receiving field(s), it is transferred to maintain its arithmetic value. If the receiving field is too small to hold the result, leading digits before the decimal point and trailing digits after the decimal point are removed as needed (but see the ON SIZE ERROR phrase for an exception). If the receiving field is unsigned and the value is negative, the results are undefined.
  5. An attempt to use non-numeric data in a field defined as numeric results in an intermediate runtime error. Intermediate errors call installed error procedures. See Appendix I. Library Routines for detailed discussion of the runtime Error and Exit Procedures.
    Note: In division operations, the remainder is calculated before the quotient is moved to the destination item(s). The remainder will almost always be 0 if the dividend or divisor is floating-point. This is because all of the arithmetic is performed using floating-point variables. The remainder will be non-zero only if precision is lost during the calculation.