Menu

#996 Constant folding does not handle big numbers

GC 3.x
open
nobody
5 - default
2024-10-02
2024-10-02
No

Hi

When compiling this program i have a bad result
The problem is that in the cb_build_binary_op function the we diden't check that somme functions return 'bad' result (atoll for example )
If the arg of atoll is to large it returns 0

When compiled with no-constant , it's ok .

My guess to solve the problem :
At compile time use gmp to handle op and result and then generate the good constant regarding if the result fits in c type range.

Denis

       IDENTIFICATION DIVISION.
       PROGRAM-ID . testfold .
      *>----------------------------------------------------------------
      *>----------------------------------------------------------------
      *>
       ENVIRONMENT DIVISION.
       DATA DIVISION .
       WORKING-STORAGE  SECTION.

       01 MAX-PWR2-1     PIC 9(38) PACKED-DECIMAL .
      *>
       PROCEDURE DIVISION .
      *>------------------
      *>
           compute max-pwr2-1  = 2 ** 102
           on size error
                   display 'error should not size error'
           end-compute.
           if max-pwr2-1 NOT = 5070602400912917605986812821504
           then
                   display max-pwr2-1
                   display 'error' .
      *>
           compute max-pwr2-1  =
                   9223372036854775806 * 9223372036854775806
           on size error
                   display 'error should not size error'
           end-compute.
           if max-pwr2-1 NOT = 85070591730234615828950163710522949636
           then
                   display max-pwr2-1
                   display 'error' .



           GOBACK .

Discussion


Log in to post a comment.