Using math-oriented callable services
Most COBOL intrinsic functions have corresponding math-oriented callable services that you can use to produce the same results.
When you compile with the default option ARITH(COMPAT)
,
COBOL floating-point intrinsic functions return long (64-bit) results.
When you compile with option ARITH(EXTEND)
, COBOL
floating-point intrinsic functions (with the exception of RANDOM
)
return extended-precision (128-bit) results.
For example (considering
the first row of the table below), if you compile using ARITH(COMPAT)
,
CEESDACS returns the same result as ACOS
. If you
compile using ARITH(EXTEND)
, CEESQACS returns the
same result as ACOS
.
COBOL intrinsic function | Corresponding long-precision Language Environment® callable service | Corresponding extended-precision Language Environment callable service | Results same for intrinsic function and callable service? |
---|---|---|---|
ACOS |
CEESDACS | CEESQACS | Yes |
ASIN |
CEESDASN | CEESQASN | Yes |
ATAN |
CEESDATN | CEESQATN | Yes |
COS |
CEESDCOS | CEESQCOS | Yes |
![]() E ![]() |
![]() ![]() |
![]() ![]() |
![]() ![]() |
![]() EXP ![]() |
![]() ![]() |
![]() ![]() |
![]() ![]() |
![]() EXP10 ![]() |
![]() ![]() |
![]() ![]() |
![]() ![]() |
LOG |
CEESDLOG | CEESQLOG | Yes |
LOG10 |
CEESDLG1 | CEESQLG1 | Yes |
RANDOM 1 |
CEERAN0 | none | No |
REM |
CEESDMOD | CEESQMOD | Yes |
SIN |
CEESDSIN | CEESQSIN | Yes |
SQRT |
CEESDSQT | CEESQSQT | Yes |
TAN |
CEESDTAN | CEESQTAN | Yes |
|
Both
the RANDOM
intrinsic function and CEERAN0 service
generate random numbers between zero and one. However, because each
uses its own algorithm, RANDOM
and CEERAN0 produce
different random numbers from the same seed.
Even
for functions that produce the same results, how you use intrinsic
functions and Language Environment callable
services differs. The rules for the data types required for intrinsic
function arguments are less restrictive. For numeric intrinsic functions,
you can use arguments that are of any numeric data type. When you
invoke a Language Environment callable service
with a CALL
statement, however, you must ensure that
the parameters match the numeric data types (generally COMP-1
or COMP-2
)
required by that service.
The error handling of intrinsic functions
and Language Environment callable services
sometimes differs. If you pass an explicit feedback token when calling
the Language Environment math services, you
must check the feedback code after each call and take explicit action
to deal with errors. However, if you call with the feedback token
explicitly OMITTED
, you do not need to check the
token; Language Environment automatically signals
any errors.
Fixed-point contrasted with floating-point arithmetic
Intermediate results and arithmetic precision