Using COMPUTE and other arithmetic statements
Use the COMPUTE
statement for most arithmetic
evaluations rather than ADD
, SUBTRACT
, MULTIPLY
,
and DIVIDE
statements. Often you can code only one COMPUTE
statement
instead of several individual arithmetic statements.
About this task
The COMPUTE
statement assigns the result
of an arithmetic expression to one or more data items:
Compute z = a + b / c ** d - e
Compute x y z = a + b / c ** d - e
Some
arithmetic calculations might be more intuitive using arithmetic statements
other than COMPUTE
. For example:
COMPUTE |
Equivalent arithmetic statements |
---|---|
|
|
|
|
|
|
You might also prefer to use the DIVIDE
statement
(with its REMAINDER
phrase) for division in which
you want to process a remainder. The REM
intrinsic
function also provides the ability to process a remainder.
When you perform arithmetic calculations, you can use national decimal data items as operands just as you use zoned decimal data items. You can also use national floating-point data items as operands just as you use display floating-point operands.
Fixed-point contrasted with floating-point arithmetic
Intermediate results and arithmetic precision