public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libfortran/17195] New: Infinite loop in output_float in libgfortran/io/write.c
@ 2004-08-25 23:48 sgk at troutmask dot apl dot washington dot edu
  2004-08-25 23:49 ` [Bug libfortran/17195] " pinskia at gcc dot gnu dot org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: sgk at troutmask dot apl dot washington dot edu @ 2004-08-25 23:48 UTC (permalink / raw)
  To: gcc-bugs

This program,

   program t
   real(8) y
   print*, 'huge(y) = ', huge(y)
   end program t

when compiled with "gfortran -static -o t t.f90" leads
to a program "t", which executes an infinite loop.  The 
problem is in libgfortran/io/write.c where write_real()
sets the global variable g.scaling=1.  We eventually end
up executing this code in output_float() where
n = huge(y) and sca = 1.

  if (ft == FMT_F || ft == FMT_E || ft == FMT_D)
    {
      if (ft == FMT_F)
        scale_flag = 0;
      if (ft == FMT_D)
        exp_char = 'D' ;
      minv = 0.1;
      maxv = 1.0;

      /* Calculate the new val of the number with consideration
         of global scale value.  */
      while (sca >  0)
        {
          minv *= 10.0;
          maxv *= 10.0;
          n *= 10.0;       /* XXXXX huge(y) * 10 becomes Inf. */
          sca -- ;
          neval --;
        }

      /* Now calculate the new Exp value for this number.  */
      sca = g.scale_factor;
      while(sca >= 1)
        {
          sca /= 10;
          digits ++ ;
        }
    }

Further down, we hit this loop and n = Inf > maxv, forever.

   while (scale_flag && n > 0.0 && n > maxv)
     {
       if (n > maxv)
         {
           n = n / 10.0 ;
           neval ++;
         }
     }

-- 
           Summary: Infinite loop in output_float in libgfortran/io/write.c
           Product: gcc
           Version: 3.5.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: libfortran
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: sgk at troutmask dot apl dot washington dot edu
                CC: gcc-bugs at gcc dot gnu dot org
  GCC host triplet: amd64-unknown-freebsd5.2


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


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

end of thread, other threads:[~2004-08-31 20:58 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-08-25 23:48 [Bug libfortran/17195] New: Infinite loop in output_float in libgfortran/io/write.c sgk at troutmask dot apl dot washington dot edu
2004-08-25 23:49 ` [Bug libfortran/17195] " pinskia at gcc dot gnu dot org
2004-08-26 20:32 ` sgk at troutmask dot apl dot washington dot edu
2004-08-28 19:48 ` cvs-commit at gcc dot gnu dot org
2004-08-28 22:03 ` pinskia at gcc dot gnu dot org
2004-08-31 20:58 ` pinskia 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).