diff options
author | Jerry DeLisle <jvdelisle@gcc.gnu.org> | 2014-01-19 23:17:43 +0000 |
---|---|---|
committer | Jerry DeLisle <jvdelisle@gcc.gnu.org> | 2014-01-19 23:17:43 +0000 |
commit | 32aeb94ab171c66d379610c53dc7423cd9c1ddae (patch) | |
tree | a6359e54c7c40f08ced929b1de5a0ed36e6a6642 /libgfortran/io | |
parent | cdafab3de6518fa0055425aea8fcc82fc2b53872 (diff) | |
download | gcc-32aeb94ab171c66d379610c53dc7423cd9c1ddae.zip gcc-32aeb94ab171c66d379610c53dc7423cd9c1ddae.tar.gz gcc-32aeb94ab171c66d379610c53dc7423cd9c1ddae.tar.bz2 |
re PR libfortran/59771 (Cleanup handling of Gw.0 and Gw.0Ee format)
2014-01-19 Jerry DeLisle <jvdelisle@gcc.gnu>
Dominique d'Humieres <dominiq@lps.ens.fr>
PR libfortran/59771
PR libfortran/59774
PR libfortran/59836
* io/write_float.def (output_float): Fix wrong handling of the
Fw.0 format.
(output_float_FMT_G_): Fixes rounding issues with -m32.
Co-Authored-By: Dominique d'Humieres <dominiq@lps.ens.fr>
From-SVN: r206785
Diffstat (limited to 'libgfortran/io')
-rw-r--r-- | libgfortran/io/write_float.def | 22 |
1 files changed, 13 insertions, 9 deletions
diff --git a/libgfortran/io/write_float.def b/libgfortran/io/write_float.def index f8e23e9..4777cda 100644 --- a/libgfortran/io/write_float.def +++ b/libgfortran/io/write_float.def @@ -373,7 +373,7 @@ output_float (st_parameter_dt *dtp, const fnode *f, char *buffer, size_t size, updown: rchar = '0'; - if (w > 0 && d == 0 && p == 0) + if (ft != FMT_F && nbefore == 0 && w > 0 && d == 0 && p == 0) nbefore = 1; /* Scan for trailing zeros to see if we really need to round it. */ for(i = nbefore + nafter; i < ndigits; i++) @@ -386,13 +386,14 @@ output_float (st_parameter_dt *dtp, const fnode *f, char *buffer, size_t size, do_rnd: if (nbefore + nafter == 0) + /* Handle the case Fw.0 and value < 1.0 */ { ndigits = 0; if (nzero_real == d && digits[0] >= rchar) { /* We rounded to zero but shouldn't have */ - nzero--; - nafter = 1; + nbefore = 1; + digits--; digits[0] = '1'; ndigits = 1; } @@ -1018,13 +1019,14 @@ output_float_FMT_G_ ## x (st_parameter_dt *dtp, const fnode *f, \ int d = f->u.real.d;\ int w = f->u.real.w;\ fnode newf;\ - GFC_REAL_ ## x rexp_d, r = 0.5;\ + GFC_REAL_ ## x exp_d, r = 0.5, r_sc;\ int low, high, mid;\ int ubound, lbound;\ char *p, pad = ' ';\ int save_scale_factor, nb = 0;\ bool result;\ int nprinted, precision;\ + volatile GFC_REAL_ ## x temp;\ \ save_scale_factor = dtp->u.p.scale_factor;\ \ @@ -1043,10 +1045,13 @@ output_float_FMT_G_ ## x (st_parameter_dt *dtp, const fnode *f, \ break;\ }\ \ - rexp_d = calculate_exp_ ## x (-d);\ - if ((m > 0.0 && ((m < 0.1 - 0.1 * r * rexp_d) || (rexp_d * (m + r) >= 1.0)))\ + exp_d = calculate_exp_ ## x (d);\ + r_sc = (1 - r / exp_d);\ + temp = 0.1 * r_sc;\ + if ((m > 0.0 && ((m < temp) || (r >= (exp_d - m))))\ || ((m == 0.0) && !(compile_options.allow_std\ - & (GFC_STD_F2003 | GFC_STD_F2008))))\ + & (GFC_STD_F2003 | GFC_STD_F2008)))\ + || d == 0)\ { \ newf.format = FMT_E;\ newf.u.real.w = w;\ @@ -1066,10 +1071,9 @@ output_float_FMT_G_ ## x (st_parameter_dt *dtp, const fnode *f, \ \ while (low <= high)\ { \ - volatile GFC_REAL_ ## x temp;\ mid = (low + high) / 2;\ \ - temp = (calculate_exp_ ## x (mid - 1) * (1 - r * rexp_d));\ + temp = (calculate_exp_ ## x (mid - 1) * r_sc);\ \ if (m < temp)\ { \ |