[Bug libfortran/48488] Wrong default format for real numbers
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48488 Thomas Henlich changed: What|Removed |Added Status|ASSIGNED|RESOLVED Resolution||FIXED --- Comment #9 from Thomas Henlich 2011-05-02 11:24:13 UTC --- Ok, the precision is now consistently the smallest value that ensures round-trip conversion for all values. It may not always look nice, but it fulfills the Fortran standard ("reasonable processor-dependent values of w, d, and e are used") with "reasonable" being defined by Pmin(bf) in IEEE 754/2008. It's the best we can do with this, so I'm closing this one.
[Bug libfortran/48488] Wrong default format for real numbers
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48488 --- Comment #7 from Janne Blomqvist 2011-04-29 16:03:57 UTC --- Author: jb Date: Fri Apr 29 16:03:54 2011 New Revision: 173170 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=173170 Log: PR 48488 Fix comments Modified: trunk/libgfortran/io/write.c
[Bug libfortran/48488] Wrong default format for real numbers
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48488 --- Comment #8 from Janne Blomqvist 2011-04-29 16:06:55 UTC --- Author: jb Date: Fri Apr 29 16:06:48 2011 New Revision: 173171 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=173171 Log: PR 48488 Typo Modified: trunk/libgfortran/io/write.c
[Bug libfortran/48488] Wrong default format for real numbers
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48488 --- Comment #6 from Janne Blomqvist 2011-04-29 15:58:23 UTC --- Author: jb Date: Fri Apr 29 15:58:20 2011 New Revision: 173169 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=173169 Log: PR 48488 Fix comments Modified: trunk/libgfortran/ChangeLog trunk/libgfortran/io/write.c
[Bug libfortran/48488] Wrong default format for real numbers
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48488 --- Comment #5 from Jerry DeLisle 2011-04-29 15:09:02 UTC --- Author: jvdelisle Date: Fri Apr 29 15:08:57 2011 New Revision: 173168 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=173168 Log: 2011-04-29 Jerry DeLisle PR libgfortran/48488 PR libgfortran/48602 PR libgfortran/48615 PR libgfortran/48684 PR libgfortran/48787 * gfortran.dg/fmt_g.f: Adjust test. * gfortran.dg/fmt_g0_1.f08: Adjust test. * gfortran.dg/round_3.f08: New test. * gfortran.dg/namelist_print_1.f: Adjust test. * gfortran.dg/char4_iunit_1.f03: Adjust test. * gfortran.dg/f2003_io_5.f03: Adjust test. * gfortran.dg/coarray_15.f90: Adjust test. * gfortran.dg/namelist_65.f90: Adjust test. * gfortran.dg/fmt_cache_1.f: Adjust test. * gfortran.dg/char4_iunit_2.f03: Adjust test. * gfortran.dg/real_const_3.f90: Adjust test. Added: trunk/gcc/testsuite/gfortran.dg/round_3.f08 Modified: trunk/gcc/testsuite/ChangeLog trunk/gcc/testsuite/gfortran.dg/char4_iunit_1.f03 trunk/gcc/testsuite/gfortran.dg/char4_iunit_2.f03 trunk/gcc/testsuite/gfortran.dg/coarray_15.f90 trunk/gcc/testsuite/gfortran.dg/f2003_io_5.f03 trunk/gcc/testsuite/gfortran.dg/fmt_cache_1.f trunk/gcc/testsuite/gfortran.dg/fmt_g.f trunk/gcc/testsuite/gfortran.dg/fmt_g0_1.f08 trunk/gcc/testsuite/gfortran.dg/namelist_65.f90 trunk/gcc/testsuite/gfortran.dg/namelist_print_1.f trunk/gcc/testsuite/gfortran.dg/real_const_3.f90
[Bug libfortran/48488] Wrong default format for real numbers
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48488 --- Comment #4 from Jerry DeLisle 2011-04-29 14:56:06 UTC --- Author: jvdelisle Date: Fri Apr 29 14:56:02 2011 New Revision: 173166 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=173166 Log: 2011-04-29 Jerry DeLisle Janne Blomqvist PR libgfortran/48488 PR libgfortran/48602 PR libgfortran/48615 PR libgfortran/48684 PR libgfortran/48787 * io/write.c (write_d, write_e, write_f, write_en, write_es): Add precision compemsation parameter to call. (set_fnode_default): Adjust default widths to assure round trip on write and read. (write_real): Adjust call to write_float. (write_real_g0): Calculate compensation for extra precision and adjust call to write_float. * io/write_float.def (output_float_FMT_G_): Use volatile rather than asm volatile to avoid optimization issue. Correctly calculate the number of blanks (nb) to be appended and simplify calculation logic. (write_float): Increase MIN_FIELD_WIDTH by one to accomodate the new default widths. Eliminate the code that attempted to reduce the the precision used in later sprintf functions. Add call parameter to compensate for extra precision. Modified: trunk/libgfortran/ChangeLog trunk/libgfortran/io/write.c trunk/libgfortran/io/write_float.def
[Bug libfortran/48488] Wrong default format for real numbers
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48488 Jerry DeLisle changed: What|Removed |Added Status|UNCONFIRMED |ASSIGNED Last reconfirmed||2011.04.08 23:54:07 AssignedTo|unassigned at gcc dot |jvdelisle at gcc dot |gnu.org |gnu.org Ever Confirmed|0 |1 --- Comment #3 from Jerry DeLisle 2011-04-08 23:54:07 UTC --- We have tried for b) up to now. A patch is simple enough.
[Bug libfortran/48488] Wrong default format for real numbers
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48488 --- Comment #2 from Thomas Henlich 2011-04-07 11:22:49 UTC --- Ok, now I found that this was changed in http://gcc.gnu.org/viewcvs?view=revision&revision=128967 The testcase says: > ! This tests that the default formats for formatted I/O of reals are > ! wide enough and have enough precision, by checking that values can > ! be written and read back. However, the selected width in the current version (8, 17, 20, 35) is not big enough to guarantee that. See IEEE 754/2008: For the purposes of discussing the limits on correctly rounded conversion, define the following quantities: ... ― for binary32, Pmin(binary32) = 9 ― for binary64, Pmin(binary64) = 17 ― for binary128, Pmin(binary128) = 36 ― for all other binary formats bf, Pmin(bf) = 1 + ceiling(p×log10(2)), where p is the number of significant bits in bf ... Conversions from a supported binary format bf to an external character sequence and back again results in a copy of the original number so long as there are at least Pmin(bf) significant digits specified and the rounding-direction attributes in effect during the two conversions are round to nearest rounding-direction attributes. I see two possibilities: A. We aim to make the default format useful for human readers, so that e.g. 0.3 is always represented as 0.3000... In that case we must choose P(bf) = floor(p×log10(2)) P = {7, 15, 19, 34} B. We aim to make the default format useful for round-trip conversion, so that a binary value is always converted to the same binary value. In that case we must choose P(bf) = 1 + ceiling(p×log10(2)) P = {9, 17, 21, 36} I personally prefer A. Currently the values are sort of in the middle (except for real64).
[Bug libfortran/48488] Wrong default format for real numbers
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48488 --- Comment #1 from Dominique d'Humieres 2011-04-07 09:08:01 UTC --- > In write.c the intended default format for real numbers is documented as: > > /* Output a real number with default format. >This is 1PG14.7E2 for REAL(4), 1PG23.15E3 for REAL(8), >1PG28.19E4 for REAL(10) and 1PG43.34E4 for REAL(16). */ > // FX -- FIXME: should we change the default format for __float128-real(16)? > > This is reasonable, since it reflects the rounded-down number of decimal > significant digits for each format: 7, 15, 19, 34. Thus any number with less > decimal digits than the maximum precision always retains its original decimal > value which is a useful feature. I think the error is in the documentation: the actual formats are 1PG16.8E2 for REAL(4), 1PG26.17E3 for REAL(8), 1PG30.20E4 for REAL(10) and 1PG45.35E4 for REAL(16) as shown by the following modified test print "(1PG16.8E2)", .3_4 print *, .3_4 print "(1PG26.17E3)", .3_8 print *, .3_8 print "(1PG30.20E4)", .3_10 print *, .3_10 print *, x10 print "(1PG45.35E4)", .3_16 print *, .3_16 end that gives 0.3001 0.3001 0.2 0.2 0.3001 0.3001 0.299 0.299 The values 8, 17, 20, and 35 (?see FIXME) are chosen such that reading the default output will always returns the original value up to the last bit. There is a test in the test suite checking that, but AFAIK not for all supported reals, in particular I don't think this has been tested for REAL(16).