https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111022
--- Comment #17 from Jerry DeLisle <jvdelisle at gcc dot gnu.org> --- Preliminary patch: diff --git a/libgfortran/io/write.c b/libgfortran/io/write.c index 5d47a6d25f7..aafbd96b65a 100644 --- a/libgfortran/io/write.c +++ b/libgfortran/io/write.c @@ -1784,8 +1784,6 @@ write_real_w0 (st_parameter_dt *dtp, const char *source, int kind, set_fnode_default (dtp, &ff, kind); - if (f->u.real.d > 0) - ff.u.real.d = f->u.real.d; ff.format = f->format; /* For FMT_G, Compensate for extra digits when using scale factor, d @@ -1793,11 +1791,17 @@ write_real_w0 (st_parameter_dt *dtp, const char *source, int kind, is used. */ if (f->format == FMT_G) { + if (f->u.real.d > 0) + ff.u.real.d = f->u.real.d; if (dtp->u.p.scale_factor > 0 && f->u.real.d == 0) comp_d = 1; else comp_d = 0; } + else + if (f->u.real.d >= 0) + ff.u.real.d = f->u.real.d; + if (f->u.real.e >= 0) ff.u.real.e = f->u.real.e; I have regression tested this OK. I do want to watch out for any surprises so I am still testing.