Hi Jerry,

thanks for your draft patch!

I don't mind implementing it step by step, but it does not
work here as I think it should (based on two other compilers).

Let's look at the testcases first:

- real(10) should be restricted to platforms where this is
  available; it will be rejected on several others

- EXformat_1.f90

  r4 = -huge(1.0_4/3.0_4)

this is identical to

  r4 = -huge(1.0_4)

and should print as:

-0XF.FFFFFP+124

and not

-0X1.P+127

etc.

Similarly for EXformat_2.f90, the first write should be

 >          -0X9.D14707B63DFBP+3<

and not

 >                      -0X1.P+6<

I would also recommend to extend the string length s1 so that
other brands do not complain about it being to short:

  character(kind=1, len=16) :: s1

I also get a warning at compilation of io.cc:

../../gcc-trunk/gcc/fortran/io.cc: In function 'format_token format_lex()':
../../gcc-trunk/gcc/fortran/io.cc:449:11: warning: this statement may fall through [-Wimplicit-fallthrough=]
  449 |           switch (c)
      |           ^~~~~~
../../gcc-trunk/gcc/fortran/io.cc:464:9: note: here
  464 |         case 'Z':
      |         ^~~~

Can you check the logic?

I stopped the review here.

Finally a few general comments: please try to stick to the
80 columns/line recommendation for commit messages as well
as for code.

Best,
Harald

On 1/29/26 20:55, Jerry D wrote:
The attached patch is the first step in implementing the EX format specifier.

As noted in the Change Log, I chose to hold off on the KIND=16 hex float output for a future patch. Likewise for the corresponding READ implementation. Unfortunately I ran into a number of places in the files where tabs were not used for indentation. I opted to fix those now as my editor does it on the fly.

The two new test cases pass on x86_64. Some implementations of the %A in snprintf may normalize the hex representation differently. I am hoping we can get some broader testing of this so I can set the { target *-*- * } for those that pass the tests.

I intend to take care of the READ and KIND=16 implementations in my next round.

I Would like this to get into the wild if I may.

Regression tested on x86_64-linux-gnu.

Comments welcome.

OK for mainline?

Regards,

Jerry


Author: Jerry DeLisle <[email protected]>
Date:   Thu Jan 29 11:07:22 2026 -0800

     Fortran: Implement EX format writing of floats

     This patch implements the Fortran 2018 Standard EX formatting for
     WRITE of floating point.  KIND=16 is not implemented by this. READ
     is not implemented.

             PR fortran/93727

     gcc/fortran/ChangeLog:

             * io.cc (enum format_token): Add FMT_EX token.
             (format_lex): Add parsing for the FMT_EX and add
             checks as needed.

     libgfortran/ChangeLog:

             * io/format.c (format_lex): Add use of FMT_EX.
             (parse_format_list): Add parsing of FMT_EX.
             (next_format): Use FMT_EX in reversion check.
             * io/io.h (write_ex): Add prototype for write_ex.
             (internal_proto): Make it internal.
             * io/transfer.c (formatted_transfer_scalar_write): Use
             FMT_EX token in the main loop processing.
             * io/write.c (write_default_char4): Cleanup whitespace.
             (write_a): Likewise.
             (write_boz): Likewise.
             (write_decimal): Likewise.
             (otoa_big): Likewise.
             (write_character): Likewise.
             (write_float_0): Likewise.
             (write_ex): New function that implements the hex float write,
             padding with spaces as needed. Handles kind=1 and kind=4
            character output. Uses the new function get_float_hex_string ()
             defined in io/write_float.def.
             (write_real): Cleanup whitespace.
             (write_complex): Likewise.
             (nml_write_obj): Likewise.
             (namelist_write): Likewise.
            * io/write_float.def (get_float_hex_string): New function that uses the             snprintf() function with %A to create the initial hex formmatted float
             string for later re-formatting in the write_ex function.
             (build_float_string): Cleanup whitespace.
             (quadmath_snprintf): Likewise.
             (determine_en_precision): Likewise.

     gcc/testsuite/ChangeLog:

             * gfortran.dg/EXformat_1.f90: New test.
             * gfortran.dg/EXformat_2.f90: New test.

Reply via email to