public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/20473] New: false arithmetic  with short integers
@ 2005-03-14 18:49 ralph dot doering at web dot de
  2005-03-14 19:03 ` [Bug fortran/20473] " tobi at gcc dot gnu dot org
  0 siblings, 1 reply; 2+ messages in thread
From: ralph dot doering at web dot de @ 2005-03-14 18:49 UTC (permalink / raw)
  To: gcc-bugs

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


^ permalink raw reply	[flat|nested] 2+ messages in thread

* [Bug fortran/20473] false arithmetic  with short integers
  2005-03-14 18:49 [Bug fortran/20473] New: false arithmetic with short integers ralph dot doering at web dot de
@ 2005-03-14 19:03 ` tobi at gcc dot gnu dot org
  0 siblings, 0 replies; 2+ messages in thread
From: tobi at gcc dot gnu dot org @ 2005-03-14 19:03 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From tobi at gcc dot gnu dot org  2005-03-14 19:03 -------
"2*i1" implicitly converts i1 to default integer kind, and then performs the
multiplication.  g77's behavior is correct.  It is unfortunate that g77 doesn't
have the -Wconversion command-line option, with gfortran you get:
[tobi@marktplatz tests]$ gfortran pr20473.f90 -Wconversion
 In file pr20473.f90:8

      print*, i1+i1, 2*i1
                        1
Warning: Conversion from INTEGER(1) to INTEGER(4) at (1)
 In file pr20473.f90:10

      print*, i2+i2, 2*i2
                        1
Warning: Conversion from INTEGER(2) to INTEGER(4) at (1)
 In file pr20473.f90:7

      i1=100
        1
Warning: Conversion from INTEGER(4) to INTEGER(1) at (1)
 In file pr20473.f90:9

      i2=20000
        1
Warning: Conversion from INTEGER(4) to INTEGER(2) at (1)


-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID


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


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2005-03-14 19:03 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-03-14 18:49 [Bug fortran/20473] New: false arithmetic with short integers ralph dot doering at web dot de
2005-03-14 19:03 ` [Bug fortran/20473] " tobi at gcc dot gnu dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).