From 87aa609d76b2981ba3a01980919ef95c93bde950 Mon Sep 17 00:00:00 2001 From: jvdelisle Date: Sun, 19 Jan 2014 23:17:43 +0000 Subject: [PATCH] 2014-01-19 Jerry DeLisle Dominique d'Humieres 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. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@206785 138bc75d-0d04-0410-961f-82ee72b054a4 --- libgfortran/ChangeLog | 10 ++++++++++ libgfortran/io/write_float.def | 22 +++++++++++++--------- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/libgfortran/ChangeLog b/libgfortran/ChangeLog index 308ae8d..3e3ef97 100644 --- a/libgfortran/ChangeLog +++ b/libgfortran/ChangeLog @@ -1,3 +1,13 @@ +2014-01-19 Jerry DeLisle + Dominique d'Humieres + + 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. + 2014-01-11 Jerry DeLisle Dominique d'Humieres Steven G. Kargl 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)\ { \ -- 2.7.4