[PATCH] Fix PR 17195

Steve Kargl sgk@troutmask.apl.washington.edu
Thu Aug 26 20:07:00 GMT 2004


The attached patch hacks around a corner case
in writing out floating point numbers.  This
program

    real(8) x
    print*. huge(x)
    end

will enter an infinite loop.

2004-08-24  Steven G. Kargl  <kargls@comcast.net>

        PR fortran/17195        
        * io/write.c (output_float): Avoid corner case "print *, huge(1e0_8)"

-- 
Steve
-------------- next part --------------
? write.c.diff
Index: write.c
===================================================================
RCS file: /cvs/gcc/gcc/libgfortran/io/write.c,v
retrieving revision 1.11
diff -u -r1.11 write.c
--- write.c	23 Aug 2004 14:28:31 -0000	1.11
+++ write.c	26 Aug 2004 19:58:51 -0000
@@ -316,8 +316,17 @@
           minv *= 10.0;
           maxv *= 10.0;
           n *= 10.0;
-          sca -- ;
-          neval --;
+          /* Corner case of n = HUGE(REAL(8)).  */
+          if (isinf(n) && isfinite(value))
+          {
+            sca = 0;
+            n = (value > 0) ? value : - value;
+          }
+          else
+          {
+            sca -- ;
+            neval --;
+          }
         }
 
       /* Now calculate the new Exp value for this number.  */


More information about the Fortran mailing list