[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[open-cobol-list] Incorrect results with binary fields
From: |
Roger While |
Subject: |
[open-cobol-list] Incorrect results with binary fields |
Date: |
Fri Oct 8 12:02:41 2004 |
Take the following program compiled with one of the options
that sets binary-trunc off :
IDENTIFICATION DIVISION.
PROGRAM-ID. TCOMP.
ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 P1 pic 9(9) comp.
01 P2 pic S9(9) comp.
01 P3 pic 9(9) comp-5.
01 P4 pic S9(9) comp-5.
PROCEDURE DIVISION.
MAIN-LINE-BEGIN.
* Move near max value to signed fields
display "Move 2147483640 to signed comp/comp-5"
move 2147483640 to p2 p4
display "Pic s9(8) comp " p2
display "Pic s9(8) comp-5 " p4
add 64 to p2
add 64 to p4
display "Add 64 to comp/comp-5"
display "Pic s9(8) comp " p2
display "Pic s9(8) comp-5 " p4
* Move near max value to unsigned fields
display "Move 4294967290 to unsigned comp/comp-5"
move 4294967290 to p1 p3
display "Pic 9(8) comp " p1
display "Pic 9(8) comp-5 " p3
add 64 to p1
add 64 to p3
display "Add 64 to comp/comp-5"
display "Pic 9(8) comp " p1
display "Pic 9(8) comp-5 " p3
STOP RUN.
This gives (incorrectly) :
Move 2147483640 to signed comp/comp-5
Pic s9(8) comp +2147483640
Pic s9(8) comp-5 +2147483640
Add 64 to comp/comp-5
Pic s9(8) comp +2147483640
Pic s9(8) comp-5 +2147483640
Move 4294967290 to unsigned comp/comp-5
Pic 9(8) comp 4294967290
Pic 9(8) comp-5 4294967290
Add 64 to comp/comp-5
Pic 9(8) comp 4294967290
Pic 9(8) comp-5 4294967290
It should be producing :
Move 2147483640 to signed comp/comp-5
Pic s9(8) comp +2147483640
Pic s9(8) comp-5 +2147483640
Add 64 to comp/comp-5
Pic s9(8) comp -2147483592
Pic s9(8) comp-5 -2147483592
Move 4294967290 to unsigned comp/comp-5
Pic 9(8) comp 4294967290
Pic 9(8) comp-5 4294967290
Add 64 to comp/comp-5
Pic 9(8) comp 0000000058
Pic 9(8) comp-5 0000000058
There seem to be several problems here,
some of which I have detected but there still remains
something that is wrong.
In numeric.c, cob_decimal_get_binary, we should not be doing
the mpz_fits tests when !flag_binary_truncate (I think)
However, that's not the only problem. Still looking.
Keisuke, can you come up with a quick fix ?
Roger While
- [open-cobol-list] Incorrect results with binary fields,
Roger While <=