When using the EN descriptor with d=0 (ENw.0) and rounding mode UP or DOWN the result is totally wrong: program test_en print "(RU,EN9.0)", 800.0_8 ! 8.E+00 expected 800.E+00 print "(RU,EN9.0)", 901.0_8 ! 10.E+00 expected 901.E+00 print "(RD,EN9.0)", -999.6_8 ! -10.E+00 expected -1.E+03 end
Confirmed since at least GCC7.
--- ../_clean/libgfortran/io/write_float.def 2020-06-13 03:11:55.000000000 +0200 +++ libgfortran/io/write_float.def 2020-07-19 22:46:57.000000000 +0200 @@ -399,7 +399,7 @@ build_float_string (st_parameter_dt *dtp updown: rchar = '0'; - if (ft != FMT_F && w > 0 && d == 0 && p == 0) + if (ft != FMT_F && ft !=FMT_EN && 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++) should do the trick. I am currently try to reuse gfortran.dg/fmt_en.f90 for a more general testing.
Created attachment 48894 [details] Extensive test with RU and EN
Created attachment 48895 [details] Extensive test with RD and EN It would be nice to check that I did not make any mistake.
Created attachment 48909 [details] Extensive test with RZ and EN
Created attachment 48910 [details] Extensive test with RN and EN
Could someone used to git commit the fix and the tests and back port them to all the active branches?
(In reply to Dominique d'Humieres from comment #7) > Could someone used to git commit the fix and the tests and back port them to > all the active branches? I think the normal procedure would be to submit this for review first.
Patch submitted at https://gcc.gnu.org/pipermail/fortran/2020-July/054769.html.
The patch applies and regtest cleanly down to GCC8. IMO this is nasty wrong code and it should be fixed on all the active branches.
The master branch has been updated by Thomas Kथà¤nig <tkoenig@gcc.gnu.org>: https://gcc.gnu.org/g:05e0971bcf94a481cbfa2731484f024a67dbd4a5 commit r11-2309-g05e0971bcf94a481cbfa2731484f024a67dbd4a5 Author: Dominique d'Humieres <dhumieres.dominique@free.fr> Date: Fri Jul 24 20:07:12 2020 +0200 PR 93592 - Invalid UP/DOWN rounding with EN descriptor. The fix is obvious (I have added a comment). The tests are probably an overkill, but it does not hurt. libgfortran/ChangeLog: PR fortran/93592 * io/write_float.def (build_float_string): Do not reset nbefore for FMT_F and FMT_EN. gcc/testsuite/ChangeLog: PR fortran/93592 * gfortran.dg/fmt_en.f90: Adjust test. * gfortran.dg/fmt_en_rd.f90: New test. * gfortran.dg/fmt_en_rn.f90: New test. * gfortran.dg/fmt_en_ru.f90: New test. * gfortran.dg/fmt_en_rz.f90: New test.
The releases/gcc-10 branch has been updated by Thomas Kथà¤nig <tkoenig@gcc.gnu.org>: https://gcc.gnu.org/g:b45f51d467c6c192c70f57e517bec3a3c0c9d1f4 commit r10-8531-gb45f51d467c6c192c70f57e517bec3a3c0c9d1f4 Author: Dominique d'Humieres <dhumieres.dominique@free.fr> Date: Fri Jul 24 20:07:12 2020 +0200 PR 93592 - Invalid UP/DOWN rounding with EN descriptor. The fix is obvious (I have added a comment). The tests are probably an overkill, but it does not hurt. libgfortran/ChangeLog: PR fortran/93592 * io/write_float.def (build_float_string): Do not reset nbefore for FMT_F and FMT_EN. gcc/testsuite/ChangeLog: PR fortran/93592 * gfortran.dg/fmt_en.f90: Adjust test. * gfortran.dg/fmt_en_rd.f90: New test. * gfortran.dg/fmt_en_rn.f90: New test. * gfortran.dg/fmt_en_ru.f90: New test. * gfortran.dg/fmt_en_rz.f90: New test. (cherry picked from commit 05e0971bcf94a481cbfa2731484f024a67dbd4a5)
The releases/gcc-9 branch has been updated by Thomas Kथà¤nig <tkoenig@gcc.gnu.org>: https://gcc.gnu.org/g:eca316afa46907e6b0e1513ecbc3010aaf2590f3 commit r9-8765-geca316afa46907e6b0e1513ecbc3010aaf2590f3 Author: Dominique d'Humieres <dhumieres.dominique@free.fr> Date: Fri Jul 24 20:07:12 2020 +0200 PR 93592 - Invalid UP/DOWN rounding with EN descriptor. The fix is obvious (I have added a comment). The tests are probably an overkill, but it does not hurt. libgfortran/ChangeLog: PR fortran/93592 * io/write_float.def (build_float_string): Do not reset nbefore for FMT_F and FMT_EN. gcc/testsuite/ChangeLog: PR fortran/93592 * gfortran.dg/fmt_en.f90: Adjust test. * gfortran.dg/fmt_en_rd.f90: New test. * gfortran.dg/fmt_en_rn.f90: New test. * gfortran.dg/fmt_en_ru.f90: New test. * gfortran.dg/fmt_en_rz.f90: New test. (cherry picked from commit 05e0971bcf94a481cbfa2731484f024a67dbd4a5)
The releases/gcc-8 branch has been updated by Thomas Kथà¤nig <tkoenig@gcc.gnu.org>: https://gcc.gnu.org/g:1757a63809d6c6073c87978c22dcfffe85753c0f commit r8-10375-g1757a63809d6c6073c87978c22dcfffe85753c0f Author: Dominique d'Humieres <dhumieres.dominique@free.fr> Date: Fri Jul 24 20:07:12 2020 +0200 PR 93592 - Invalid UP/DOWN rounding with EN descriptor. The fix is obvious (I have added a comment). The tests are probably an overkill, but it does not hurt. libgfortran/ChangeLog: PR fortran/93592 * io/write_float.def (build_float_string): Do not reset nbefore for FMT_F and FMT_EN. gcc/testsuite/ChangeLog: PR fortran/93592 * gfortran.dg/fmt_en.f90: Adjust test. * gfortran.dg/fmt_en_rd.f90: New test. * gfortran.dg/fmt_en_rn.f90: New test. * gfortran.dg/fmt_en_ru.f90: New test. * gfortran.dg/fmt_en_rz.f90: New test. (cherry picked from commit 05e0971bcf94a481cbfa2731484f024a67dbd4a5)
Patch committed to all the active branches. Closing. Tanks for the report.