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



--- Comment #3 from Harald Anlauf <anlauf at gmx dot de> 2012-12-11 22:33:21 
UTC ---

(In reply to comment #2)



I played a little bit with the code and found that the

following patch appears to fix my problem:



Index: libgfortran/io/write_float.def

===================================================================

--- libgfortran/io/write_float.def      (revision 194417)

+++ libgfortran/io/write_float.def      (working copy)

@@ -492,7 +492,7 @@

   /* To format properly, we need to know if the rounded result is zero and if

      so, we set the zero_flag which may have been already set for

      actual zero.  */

-  if (i == ndigits)

+  if (i == ndigits && (digits[i] == '0' || digits[i] == '.'))

     {

       zero_flag = true;

       /* The output is zero, so set the sign according to the sign bit unless





Testcase:



  implicit none

  real              :: x = 0.5 + epsilon(0.)

  character(len=80) :: line

  print '(7f5.1)', x, -x

  write (line,'(2f5.1)') x, -x

  print '(A)', line

  if (line /= "  0.5 -0.5") call abort ()

  print '(7f5.0)', x, -x

  write (line,'(2f5.0)') x, -x

  print '(A)', line

  if (line /= "   1.  -1.") call abort ()

end





Strangely enough I needed to add some epsilon to 0.5 so that

the second test passes, because the exact value 0.5 appears

to get rounded down to 0 in formatted output.

Reply via email to