Syntax rules
All identifiers used in arithmetic statements must be defined as numeric data in the Data Division.
All literals used in arithmetic statements must be numeric. They may be floating-point literals.
The maximum size of any operand (identifier or literal) is 31 decimal digits.
The maximum size of all results after decimal point alignment is 31 decimal digits.
When several operands occurring in an arithmetic statement are "overlapped" in a hypothetical data item, aligned on their decimal points, then the maximum size of the data item required (i.e. the composite of operands) is 31 decimal digits (see "ADD statement" and "SUBTRACT statement").
A maximum of 100 operands may be supplied in one arithmetic statement or arithmetic expression. The number of right and left parentheses () must not exceed 250.
The format of any data item involved in computations (for example, an addend, a subtrahend, or a multiplier) cannot contain editing symbols. Operational signs and implied decimal points are not considered to be editing symbols.
Identifiers which are used only to receive the result of an arithmetic statement (for example, the identifier used with the GIVING phrase) may be numeric-edited items (see section "GIVING phrase").
Condition-names cannot appear as operands.
General rules
The operands need not have the same data description; any necessary conversion and decimal point alignment is supplied throughout the calculation (see "Rules for numeric moves" on MOVE statement ).
If the sending or receiving items of an arithmetic statement, or of an INSPECT, MOVE, SET, STRING or UNSTRING statement, share the same storage area (that is, if the operands overlap), the result of the execution of such a statement is undefined.
The results are also undefined if the identifiers contain any data other than numeric data at object time.
If the input operands for an arithmetic statement do not contain valid numeric data, a data error will occur at program runtime.
The following rules apply to evaluation of exponentiation in an arithmetic expression:
If the value of an expression to be raised to a power is zero, the exponent must have a value greater than zero. Otherwise, the size error condition exists.
If the evaluation yields both a positive and a negative real number, the value returned as the result is the positive number.
If no real number exists as the result of the evaluation, the size error condition exists.
In evaluating arithmetic statements, the compiler generates a number of arithmetic operations. Depending on the relationship between the various operands, the compiler will generate one or more intermediate result items. These intermediate result items are retained until required for solving the final result of that statement.
Table 25 shows the number of the integer and decimal digits which are stored in the result item according to the operation executed. From this table, it is possible to determine the optimum operand size for the desired precision to be achieved in the statement. On the basis of the decimal places contained in each operand, and by reference to the formulae supplied in the table, the programmer may determine the exact number of positions which the compiler will make available to the result item. However, the result placed in the result item is aligned on the decimal point. Hence decimal point alignment is likewise important in determining the precision of the result.
If one of the operands has the data format COMPUTATIONAL or COMPUTATIONAL-5, then special rules apply that cannot be shown in table 25.
Statement
typeOperation
Decimal places
in intermediate result (d)Integer places
in intermediate result (i)Arithmetic
Addition or
subtraction (+) or (-
)MAX (Ad, Bd)
MAX (Ai+1, Bi+1)
Multiplication (
*
)Ad+Bd
Ai+Bi
Division (/)
MAX (Fd+1, Ad)
Ai+Bd
IF or
PERFORMAddition or
subtraction (+) or (-
)MAX (Ad, Bd)
MAX(Ai+1, Bi+1)
Multiplication(
*
)Ad+Bd
Ai+Bi
Division (/)
Ad
Ai+Bd
Table 25: Calculating the integer and decimal places in intermediate results
i
= Calculated integer places
Ai
= Integer places in first operand
Bi
= Integer places in second operand
d
= Calculated decimal places
Ad
= Decimal places in first operand
Bd
= Decimal places in second operand
Fd
= Decimal places in final result
MAX
= The greater value of the specified operands in each case
If the result item (i+d) contains more than 31 places then floating point arithmetic is generally used to perform the calculation.
The following are also performed using floating point arithmetic
Potentiation
Divisions specified in the arguments of internal standard functions