[an error occurred while processing this directive]

HP OpenVMS Systems Documentation

Content starts here

HP COBOL
Reference Manual


Previous Contents Index

6.4.4 Native 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 those described in Section 6.4.4.1.

When native arithmetic is in effect, the following rules apply:

  1. If the result of an arithmetic expression can be represented without loss of significance in 38 decimal digits or less, then decimal or computational operations are used to evaluate the expression.
  2. When it is possible for an expression to produce more than 38 decimal digits, an intermediate data item is selected based on the MATH_INTERMEDIATE qualifier.

The compiler assumes that all possible digit positions of a variable are significant.

6.4.4.1 FLOAT Arithmetic (Alpha, I64)

A double-precision binary floating-point intermediate data item is selected when /MATH_INTERMEDIATE=FLOAT is specified. On OpenVMS Alpha and I64 this is a G_floating or T_floating data item; on Tru64 UNIX, this is a T_floating data item. Refer to the Alpha Architecture Reference Manual for more information on floating-point data types and operations.

A G_floating data item has a sign bit, an 11-bit binary exponent, and a normalized 53-bit fraction with the redundant most significant fraction bit not represented. The magnitude of a G_floating data item is in the approximate range 0.56 * 10**-308 through 0.9 * 10**308. The precision of a G_floating data item is approximately one part in 2**52, typically 15 decimal digits.

A T_floating data item has a sign bit, an 11-bit binary exponent, and a 52-bit fraction. HP COBOL generates code that uses the finite, normalized, floating-point range capabilities of T_floating. The magnitude of a T_floating data item is in the approximate range 2.2 * 10**-308 through 1.8 * 10**308. The precision of a T_floating data item is approximately one part in 2**52, typically 15 decimal digits.

When the destination of an arithmetic statement is a floating-point data item, normal rounding takes place.

When an arithmetic expression references a floating-point operand, floating-point operations are used to evaluate the expression, and the result is represented in a floating-point intermediate data item. Floating-point operations use normal rounding; implicit conversions to integer are chopped. HP COBOL provides support for finite (normalized) floating-point values only.

When arithmetic expressions using addition, subtraction, multiplication, division, exponentiation, unary plus, and unary minus are evaluated, the exact result is truncated to 53 significant bits, normalized, and stored in a floating-point intermediate data item.

6.4.4.2 CIT3 Arithmetic (Alpha, I64)

A decimal floating-point intermediate data item is selected when the qualifier /MATH_INTERMEDIATE=CIT3 is specified.

A CIT3 intermediate data item has the unique value of zero or a value whose magnitude is in the range 10**-100 through 10**99 - 10**81, that is, (.100 000 000 000 000 000E-99) through (.999 999 999 999 999 999E+99)4 inclusive, with a precision of 18 decimal digits.

When a CIT3 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 the ROUNDED phrase is not present, no rounding takes place.

When arithmetic expressions addition, subtraction, multiplication, division, exponentiation, unary plus, and unary minus are evaluated, the exact result is truncated to 18 significant digits, normalized, and stored in a CIT3 intermediate data item.

6.4.4.3 CIT4 Arithmetic (Alpha, I64)

A decimal floating-point intermediate data item is selected when /MATH_INTERMEDIATE=CIT4 is specified.

A CIT4 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)1 inclusive, with a precision of 32 decimal digits.

Rounding rules for CIT4 arithmetic are the same as those described in Section 6.4.3.

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 CIT4 intermediate data item. <>

Note

4 The blanks are added for readability.

6.5 Conditional Expressions

A conditional expression specifies a condition the program must evaluate to determine the path of program flow. If the condition is true, the program takes one path; if it is false, the program takes another path. The IF, EVALUATE, PERFORM UNTIL, PERFORM VARYING, and SEARCH statements use conditional expressions. Any statement that can contain another imperative statement can contain a conditional expression.

A conditional expression can be either a simple or a complex condition. The types of simple conditions are the relation, class, condition-name, switch-status, sign, and success/failure conditions. Complex conditions are formed by using logical operators (AND, OR, NOT) with simple conditions. You can enclose conditions within any number of paired parentheses. However, embedding conditions this way has no effect on whether they are considered simple or complex.

6.5.1 Relation Conditions

A relation condition states a relation between two operands. The program compares the operands to determine whether the stated relation is true or false. The first operand is called the condition's subject. The second operand is called its object. Either operand can be an identifier, a literal, or the value of an arithmetic expression. The set of words that specifies the type of comparison is called the relational operator.

The format for a relation condition is as follows:


You can compare two numeric operands regardless of their USAGE. However, if one or both of the operands are not numeric, they must have the same USAGE. If either operand is a group item, then the comparison is treated as nonnumeric, since group items are always considered alphanumeric.

You must refer to at least one variable in a relation condition; you cannot refer only to literals.

A space must precede and follow each word in the relational operator. However, NOT and the key word or relation character that follows NOT are treated as a unit.

The following relational operators are equivalent:

  • IS NOT GREATER THAN is equivalent to IS LESS THAN OR EQUAL TO
  • IS NOT LESS THAN is equivalent to IS GREATER THAN OR EQUAL TO

Table 6-3 specifies valid true conditions that correspond to each relational operator.

Table 6-3 Relational Operators and Corresponding True Conditions
Relational Operator True Condition
IS GREATER THAN
IS > THAN
Subject is greater than object.
IS NOT GREATER THAN
IS NOT > THAN
Subject is either less than or equal to object.
IS LESS THAN
IS < THAN
Subject is less than object.
IS NOT LESS THAN
IS NOT < THAN
Subject is either greater than or equal to object.
IS EQUAL TO
IS = TO
Subject is equal to object.
IS NOT EQUAL TO
IS NOT = TO
Subject is either greater than or less than object.
IS GREATER THAN OR EQUAL TO
IS >=
Subject is greater than or equal to object.
IS LESS THAN OR EQUAL TO
IS <=
Subject is less than or equal to object.

The following two sections specify the rules that apply to numeric and nonnumeric comparisons in relation conditions.


Previous Next Contents Index