gnucobol-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[open-cobol-list] RE: Cobol division


From: Bill Klein
Subject: [open-cobol-list] RE: Cobol division
Date: Wed Mar 2 11:53:37 2005

All "arithmetic expressions" (things to the right of the "=" in a compute -
among other things) are TOTALLY implementor defined.

Micro Focus - in its usual "all thing to all people" approach provides an
   ARITHMETIC
directive.  Currently (SeverExpress 4.0) it has the following options:

 ENTCOBOL 
        Truncate according to the rules of Enterprise COBOL for z/OS and
OS/390.  
 MF 
        Do not truncate intermediate results. With ARITHMETIC"MF" specified,
expressions are calculated as accurately as possible because no truncation
takes place. 
 OS390 
        Truncate according to the rules of COBOL for OS/390.  
 OSVS 
        Truncate according to the rules of OS/VS COBOL.  
 TRUNC20 
        Truncate the number of digits to the right of the decimal point to
20 at each step of the evaluation of the expression. This provides similar
results to the truncation provided in COBOL Workbench. You should only use
this directive if you need to obtain evaluation results similar to those
provided in COBOL Workbench. If you specify TRUNC20, you must not change the
setting of the INTLEVEL Compiler directive from its default value of 2. This
means that you cannot use some of the newer features, such as numeric
pictures with more than 18 total digits, with the TRUNC20 parameter. 
 VSC2 
        Truncate according to the rules of VS COBOL II and COBOL/370. 

***
  If you are TRYING to emulate an IBM compiler, you need to find out WHICH
compiler as the rules have changed over the years (and releases).

The most current definition for is at:
 
http://publibz.boulder.ibm.com/cgi-bin/bookmgr_OS390/BOOKS/igy3pg20/APPENDIX
1.1 

Doing ALL of this is quite a challenge.  On the other hand, I know that IBM
mainframers DO expect to get "same results" NOT "best results" for
arithmetic operations.

NOTE:
  The other arithmetic statements (Add, Subtract, Multiply, and Divide) DO
have more precise rules.  Unfortunately, there is an ERROR in DIVIDE that is
only fixed in the '02 Standard - when mixing signed and unsigned operands
(See '02 Substantive changes for details).  MOST (not all) '85 Standard
compilers use "reasonable" rules available in the '02 Standard.

P.S.  As far as "composite of operands" goes, see page 121 of the '02
Standard (and this has ALWAYS been true)

"Arithmetic expressions allow the user to combine arithmetic operations
without the restrictions on composite of operands and receiving data items."

> -----Original Message-----
> From: Roger While [mailto:address@hidden 
> Sent: Wednesday, March 02, 2005 1:47 AM
> To: address@hidden
> Cc: address@hidden; 
> address@hidden; address@hidden
> Subject: Re: Cobol division
> 
> Bill, care to comment on this ?
> Here's what I have found out so far -
> OC, MF and ACU all produce the same results for this.
>  From the 2002 standard 14.6.6 Arithmetic statements :
> ...
> The composite of operends is a hypothetical data item resulting
> from the superimposition of specified operands aligned on their
> decimal points.
> ....
> Because of the division, this would imply 2 decimal places. (Bill ?)
> So, I would say say we are doing the correct thing.
> 
> Roger
> 
>  > The IBM MVS compiler has some rules to decide when to use
>  > integer division and when to use floating point division.
>  > OpenCobol only seems to support floating point division.
>  > With the MVS Cobol compiler
>  >    IF      100*(X/100) = X
>  >    THEN    DISPLAY 'X=' X
>  >    END-IF
>  > will only output X when X is a multiple of 100 because it
>  > does integer division for X/100.
>  > Note that
>  >    COMPUTE  Y = 100*(X/100)
>  > will give different values depending on whether Y is declared
>  > as  S9(9) or S9(9)V9(2).
> 
> 
> 
> 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]