https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93567
--- Comment #8 from Dominique d'Humieres <dominiq at lps dot ens.fr> --- Simpler patch with comments --- ../_clean/libgfortran/io/write_float.def 2020-06-13 03:11:55.000000000 +0200 +++ libgfortran/io/write_float.def 2020-07-21 23:03:08.000000000 +0200 @@ -987,16 +987,19 @@ determine_en_precision (st_parameter_dt w = default_width;\ d = precision;\ }\ + /* The switch between FMT_E and FMT_F is based on the absolute value. \ + Set r=0 for rounding toward zero and r = 1 otherwise. \ + If (exp_d - m) == 1 there is no rounding needed. */\ switch (dtp->u.p.current_unit->round_status)\ {\ case ROUND_ZERO:\ - r = sign_bit ? 1.0 : 0.0;\ + r = 0.0;\ break;\ case ROUND_UP:\ - r = 1.0;\ + r = sign_bit ? 0.0 : 1.0;\ break;\ case ROUND_DOWN:\ - r = 0.0;\ + r = sign_bit ? 1.0 : 0.0;\ break;\ default:\ break;\ @@ -1004,7 +1007,8 @@ determine_en_precision (st_parameter_dt 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))))\ + if ((m > 0.0 && ((m < temp) || (r < 1 && r >= (exp_d - m))\ + || (r == 1 && 1 > (exp_d - m))))\ || ((m == 0.0) && !(compile_options.allow_std\ & (GFC_STD_F2003 | GFC_STD_F2008)))\ || d == 0)\