write.c (write_float): Revise output of IEEE exceptional values to comply with F95...
authorJerry DeLisle <jvdelisle@verizon.net>
Sun, 24 Jul 2005 02:24:15 +0000 (02:24 +0000)
committerJerry DeLisle <jvdelisle@gcc.gnu.org>
Sun, 24 Jul 2005 02:24:15 +0000 (02:24 +0000)
2005-07-23  Jerry DeLisle  <jvdelisle@verizon.net>

    * io/write.c (write_float): Revise output of IEEE exceptional
    values to comply with F95 and F2003 standards.

From-SVN: r102324

libgfortran/ChangeLog
libgfortran/io/write.c

index 747ef9e9023cb9d49b178c65a5ffd047e54f1d20..3e37aacb211056c60927ef8f3bcc30ede9e2004b 100644 (file)
@@ -1,3 +1,8 @@
+2005-07-23  Jerry DeLisle  <jvdelisle@verizon.net>
+
+    * io/write.c (write_float): Revise output of IEEE exceptional
+    values to comply with F95 and F2003 standards.
+    
 2005-07-22 Jerry DeLisle <jvdelisle@verizon.net>
 
        PR libfortran/22570
index 54bf480fdf3de3e2ef4446cb74f7da554871861f..a702de18a2a9378ed31377a1325b09d0d24657bc 100644 (file)
@@ -772,6 +772,11 @@ write_float (fnode *f, const char *source, int len)
       if (res == 0)
        {
          nb =  f->u.real.w;
+         
+         /* If the field width is zero, the processor must select a width 
+            not zero.  4 is chosen to allow output of '-Inf' or '+Inf' */
+            
+         if (nb == 0) nb = 4;
          p = write_block (nb);
          if (nb < 3)
            {
@@ -784,18 +789,43 @@ write_float (fnode *f, const char *source, int len)
          if (res != 0)
            {
              if (signbit(n))
-               fin = '-';
+               {
+               
+                 /* If the sign is negative and the width is 3, there is
+                    insufficient room to output '-Inf', so output asterisks */
+                    
+                 if (nb == 3)
+                   {
+                     memset (p, '*',nb);
+                     return;
+                   }
+                   
+                 /* The negative sign is mandatory */
+                   
+                 fin = '-';
+               }    
              else
-               fin = '+';
+             
+                 /* The positive sign is optional, but we output it for
+                    consistency */
+                    
+                 fin = '+';
 
              if (nb > 8)
+             
+               /* We have room, so output 'Infinity' */
+               
                memcpy(p + nb - 8, "Infinity", 8);
              else
+             
+               /* For the case of width equals 8, there is not enough room
+                  for the sign and 'Infinity' so we go with 'Inf' */
+                   
                memcpy(p + nb - 3, "Inf", 3);
              if (nb < 9 && nb > 3)
-               p[nb - 4] = fin;
+               p[nb - 4] = fin;  /* Put the sign in front of Inf */
              else if (nb > 8)
-               p[nb - 9] = fin;
+               p[nb - 9] = fin;  /* Put the sign in front of Infinity */
            }
          else
            memcpy(p + nb - 3, "NaN", 3);