Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

#41 ADD -2 TO 1 GIVES 999 instead of -1

invalid
closed
nobody
None
1
2012-10-18
2012-10-12
Ron Norman
No

See the following test program and results using OpenCOBOL 1.1
Does anyone have a fix for this?

   IDENTIFICATION DIVISION.
   PROGRAM-ID.    tst9.
   DATA  DIVISION.
   WORKING-STORAGE SECTION.
   01  NUMS9    PIC S9(7) VALUE 74848.
   01  NEGS9    PIC S9(7) VALUE -74849.

   PROCEDURE DIVISION.
       DISPLAY NUMS9.
       ADD -74849 TO NUMS9.
       DISPLAY NUMS9.
       MOVE 74848 to NUMS9.
       ADD NEGS9 TO NUMS9.
       DISPLAY NUMS9.
       STOP RUN.

/u/tipsrc/tst:4 >tst9
0074848+
9999999+
9999999+

Discussion

  • Ron Norman
    Ron Norman
    2012-10-14

    The problem was in libcob/numeric.c in the routine cob_add_int.
    It tries to optimize handling of COB_TYPE_NUMERIC_DISPLAY and COB_TYPE_NUMERIC_PACKED but the routines called do not handle numeric underflow. I.e. computing a negative result.
    I simply commented out that code let it always execute the default code which uses teh GMP package that seems to always work.
    This was for OpenCOBOL 1.1.
    This issue can be closed.

     
  • Simon Sobisch
    Simon Sobisch
    2012-10-15

    No, can't be closed as there isn't any fix in trunk.

    I cannot reproduce it neither in an older 1.1 pre-release nor in 1.1 CE. From the sources the handling of negative values seems correct.
    We really should try to find out why your program broke.

    Simon

     
  • Ron Norman
    Ron Norman
    2012-10-16

    I have some middle version of 1.1 and the problem was definitely in numeric.c as I described above. Maybe this was some new cdoe that Roger was working on but never completed. I got this 1.1 version directly from Roger While in March 2010.

     
  • Simon Sobisch
    Simon Sobisch
    2012-10-18

    Please do me a favour: only talk about 1.1 with "official" versions --> "1.1 Release" (=Feb 09) or "1.1 CE (currently no release, only SVN)".
    I highly suggest to use one of these, as there'll be no support for other versions (and that is for reason, at least your problem here did never occur in "official" 1.1 versions).

    Bug closed as invalid.

    Simon

     
  • Simon Sobisch
    Simon Sobisch
    2012-10-18

    • status: open --> closed
    • milestone: open --> invalid