Handling Numeric Data
2.7 Using the Arithmetic Statements
The default is /MATH_INTERMEDIATE=FLOAT (or
-math_intermediate float
).
If you specify /ARITHMETIC=STANDARD (discussed in Section 2.7.2.2), this will
force /MATH_INTERMEDIATE=CIT4.
Example of Different Arithmetic Results
The following example illustrates the different results that you can get with
FLOAT, CIT3, and CIT4:
IDENTIFICATION DIVISION.
PROGRAM-ID. MUL31.
DATA DIVISION.
WORKING-STORAGE SECTION.
01
XD PIC S9(31) VALUE 3.
01
YD PIC S9(31) VALUE 258718314234781388692555698765.
01
ZD PIC S9(31).
PROCEDURE DIVISION.
0.
MULTIPLY XD BY YD GIVING ZD
ON SIZE ERROR DISPLAY "Size error raised"
NOT ON SIZE ERROR DISPLAY ZD WITH CONVERSION.
The compiler relies on the number of digits implied by the pictures of decimal and
integer operands. Here it assumes that XD has 31 digits and YD has 31 digits.
The product could require 62 digits, which is larger than the largest fixed-point
arithmetic type available to the compiler. Depending on the intermediate data
type chosen, this program gets several different results.
Intermediate maintains
MATH
ZD
the most significant
-----
------------------------------
----------------------
FLOAT
776154942704344283789821739008
53 bits
CIT3
776154942704344164000000000000
18 digits
CIT4
776154942704344166077667096295
32 digits
Other Consequences of Intermediate Range Differences
Because each intermediate data type has a different maximum magnitude, an
arithmetic statement can raise the size error condition with one arithmetic mode
but not with another.
For example, the value +0.999 999 999 999 999 999E+99 (spaces added for
readability) is representable in any of the intermediate data types. By contrast,
the larger value +0.999 999 999 999 999 999 9E+99 cannot be represented in a
CIT3 intermediate data item. Such an operation would cause an overflow, raising
the size error condition. This value is representable, however, in a FLOAT or
CIT4 intermediate data item; the size error condition would not be raised.
The value 1.0E+99 cannot be represented in either CIT3 or CIT4 form, but is
representable in FLOAT form.
Similarly, because each intermediate data type has a different minimum
magnitude, an arithmetic statement can raise the size error condition for
underflow with one arithmetic mode but not another. (Underflow does not raise
the size error condition when FLOAT arithmetic is used.)
A literal also can be valid with one arithmetic mode but not with another,
resulting in different HIGHTRUNC and LOWTRUNC informational diagnostics.
When a literal cannot be represented in an intermediate data item, the value
used is undefined.
Handling Numeric Data 2–11
Содержание COBOL AAQ2G1FTK
Страница 22: ......
Страница 30: ......
Страница 94: ......
Страница 110: ......
Страница 146: ......
Страница 180: ......
Страница 194: ...Processing Files and Records 6 1 Defi...
Страница 300: ......
Страница 490: ......
Страница 516: ......
Страница 517: ......
Страница 530: ......
Страница 534: ......
Страница 590: ......
Страница 620: ......