Menu

ADD and SUBTRACT with ROUNDED

Anonymous
2024-01-09
2024-01-10
  • Anonymous

    Anonymous - 2024-01-09

    Hi
    The following program show a bug in the ADD statement with the ROUNDED clause. The function cob_addsub_optimized (numeric.c) does not work.

           IDENTIFICATION DIVISION.
           PROGRAM-ID. GAG1.
          *
           ENVIRONMENT DIVISION.
           CONFIGURATION SECTION.
           SOURCE-COMPUTER. VAX-11.
           OBJECT-COMPUTER. VAX-11.
           SPECIAL-NAMES.
                 DECIMAL-POINT IS COMMA.
          *
           DATA DIVISION.
           WORKING-STORAGE SECTION.
            1  TOTO.
             2   RESULT PIC S9(13)V9(2) COMP-3.
             2   RESULT-5 PIC S9(13)V9(5) COMP-3.
    
           PROCEDURE DIVISION.
           DEBUT.
                 DISPLAY "add rounded fail".
                 MOVE 3,14659 TO RESULT-5.
                 DISPLAY "ADD  RESULT-5 TO RESULT ROUNDED.".
                 DISPLAY "RESULT-5 " RESULT-5.
                 MOVE ZERO TO RESULT.
                 ADD  RESULT-5 TO RESULT ROUNDED.
                 DISPLAY "RESULT " RESULT.
                 STOP RUN.
    

    The results are :

    add rounded fail
    ADD  RESULT-5 TO RESULT ROUNDED.
    RESULT-5 +000000000000314659
    RESULT +000000000000314
    
     

    Last edit: Simon Sobisch 2024-01-09
  • Simon Sobisch

    Simon Sobisch - 2024-01-09

    Hi Anonymous. Please consider to register/login; and if you don't do that wait for post-moderation (that's a manual thing!) before posting again.

    Concerning the content (I've did some minor mod-editing for syntax-highlighting) - cob_addsub_optimized(), which is called internally by cob_add() and sub_sub(), calls cob_add_bcd() which handles ROUNDING in general.

    I'll recheck later, if no one does it before.

     
  • Simon Sobisch

    Simon Sobisch - 2024-01-09

    Thank you for reporting this severe issue, which is now tracked as [bugs:#934] (see this report for more details including possible work-arounds in the COBOL code).
    If you build GnuCOBOL from source you could also locally fix that (numeric.c around line 3100), or wait until Chuck provides the fix (likely in the next 32h :-)

     
    👍
    1

    Related

    Bugs: #934

  • Anonymous

    Anonymous - 2024-01-10

    Hello,

    the fix for this issue has been coded and tested. I expect that Simon will include it in the upcoming 3.3 release

    F:\AA-minGW32-static>testbug-001
    add rounded fail
    ADD RESULT-5 TO RESULT ROUNDED.
    RESULT-5 +0000000000003,14659
    RESULT +0000000000003,15

    ps... note that the 3.3 fixes also include a fix for the missing decimal point character in the DISPLAY output.

    Chuck Haatvedt

     
    👍
    2
  • Chuck Haatvedt

    Chuck Haatvedt - 2024-01-10

    Sorry, I have auto logon set but for some reason, I was not logged in and did not notice that when I responded above.

      Chuck Haatvedt
    
     

Anonymous
Anonymous

Add attachments
Cancel