diff options
author | Jerry DeLisle <jvdelisle@gcc.gnu.org> | 2024-02-02 18:12:33 -0800 |
---|---|---|
committer | Jerry DeLisle <jvdelisle@gcc.gnu.org> | 2024-02-03 09:31:35 -0800 |
commit | d436e8e70dacd9c06247bb56d0abeded8fcb4242 (patch) | |
tree | 042962bb82d2cbc5158b7cc6a768275a2a596f17 /libgfortran/io/write.c | |
parent | 266354012e0aa42e0d1639ee7708595f316cc36b (diff) | |
download | gcc-d436e8e70dacd9c06247bb56d0abeded8fcb4242.zip gcc-d436e8e70dacd9c06247bb56d0abeded8fcb4242.tar.gz gcc-d436e8e70dacd9c06247bb56d0abeded8fcb4242.tar.bz2 |
libgfortran: EN0.0E0 and ES0.0E0 format editing.
F2018 and F2023 standards added zero width exponents. This required
additional special handing in the process of building formatted
floating point strings.
G formatting uses either F or E formatting as documented in
write_float.def comments. This logic changes the format token from FMT_G
to FMT_F or FMT_E. The new formatting requirements interfere with this
process when a FMT_G float string is being built. To avoid this, a new
component called 'pushed' is added to the fnode structure to save this
condition. The 'pushed' condition is then used to bypass portions of
the new ES,E,EN, and D formatting, falling through to the existing
default formatting which is retained.
libgfortran/ChangeLog:
PR libfortran/111022
* io/format.c (get_fnode): Update initialization of fnode.
(parse_format_list): Initialization.
* io/format.h (struct fnode): Added the new 'pushed' component.
* io/write.c (select_buffer): Whitespace.
(write_real): Whitespace.
(write_real_w0): Adjust logic for the d == 0 condition.
* io/write_float.def (determine_precision): Whitespace.
(build_float_string): Calculate width of ..E0 exponents and
adjust logic accordingly.
(build_infnan_string): Whitespace.
(CALCULATE_EXP): Whitespace.
(quadmath_snprintf): Whitespace.
(determine_en_precision): Whitespace.
gcc/testsuite/ChangeLog:
PR libfortran/111022
* gfortran.dg/fmt_error_10.f: Show D+0 exponent.
* gfortran.dg/pr96436_4.f90: Show E+0 exponent.
* gfortran.dg/pr96436_5.f90: Show E+0 exponent.
* gfortran.dg/pr111022.f90: New test.
Diffstat (limited to 'libgfortran/io/write.c')
-rw-r--r-- | libgfortran/io/write.c | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/libgfortran/io/write.c b/libgfortran/io/write.c index 49beaee..1a7c123 100644 --- a/libgfortran/io/write.c +++ b/libgfortran/io/write.c @@ -1574,7 +1574,7 @@ select_buffer (st_parameter_dt *dtp, const fnode *f, int precision, char *buf, size_t *size, int kind) { char *result; - + /* The buffer needs at least one more byte to allow room for normalizing and 1 to hold null terminator. */ *size = size_from_kind (dtp, f, kind) + precision + 1 + 1; @@ -1757,7 +1757,7 @@ write_real (st_parameter_dt *dtp, const char *source, int kind) /* Scratch buffer to hold final result. */ buffer = select_buffer (dtp, &f, precision, buf_stack, &buf_size, kind); - + get_float_string (dtp, &f, source , kind, 1, buffer, precision, buf_size, result, &flt_str_len); write_float_string (dtp, result, flt_str_len); @@ -1785,8 +1785,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 @@ -1794,11 +1792,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; |