Bug ID: 77648
           Summary: Setting conversion to a integer to double to 0 3/4
                    through a loop
           Product: gcc
           Version: 5.3.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot
          Reporter: raynman4451 at tamu dot edu
  Target Milestone: ---

I am using gfortran 5.3.1 on OSX 10.11. My code is compiled with -m64 -O3
-fdefault-real-8 -fdefault-double-8, and when compiled for debugging  -m64
-fdefault-real-8 -fdefault-double-8 -fcheck=all -fbacktrace
-ffpe-trap=zero,underflow,denormal,invalid -g) does not throw any errors.
Additionally, I have statically debugged with FORCHECK. My issue is as follows.
Take the following block of code which updates the coefficients of a polynomial
type after integration:

  p_int%coefficients(0) = 0.0d0
  do i = 0, p%order
       p_int%coefficients(i+1) = 1.0d0/dble(i+1)*p%coefficients(i)
  end do

For both Intel and Absoft compilers using similar options, that loop works just
fine, and the conversion of integer to a double is ok. For gfortran, however,
1.0d0/dble(i+1) will equal 0 roughly 3/4 though the number of steps in the
loop. So, if p%order = 7, at about 5 gfortran makes that factor 0. It does not
do this if I place a write statement for 1.0d0/dble(i+1) in the loop, nor does
it do it when the debug options are thrown. To get around it, I had to change
the above block of code to the following:  

   fac = 0.0d0
   do i = 0, p%order
       fac = fac + 1.0d0
       p_int%coefficients(i+1) = p%coefficients(i)/fac
    end do

which avoids the conversion altogether.

Reply via email to