Handling Numeric Data
2.5 Evaluating Numeric Items
The length of the literal or arithmetic expression operands (in terms of the
number of digits represented) is not significant. Zero is a unique value, regardless
of the sign.
Unsigned numeric operands are assumed to be positive for comparison. The
results of relation tests involving invalid (nonnumeric) data in a numeric item are
undefined.
2.5.2 Numeric Sign Test
The sign test compares a numeric quantity to zero and determines if it is greater
than (positive), less than (negative), or equal to zero. Both the relation test and
the sign test can perform this function. For example, consider the following
relation test:
IF FIELD1 > 0 ...
Now consider the following sign test:
IF FIELD1 POSITIVE ...
Both of these tests accomplish the same thing and always arrive at the same
result. The sign test, however, shortens the statement and makes it more obvious
that the sign is being tested.
Table 2–2 shows the sign tests and their equivalent relation tests.
Table 2–2 Sign Tests
Sign Test
Equivalent Relation Test
IF FIELD1 POSITIVE ...
IF FIELD1 > 0 ...
IF FIELD1 NOT POSITIVE ...
IF FIELD1 NOT > 0 ...
IF FIELD1 NEGATIVE ...
IF FIELD1 < 0 ...
IF FIELD1 NOT NEGATIVE ...
IF FIELD1 NOT < 0 ...
IF FIELD1 ZERO ...
IF FIELD1 = 0 ...
IF FIELD1 NOT ZERO ...
IF FIELD1 NOT = 0 ...
Sign tests do not execute faster or slower than relation tests because the compiler
substitutes the equivalent relation test for every correctly written sign test.
2.5.3 Numeric Class Tests
The class test inspects an item to determine if it contains numeric or alphabetic
data. For example, the following statement determines if FIELD1 contains
numeric data:
IF FIELD1 IS NUMERIC ...
If the item is numeric, the test condition is true, and program control takes the
true path of the statement.
Both relation and sign tests determine only if an item’s contents are within a
certain range. Therefore, certain items in newly prepared data can pass both the
relation and sign tests and still contain data preparation errors.
The NUMERIC class test checks alphanumeric or numeric DISPLAY or COMP-3
usage items for valid numeric digits. If the item being tested contains a sign
(whether carried as an overpunched character or as a separate character), the
test checks it for a valid sign value. If the character position carrying the sign
2–4 Handling Numeric Data
Содержание COBOL AAQ2G1FTK
Страница 22: ......
Страница 30: ......
Страница 94: ......
Страница 110: ......
Страница 146: ......
Страница 180: ......
Страница 194: ...Processing Files and Records 6 1 Defi...
Страница 300: ......
Страница 490: ......
Страница 516: ......
Страница 517: ......
Страница 530: ......
Страница 534: ......
Страница 590: ......
Страница 620: ......