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: David Korn
Subject: [open-cobol-list] RE: Cobol division
Date: Thu Mar 17 07:20:18 2005

This issue was never fully resolved.  As Bill Klein pointed out,
the behavior of division depends on which compiler is being
emulated.  Howeever,  I am running code with IBM
compiler for OS/390 and I am getting different results in
some cases.

For this compiler, integer division is used when all operands
are integers and the result is stored in an integer or
compared to an integer.

I modified the cob_decimal_div() function so that if
the decimal scale field is zero for both operands, then integer
division is performed.   This fixed some problems, but is
not correct for
        divide int by int giving float
but works for
        divide int by int giving int
and
        int *( int / int) = int

What I think is needed is that another field be added to cob_decimal.
This field with be 0 for integer and 1 for float.

The cob_decimal_set_field() would set this field to 1 if the scale
was non-zero.
In addition, it would be carried through arithmetic operations.
Finally, when generating code, the  field for cob_decimal_get_field
would have to be examined.  For example,

              /* FII2AI20.cob:80393: DIVIDE */
              {
                {
                  {
                    cob_decimal_set_field (&d[0], (f[1] = (cob_field) {8, 
b_48899 + 365 + 8 * 0, &a_57291}, &f[1]));
                    cob_decimal_set_field (&d[1], (f[1] = (cob_field) {9, 
b_48899 + 266 + 9 * 0, &a_57289}, &f[1]));
                    cob_decimal_div (&d[0], &d[1]);
                    cob_decimal_get_field (&d[0], (f[1] = (cob_field) {8, 
b_48899 + 365 + 8 * 5, &a_57291}, &f[1]));
                  }
                }


Would have to do something like:

              /* FII2AI20.cob:80393: DIVIDE */
              {
                {
                  {
                    cob_decimal_set_field (&d[0], (f[1] = (cob_field) {8, b_4889
9 + 365 + 8 * 0, &a_57291}, &f[1]));
                    cob_decimal_set_field (&d[1], (f[1] = (cob_field) {9, b_4889
9 + 266 + 9 * 0, &a_57289}, &f[1]));
                    if(cob_isfloat(a_57291))
                        d[0].isfloat |=1;
                    cob_decimal_div (&d[0], &d[1]);
                    cob_decimal_get_field (&d[0], (f[1] = (cob_field) {8, b_4889
9 + 365 + 8 * 5, &a_57291}, &f[1]));
                  }
                }

Having this attribute will allow the rules for division to be
implemented inside cob_decimal_div() in a compiler specific way
since the information will be there.

Unfortunately, I am not that familiar with the code generation
portion of the compiler to know how to add this.  Any help
would surely be appreciated.



David Korn
address@hidden


reply via email to

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