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/77648] New: Setting conversion to a integer to double to 0 3/4 through a loop


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77648

            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 gnu.org
          Reporter: raynman4451 at tamu dot edu
  Target Milestone: ---

Howdy,
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.

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