[an error occurred while processing this directive]
HP OpenVMS Systems Documentation |
HP COBOL
|
Previous | Contents | Index |
An explicit attribute is an attribute the program explicitly specifies. If the program does not explicitly specify an attribute, the attribute assumes a default; it is then an implicit attribute.
For example, a program need not specify USAGE for a data item. If it
does not, the data item's implicit usage is DISPLAY.
6.3.4 Explicit and Implicit Scope Terminators
Scope terminators delimit the scope of some Procedure Division statements as described in Section 6.1.4.
The following are explicit scope terminators:
END-ACCEPT | END-ADD | END-CALL |
END-COMPUTE | END-DELETE | END-DIVIDE |
END-EVALUATE | END-IF | END-MULTIPLY |
END-PERFORM | END-READ | END-RETURN |
END-REWRITE | END-SEARCH | END-START |
END-STRING | END-SUBTRACT | END-UNSTRING |
END-WRITE |
The following are implicit scope terminators:
Whenever the term arithmetic expression appears in Procedure Division rules, it refers to one of the following:
A unary operator (a sign) can precede any arithmetic expression.
The identifiers and literals in an arithmetic expression must represent either of the following:
Evaluation rules for arithmetic expressions depend on whether the mode
of arithmetic in effect is native or standard.
6.4.1 Arithmetic Operators
Arithmetic expressions can use five binary and two unary arithmetic operators. A space must precede each operator and follow each binary operator.
The operators are as follows:
Binary Arithmetic Operator | Meaning |
---|---|
+ | Addition |
- | Subtraction |
* | Multiplication |
/ | Division |
** | Exponentiation |
Unary Arithmetic Operator | Meaning |
+ | The effect of multiplication by +1 |
- | The effect of multiplication by -1 |
The following rules apply regardless of the mode of arithmetic that is in effect.
Parentheses can be used to specify the order in which elements in an arithmetic expression are evaluated. Expressions within parentheses are evaluated first. If you nest sets of parentheses, evaluation starts with the innermost set of parentheses and proceeds to the outermost set.
If the arithmetic expression contains no parentheses, the compiler evaluates arithmetic operators in the following hierarchical order:
First | Unary plus and minus |
Second | Exponentiation |
Third | Multiplication and division |
Fourth | Addition and subtraction |
This order also applies within a single set of parentheses.
If two or more operators are at the same hierarchical level, and parentheses do not specify the sequence of operations, evaluation proceeds from left to right.
Parentheses can eliminate ambiguities in logic when there are consecutive operations at the same hierarchical level, or change the normal hierarchical sequence of evaluation.
Consider the following expression:
(3 * ITEMA - 2) / ((4 + ITEMB) * -ITEMA - ITEMC ** 2) |
The order of evaluation is as follows:
Each left parenthesis in an arithmetic expression must have a matching right parenthesis, and each right parenthesis must have a matching left parenthesis.
If the first operator in an arithmetic expression is a unary operator, a left parenthesis (() must immediately precede it when the arithmetic expression immediately follows an identifier or another arithmetic expression. For example:
CALL "OTHERPROG" USING ITEMA (-ITEMB) ITEMC. |
The following rules apply to the evaluation of exponentiation:
If the evaluation of the arithmetic expression results in an attempted division by zero, the size error condition exists.
When a statement with an arithmetic expression does not refer to a
resultant identifier, the compiler stores the results of the arithmetic
expression in an intermediate data item. (See Section 6.6.1.)
6.4.3 Standard Arithmetic (Alpha, I64)
When a floating-point data item is an operand in an arithmetic expression or an arithmetic statement, the rules for evaluation are described in Section 6.4.4.1.1
When standard arithmetic is in effect, the following rules apply:
A standard intermediate data item is of the class numeric and the category numeric. It is the unique value zero or an abstract, signed, normalized decimal floating-point temporary data item.
A standard intermediate data item has the unique value of zero or a value whose magnitude is in the range 10**-100 through 10**99 - 10**67, that is, (.100 000 000 000 000 000 000 000 000 000 00E-99) through (.999 999 999 999 999 999 999 999 999 999 99E+99)2 inclusive, with a precision of 32 decimal digits.
When the value of a standard intermediate data item is not zero, the fraction contains no digits to the left of the decimal point and contains a digit other than zero to the immediate right of the decimal point.
A standard intermediate data item is rounded to 31 digits in the situations listed below.
When a standard intermediate data item is being moved to a resultant-identifier for which the ROUNDED phrase is specified, the number of digits to which rounding occurs is as specified in the ROUNDED phrase.
When arithmetic expressions using addition, subtraction, multiplication, division, exponentiation, unary plus, and unary minus are evaluated, the exact result is truncated to 32 significant digits, normalized, and stored in a standard intermediate data item.
1 A floating-point data item has one of these usages: COMP-1, COMP-2, FLOAT-SHORT, FLOAT-LONG, or FLOAT-EXTENDED.2 The blanks are added for readability.3 These rules are intended to eliminate excessive rounding and to ensure that rounding occurs once at the end of the evaluation of nested arithmetic expressions. |
Previous | Next | Contents | Index |