Compaq COBOL AAQ2G1FTK User Manual

Page 106

Advertising
background image

Handling Numeric Data
2.7 Using the Arithmetic Statements

Arithmetic expressions in nonarithmetic statements are also affected.
Nonarithmetic statements, such as the IF statement, allow arithmetic expressions
to be used, but do not provide a mechanism like the ON SIZE ERROR phrase to
detect errors in evaluation. If such an error occurs, the behavior of the statement
is unpredictable; in the case of an IF statement, result of the comparison is
undefined.

Similar considerations apply in other contexts, such as the use of arithmetic
expressions as subscript expressions or reference-modification components.

2.7.2.2 Using the /ARITHMETIC Qualifier

You can specify /ARITHMETIC=NATIVE or STANDARD (

-arithmetic native

or

standard

) on the COBOL command line to control whether native arithmetic

or standard arithmetic is used to evaluate arithmetic operations and statements.
These options have the following effects:

NATIVE

Arithmetic operations will produce results that are reasonably compatible
with releases for Compaq COBOL for OpenVMS Alpha prior to Version 2.7
and also with Compaq COBOL for OpenVMS VAX.

STANDARD

Most common arithmetic operations will produce results that are
predictable, reasonable, and portable. In this context, portable means
that the results will be identical from implementation to implementation.
/ARITHMETIC=STANDARD forces /MATH_INTERMEDIATE=CIT4
(described in Section 2.7.2.1).

The default is /ARITHMETIC=NATIVE (

-arithmetic native

).

Using the OPTIONS Paragraph

An alternative way to specify native or standard arithmetic is to use the
OPTIONS paragraph in the Identification Division of your Compaq COBOL
program. There you can specify ARITHMETIC IS NATIVE or STANDARD. See
the Compaq COBOL Reference Manual for the syntax and details.

2.7.3 Specifying a Truncation Qualifier

The

-trunc

flag (on Tru64 UNIX) or the /[NO]TRUNCATE qualifier (on

OpenVMS Alpha) specifies how the Compaq COBOL compiler stores values
in COMPUTATIONAL receiving items.

By default (assuming that the

-trunc

flag is turned off, or /NOTRUNCATE is

set), Compaq COBOL truncates values according to the Alpha hardware storage
unit (word, longword, or quadword) allocated to the receiving item.

If you specify

-trunc

or /TRUNCATE the compiler truncates values according to

the number of decimal digits specified by the PICTURE clause.

2.7.4 Using the ROUNDED Phrase

Rounding is an important option that you can use with arithmetic operations.

You can use the ROUNDED phrase with any Compaq COBOL arithmetic
statement. Rounding takes place only when the ROUNDED phrase requests it,
and then only if the intermediate result has low-order digits that cannot be stored
in the result.

Compaq COBOL rounds off by adding a 5 to the leftmost truncated digit of the
absolute value of the intermediate result before it stores that result.

2–12 Handling Numeric Data

Advertising