Arithmetic expressions

Arithmetic expressions are used as operands of certain conditional and arithmetic statements.

An arithmetic expression can consist of any of the following items:

  1. An identifier described as a numeric elementary item (including numeric functions)
  2. A numeric literal
  3. The figurative constant ZERO
  4. Identifiers and literals, as defined in items 1, 2, and 3, separated by arithmetic operators
  5. Two arithmetic expressions, as defined in items 1, 2, 3, or 4, separated by an arithmetic operator
  6. An arithmetic expression, as defined in items 1, 2, 3, 4, or 5, enclosed in parentheses

Any arithmetic expression can be preceded by a unary operator.

Identifiers and literals that appear in arithmetic expressions must represent either numeric elementary items or numeric literals on which arithmetic can be performed.

If an exponential expression is evaluated as both a positive and a negative number, the result is always the positive number. For example, the square root of 4:


4 ** 0.5

is evaluated as +2 and -2. Enterprise COBOL always returns +2.

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. In any case where no real number exists as the result of an evaluation, the size error condition exists.