[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[open-cobol-list] DIVIDE: wrong remainder
From: |
Hans-Martin Rasch |
Subject: |
[open-cobol-list] DIVIDE: wrong remainder |
Date: |
Wed Mar 8 02:56:07 2006 |
User-agent: |
KMail/1.6 |
The following code
05 WK-X1 PIC S9(09) COMP.
05 WK-X2 PIC S9(09) COMP.
05 WK-X3 PIC S9(09) COMP.
05 WK-X4 PIC S9(10) COMP.
.
.
MOVE 4301 TO WK-X1.
MOVE 10 TO WK-X2.
DIVIDE WK-X2 INTO WK-X1
GIVING WK-X4 REMAINDER WK-X3.
DISPLAY WK-X4 " REM. " WK-X3.
gives the output
+00000000000000000430 REM. -0000180599
Reason: In cob_div_quotient() there is a call of cob_decimal_get_field() which
in turn calls cob_decimal_get_binary(). This function uses cob_d2 as a
temporary variable, if the field size is > 4. Thus the previous value of
cob_d2 is destroyed.
This can be fixed by introducing an new variable
"static cob_decimal cob_d5;"
and replacing cob_d2 by cob_d5 in cob_div_quotient()
(not to forget "cob_decimal_init (&cob_d5);"
in cob_init_numeric() ).
Regards
Hans-Martin Rasch
- [open-cobol-list] DIVIDE: wrong remainder,
Hans-Martin Rasch <=