gnucobol-users
[Top][All Lists]
Advanced

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

[open-cobol-list] Cobol division


From: David Korn
Subject: [open-cobol-list] Cobol division
Date: Mon Feb 28 19:04:15 2005

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).

The details of when integer division is used, is defined in
http://publib.boulder.ibm.com/infocenter/pdthelp/index.jsp?topic=/com.ibm.debugtool5.doc/eqa5rm0191.htm

by looking for fixed-point vs floating point.

To implement this the cob_decimal_div() function should take an
extra argument which will be either 0 or 1 for fixed/float.
The code generator would then have to look at the expression
to decide which one to generate.

In this case since all the operands are integers, (on both sides
of the comparison), integer arithmetic should be used.

David Korn
address@hidden


reply via email to

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