This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug fortran/45624] New: Division by zero compiler error


I am running Fortran 90 on a MacBook Pro, 10.6.4, with a 2.8 GHz Intel Core 2
Duo.
I use terminal to run the code, and my compiler is gfortran.
When I type gfortran -v this is what it tells me:

Using built-in specs.
Target: i386-apple-darwin8.10.1
Configured with: /tmp/gfortran-20090604/ibin/../gcc/configure
--prefix=/usr/local/gfortran --enable-languages=c,fortran
--with-gmp=/tmp/gfortran-20090604/gfortran_libs --enable-bootstrap
Thread model: posix
gcc version 4.5.0 20090604 (experimental) [trunk revision 148180] (GCC) 


Ok, I hope that is enough information off the bat.  Here is my problem I
encountered in my code, shown here in a most simplified form to focus on the
problem:

PROGRAM test

IMPLICIT NONE
REAL*8, PARAMETER       :: alpha = 0.D0
REAL*8, DIMENSION(5,5)  :: matrix
INTEGER                 :: i

matrix = 0.D0

DO i=1,5
    IF (alpha == 0.D0) THEN
        matrix(i,i) = 0.D0
    ELSE
        matrix(i,i) = 1.D0/alpha
    ENDIF
ENDDO

END PROGRAM


When I compile, I get the following:
$ gfortran test.F90 

test.F90:14.26:

        matrix(i,i) = 1.D0/alpha
                          1
Error: Division by zero at (1)


Yes alpha is zero, and yes that line shows me dividing by it, however, I only
divide by this number when it is non-zero.  In my code, most of the time this
number is non-zero. When it is zero, I treat it with an IF-THEN-ELSE type
scenario that does not divide by zero.  The compiler doesn't realize this.

I've tried other variants (such as ELSEIF or switching the order, or using
IF-statements instead of IF-blocks), but they don't seem to matter.

I tried searching for this problem in forums, and I did read the through
gfortran manual (to avoid a RTFM answer).  However, I wasn't able to find a
similar problem or an option to fix this.  

It may seem that not making the variable alpha a PARAMETER will fix the
problem.  However, this isn't an option because of how the problem manifests
within my code.  I need to set this variable as a parameter because of how it
is used elsewhere and passed between modules and subroutines (of course it
doesn't matter in the toy program I showed here).

Thanks for your time.


-- 
           Summary: Division by zero compiler error
           Product: gcc
           Version: 4.5.0
            Status: UNCONFIRMED
          Severity: major
          Priority: P3
         Component: fortran
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: leftynm at umich dot edu


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]