Home > Archive > Cobol > July 2004 > IF NUMERIC - 2002 Standard (was: In answer to RW - again (was: Sorts (revised)
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
IF NUMERIC - 2002 Standard (was: In answer to RW - again (was: Sorts (revised)
|
|
| William M. Klein 2004-07-13, 3:55 pm |
|
"Robert Wagner" <robert.deletethis@wagner.net> wrote in message
news:40f39e89.131187942@news.optonline.net...
> "Chuck Stevens" <charles.stevens@unisys.com> wrote:
>
<snip>
>
>
> That must be about packed decimal. Everything is valid in binary.
>
Not true.
The 2002 Standard *defines* the IF NUMERIC class test against a BINARY (or
COMPUTATIONAL - or PACKED-DECIMAL) field as *only* passing when the data
*matches* the PICTURE (and usage). Therefore, an IF NUMERIC class test against
a BINARY-CHAR (new USAGE) field will (always?) pass as any bit combination
matches the USAGE (and there is NO picture clause), for a
02 Num-Field Pic S99 Binary.
field if it as an "algebraic" (using the term loosely) value of 100 - even if it
"fits" in the field, it would FAIL an IF NUMERIC class test.
Personally, I was never certain this was the right way for the definition to be
made, but it IS what the Standard says. Of course any compiler that supports a
"NOTRUNC" compiler option (as most? many? do) is already running in NON-Standard
mode - and can do whatever it wants with the "new" IF NUMERIC class test in that
environment. It only needs to "match" the Standard when "standard conforming"
options are in effect.
--
Bill Klein
wmklein <at> ix.netcom.com
| |
| Robert Wagner 2004-07-13, 3:55 pm |
| "William M. Klein" <wmklein@nospam.netcom.com> wrote:
>The 2002 Standard *defines* the IF NUMERIC class test against a BINARY (or
>COMPUTATIONAL - or PACKED-DECIMAL) field as *only* passing when the data
>*matches* the PICTURE (and usage). Therefore, an IF NUMERIC class test
against
>a BINARY-CHAR (new USAGE) field will (always?) pass as any bit combination
>matches the USAGE (and there is NO picture clause), for a
> 02 Num-Field Pic S99 Binary.
>
>field if it as an "algebraic" (using the term loosely) value of 100 - even if
it
>"fits" in the field, it would FAIL an IF NUMERIC class test.
Can a conforming program compare Num-Field to an out-of-range value?
If Num-Field less than 100 and greater than -100
Perform Good-Number
End-If
Would an optimizer discard the following condition and make the Perform
unconditional?
If Num-Field not greater than 99 and not less than -99
Perform Good-Number
End-If
| |
| William M. Klein 2004-07-13, 3:55 pm |
| A conforming compiler must allow the comparisons; it could (but is not required
to) allow its optimizer to make the loop unconditional WHEN running in "Standard
conforming mode". (Again, many/most compilers have a NOTRUNC - or equivalent
option for which these statements are NOT true).
FYI,
Also of semi-relevance are the new
HIGHEST-ALGEBRAIC
and
LOWEST-ALGEBRAIC
intrinsic functions which you may want to look at in the 2002 Standard.
--
Bill Klein
wmklein <at> ix.netcom.com
"Robert Wagner" <robert.deletethis@wagner.net> wrote in message
news:40f40a02.158705113@news.optonline.net...
> "William M. Klein" <wmklein@nospam.netcom.com> wrote:
>
> against
> it
>
> Can a conforming program compare Num-Field to an out-of-range value?
>
> If Num-Field less than 100 and greater than -100
> Perform Good-Number
> End-If
>
> Would an optimizer discard the following condition and make the Perform
> unconditional?
>
> If Num-Field not greater than 99 and not less than -99
> Perform Good-Number
> End-If
|
|
|
|
|