patch for pr 17706 -- output of -0.00 instead of 0.00
Paul Brook
paul@codesourcery.com
Mon Oct 4 15:36:00 GMT 2004
On Tuesday 28 September 2004 05:11, Bud Davis wrote:
> the below patch fixes the problem of a format statement displaying
> output of -0.00, due to setting the sign before rounding for the input.
>
> after looking over write.c, you have to finish the entire format
> before you can detect a case like the above, so i added
We do have all the digits (rounded correctly) before we start writing the
value, so can detect zero before outputting the sign. Implemented as below.
I also found and fixed PR16434 while playing with the testcase.
Tested on i686-linux.
Applied to mainline.
Paul
2004-10-04 Paul Brook <paul@codesourcery.com>
Bud Davis <bdavis9659@comcast.net>
PR fortran/17706
PR fortran/16434
* io/format.c (parse_format_list): Set repeat count for S, SP, SS,
BN and BZ formats.
* io/write.c (output_float): Don't output minus zero.
libgfortran/
* gfortran/pr17706.f90: New test.
* gfortran.dg/g77/f77-edit-s-out.f: Remove xfail.
Index: gcc/testsuite/gfortran.dg/g77/f77-edit-s-out.f
===================================================================
RCS
file: /var/cvsroot/gcc-cvs/gcc/gcc/testsuite/gfortran.dg/g77/f77-edit-s-out.f,v
retrieving revision 1.1
diff -u -p -r1.1 f77-edit-s-out.f
--- gcc/testsuite/gfortran.dg/g77/f77-edit-s-out.f 8 Jul 2004 23:36:52 -0000
1.1
+++ gcc/testsuite/gfortran.dg/g77/f77-edit-s-out.f 4 Oct 2004 15:21:26 -0000
@@ -16,5 +16,5 @@ C ( dg-output "^" }
write(*,40) 0 ! { dg-output " \\+0(\n|\r\n|\r)" }
C 15.5.9 - Note 5: When SP editing is in effect, the plus sign is not
optional
write(*,50) 11 ! { dg-output "\\*\\*(\n|\r\n|\r)" }
-C { dg-output "\$" {xfail *-*-*} } gfortran PR 16434
+C { dg-output "\$" }
end
Index: libgfortran/io/format.c
===================================================================
RCS file: /var/cvsroot/gcc-cvs/gcc/libgfortran/io/format.c,v
retrieving revision 1.6
diff -u -p -r1.6 format.c
--- libgfortran/io/format.c 2 Sep 2004 01:33:01 -0000 1.6
+++ libgfortran/io/format.c 4 Oct 2004 14:38:02 -0000
@@ -552,6 +552,7 @@ format_item:
case FMT_BN:
case FMT_BZ:
get_fnode (&head, &tail, t);
+ tail->repeat = 1;
goto between_desc;
case FMT_COLON:
Index: libgfortran/io/write.c
===================================================================
RCS file: /var/cvsroot/gcc-cvs/gcc/libgfortran/io/write.c,v
retrieving revision 1.15
diff -u -p -r1.15 write.c
--- libgfortran/io/write.c 3 Oct 2004 12:04:15 -0000 1.15
+++ libgfortran/io/write.c 4 Oct 2004 15:02:33 -0000
@@ -425,9 +425,12 @@ output_float (fnode *f, double value, in
}
/* Round the value. */
- if (nbefore + nafter < ndigits && nbefore + nafter > 0)
+ if (nbefore + nafter == 0)
+ ndigits = 0;
+ else if (nbefore + nafter < ndigits)
{
- i = nbefore + nafter;
+ ndigits = nbefore + nafter;
+ i = ndigits;
if (digits[i] >= '5')
{
/* Propagate the carry. */
@@ -513,6 +516,16 @@ output_float (fnode *f, double value, in
if (out == NULL)
return;
+ /* Zero values always output as positive, even if the value was negative
+ before rounding. */
+ for (i = 0; i < ndigits; i++)
+ {
+ if (digits[i] != '0')
+ break;
+ }
+ if (i == ndigits)
+ sign = calculate_sign (0);
+
/* Work out how much padding is needed. */
nblanks = w - (nbefore + nzero + nafter + edigits + 1);
if (sign != SIGN_NONE)
More information about the Gcc-patches
mailing list