COBOL Manual for TNS/E Programs (H06.03+)

Procedure Division
HP COBOL Manual for TNS/E Programs520347-003
8-49
Arithmetic Precision
Arithmetic Precision
The precision of ADD, SUBTRACT, MULTIPLY, and DIVIDE statements can be fairly
easily stated. The precision of arithmetic expressions is substantially more complex,
because the compiler must create intermediate data items as it evaluates the
expression. Arithmetic expressions occur only in the COMPUTE, ENTER, and
EVALUATE statements, the relation and sign conditions, function arguments, and in
reference modification.
In discussing precision, we ignore the presence of a scale factor or of any decimal
point; the arithmetic processing records and handles these elements separately. After
the computation is performed with integral values, the decimal point and scale factor (if
any) are then provided for the result.
The largest value HP COBOL can store is the unsigned COMPUTATIONAL-5 value
18,446,744,073,709,551,615.
The largest value HP COBOL can store associated with a DISPLAY or
COMPUTATIONAL data item (independent of any decimal point or scale factor) is the
20-digit number which is the highest value for an unsigned 64-bit number.
In evaluating arithmetic expressions, COBOL can manipulate intermediate values
having up to 128 bits (about 39 digits).
These topics explain arithmetic precision as it applies to:
SIZE ERROR
ADD and SUBTRACT Statements
MULTIPLY Statement
DIVIDE Statement
Arithmetic Expressions
SIZE ERROR
As explained in SIZE ERROR Phrase, the size error condition indicates a problem in
computation. It arises when an arithmetic overflow occurs or when a program attempts
to divide by zero, raise zero to the zero power, or raise a negative number to a power
that produces other than a real number value. If no SIZE ERROR clause is present in
the statement where the condition arises, the process can terminate abnormally with
an arithmetic overflow or it can store invalid values into result items (mainly in items of
USAGE COMPUTATIONAL).