diff options
author | Francois-Xavier Coudert <coudert@clipper.ens.fr> | 2005-03-11 09:03:02 +0100 |
---|---|---|
committer | Bud Davis <bdavis@gcc.gnu.org> | 2005-03-11 08:03:02 +0000 |
commit | 0b2df4a7037bf50942bb43ae799f88a7d6c4c261 (patch) | |
tree | 411601a3cc2297dfd35f8ff0cb7349f27c25de3f /libgfortran/io | |
parent | cbefb99c9944240c248e7aa8dcd9bfd2b7ecc864 (diff) | |
download | gcc-0b2df4a7037bf50942bb43ae799f88a7d6c4c261.zip gcc-0b2df4a7037bf50942bb43ae799f88a7d6c4c261.tar.gz gcc-0b2df4a7037bf50942bb43ae799f88a7d6c4c261.tar.bz2 |
[multiple changes]
2005-03-12 Francois-Xavier Coudert <coudert@clipper.ens.fr>
PR libfortran/20124
* gfortran.dg/pr20124.f90: New Test
2005-03-11 Francois-Xavier Coudert <coudert@clipper.ens.fr>
PR libfortran/20124
* write.c (output_float): Adds a nzero_real variable to store
the number of leading zeros whatever the format width is. Corrects
the rounding of numbers less than 10^(-width). Fixes typo in an
error message. Updates copyright years
From-SVN: r96291
Diffstat (limited to 'libgfortran/io')
-rw-r--r-- | libgfortran/io/write.c | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/libgfortran/io/write.c b/libgfortran/io/write.c index 1babd20..9c255d7 100644 --- a/libgfortran/io/write.c +++ b/libgfortran/io/write.c @@ -286,6 +286,8 @@ output_float (fnode *f, double value, int len) int nzero; /* Number of digits after the decimal point. */ int nafter; + /* Number of zeros after the decimal point, whatever the precision. */ + int nzero_real; int leadzero; int nblanks; int i; @@ -295,6 +297,9 @@ output_float (fnode *f, double value, int len) w = f->u.real.w; d = f->u.real.d; + nzero_real = -1; + + /* We should always know the field width and precision. */ if (d < 0) internal_error ("Unspecified precision"); @@ -359,6 +364,7 @@ output_float (fnode *f, double value, int len) if (nbefore < 0) { nzero = -nbefore; + nzero_real = nzero; if (nzero > d) nzero = d; nafter = d - nzero; @@ -436,7 +442,17 @@ output_float (fnode *f, double value, int len) /* Round the value. */ if (nbefore + nafter == 0) - ndigits = 0; + { + ndigits = 0; + if (nzero_real == d && digits[0] >= '5') + { + /* We rounded to zero but shouldn't have */ + nzero--; + nafter = 1; + digits[0] = '1'; + ndigits = 1; + } + } else if (nbefore + nafter < ndigits) { ndigits = nbefore + nafter; |