The Operation 2*i with short integers (KIND=3, KIND=6) give incorrect values if
the result exeeds the definded range for this types. The program example
compiled with  

g77 test.f

give the following results:
integer*1:      100+100=-56,         2*100=200
integer*2:      20000+20000=-25536,  2*20000=40000

The second one of each line ist mathematical correct, but outside the valid
range of the data type.

Test System was a Redhat Linux 4 Enterprise on Dual Opteron
gcc-Version 3.4.3 20041212 (Red Hat 3.4.3-9.EL4)

Also seen with gcc 3.3.1 on Suse Linux 9.1 on Pentium M, and with
cygwin gcc 3.3.3 on Xeon System.



      program short_int_test

      implicit none
      integer*1  i1
      integer*2  i2

      i1=100
      print*, i1+i1, 2*i1
      i2=20000
      print*, i2+i2, 2*i2

      end

-- 
           Summary: false arithmetic  with short integers
           Product: gcc
           Version: 3.4.3
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: fortran
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: ralph dot doering at web dot de
                CC: gcc-bugs at gcc dot gnu dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20473

Reply via email to