IBM Extension
IBM Extension

Floating-Point Data and Intermediate Results

Floating-point instructions are used to compute an arithmetic expression if any of the following conditions are true:
  • A receiver or operand in the expression is COMP-1, COMP-2, external floating-point data, or a floating-point literal.
  • An intrinsic numeric function is a floating-point function.
  • The expression is an argument of a floating-point function.

If any operation in an arithmetic expression is computed in floating-point, the entire expression is computed as if all operands were converted to floating-point and the operations are evaluated using floating-point instructions.

If an expression is computed in floating-point, double-precision floating-point is used if any receiver or operand in the expression is not COMP-1, or if a multiplication or exponentiation operation appears in the expression. Whenever double-precision floating-point is used for one operation in an arithmetic expression, all operations in the expression are computed as if double-precision floating-point instructions were used.

Floating-point exponentiations are always evaluated using double-precision floating-point arithmetic.

The value of a negative number raised to a fractional power is undefined. For example, (-2) ** 3 is equal to -8, but (-2) ** (3.000001) is not defined. When an exponentiation is evaluated in floating-point and there is a possibility that the value of the exponentiation will be undefined (as in the example above), then the value of the exponent is evaluated at run time to determine if it is actually an integer.

The floating-point numeric functions will always return a double-precision floating-point value. For a list of the floating-point and fixed-point functions, see "Types of Numeric Functions" in the IBM® Rational® Development Studio for i: ILE COBOL Programmer's Guide.

Arithmetic expressions can appear in contexts other than arithmetic statements. For example, an arithmetic expression can be used with the IF statement. In such statements, the rules for intermediate results, floating-point, and double-precision floating-point apply, with the following changes:
  • Abbreviated IF statements are handled as though the statements were not abbreviated.
  • An explicit relation condition exists when a required relational operator is used to define the comparison between two operands (here referred to as comparands). In an explicit relation condition where one or both of the comparands is an arithmetic expression, the rules for intermediate results are determined by taking into consideration the attributes of both comparands. That is to say, dmax is defined to be the maximum number of decimal places defined for any operand of either comparand, except divisors and exponents. The rules for floating-point and double-precision floating-point apply if any operand in either comparand is COMP-1, COMP-2, external floating-point data, or a floating-point literal.
    For example, in the statement:
      IF operand-1 = expression-1 THEN . . .
    where operand-1 is a data-name defined to be COMP-2, and expression-1 contains only fixed-point operands, the rules for floating-point arithmetic apply to expression-1 because it is being compared to a floating-point operand.
  • When the comparison between an arithmetic expression and either a data item or another arithmetic expression is defined without using a relational operator, then no explicit relation condition is said to exist. In these cases, the comparison can be rewritten as one or more IF statements with an explicit operator. Each IF statement then follows the rules outlined above for an explicit relation condition. For example, in the statement:
EVALUATE expression-1
  WHEN expression-2 THRU expression-3
  WHEN expression-4
  .
  .
  .
END-EVALUATE
the equivalent IF statements are:
IF expression-1 >= expression-2 AND
   expression-1 <= expression-3
IF expression-1 = expression-4
   then for each IF statement, the comparands must be looked at
   to determine if all the arithmetic in that IF statement will
   be fixed-point or floating-point.
End of IBM Extension
End of IBM Extension