public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libfortran/48488] New: Wrong default format for real numbers
@ 2011-04-07 8:23 thenlich at users dot sourceforge.net
2011-04-07 9:08 ` [Bug libfortran/48488] " dominiq at lps dot ens.fr
` (8 more replies)
0 siblings, 9 replies; 10+ messages in thread
From: thenlich at users dot sourceforge.net @ 2011-04-07 8:23 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48488
Summary: Wrong default format for real numbers
Product: gcc
Version: 4.7.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: libfortran
AssignedTo: unassigned@gcc.gnu.org
ReportedBy: thenlich@users.sourceforge.net
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.
But it is implemented incorrectly as the following example shows:
print "(1PG14.7E2)", .3_4 ! 0.3000000
print *, .3_4 ! 0.30000001 expected 0.3000000
print "(1PG23.15E3)", .3_8 ! 0.300000000000000
print *, .3_8 ! 0.29999999999999999 expected 0.300000000000000
print "(1PG28.19E4)", .3_10 ! 0.3000000000000000000
print *, .3_10 ! 0.30000000000000000001 expected (s.a.)
print "(1PG43.34E4)", .3_16 ! 0.300000000000000000000000000000000
print *, .3_16 ! 0.29999999999999999999999999999999999 exp. (s.a)
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug libfortran/48488] Wrong default format for real numbers
2011-04-07 8:23 [Bug libfortran/48488] New: Wrong default format for real numbers thenlich at users dot sourceforge.net
@ 2011-04-07 9:08 ` dominiq at lps dot ens.fr
2011-04-07 11:22 ` thenlich at users dot sourceforge.net
` (7 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: dominiq at lps dot ens.fr @ 2011-04-07 9:08 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48488
--- Comment #1 from Dominique d'Humieres <dominiq at lps dot ens.fr> 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.30000001
0.30000001
0.29999999999999999
0.29999999999999999
0.30000000000000000001
0.30000000000000000001
0.29999999999999999999999999999999999
0.29999999999999999999999999999999999
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).
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug libfortran/48488] Wrong default format for real numbers
2011-04-07 8:23 [Bug libfortran/48488] New: Wrong default format for real numbers thenlich at users dot sourceforge.net
2011-04-07 9:08 ` [Bug libfortran/48488] " dominiq at lps dot ens.fr
@ 2011-04-07 11:22 ` thenlich at users dot sourceforge.net
2011-04-08 23:54 ` jvdelisle at gcc dot gnu.org
` (6 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: thenlich at users dot sourceforge.net @ 2011-04-07 11:22 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48488
--- Comment #2 from Thomas Henlich <thenlich at users dot sourceforge.net> 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).
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug libfortran/48488] Wrong default format for real numbers
2011-04-07 8:23 [Bug libfortran/48488] New: Wrong default format for real numbers thenlich at users dot sourceforge.net
2011-04-07 9:08 ` [Bug libfortran/48488] " dominiq at lps dot ens.fr
2011-04-07 11:22 ` thenlich at users dot sourceforge.net
@ 2011-04-08 23:54 ` jvdelisle at gcc dot gnu.org
2011-04-29 14:57 ` jvdelisle at gcc dot gnu.org
` (5 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: jvdelisle at gcc dot gnu.org @ 2011-04-08 23:54 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48488
Jerry DeLisle <jvdelisle at gcc dot gnu.org> 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 <jvdelisle at gcc dot gnu.org> 2011-04-08 23:54:07 UTC ---
We have tried for b) up to now. A patch is simple enough.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug libfortran/48488] Wrong default format for real numbers
2011-04-07 8:23 [Bug libfortran/48488] New: Wrong default format for real numbers thenlich at users dot sourceforge.net
` (2 preceding siblings ...)
2011-04-08 23:54 ` jvdelisle at gcc dot gnu.org
@ 2011-04-29 14:57 ` jvdelisle at gcc dot gnu.org
2011-04-29 15:18 ` jvdelisle at gcc dot gnu.org
` (4 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: jvdelisle at gcc dot gnu.org @ 2011-04-29 14:57 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48488
--- Comment #4 from Jerry DeLisle <jvdelisle at gcc dot gnu.org> 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 <jvdelisle@gcc.gnu.org>
Janne Blomqvist <jb@gcc.gnu.org>
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
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug libfortran/48488] Wrong default format for real numbers
2011-04-07 8:23 [Bug libfortran/48488] New: Wrong default format for real numbers thenlich at users dot sourceforge.net
` (3 preceding siblings ...)
2011-04-29 14:57 ` jvdelisle at gcc dot gnu.org
@ 2011-04-29 15:18 ` jvdelisle at gcc dot gnu.org
2011-04-29 16:00 ` jb at gcc dot gnu.org
` (3 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: jvdelisle at gcc dot gnu.org @ 2011-04-29 15:18 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48488
--- Comment #5 from Jerry DeLisle <jvdelisle at gcc dot gnu.org> 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 <jvdelisle@gcc.gnu.org>
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
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug libfortran/48488] Wrong default format for real numbers
2011-04-07 8:23 [Bug libfortran/48488] New: Wrong default format for real numbers thenlich at users dot sourceforge.net
` (4 preceding siblings ...)
2011-04-29 15:18 ` jvdelisle at gcc dot gnu.org
@ 2011-04-29 16:00 ` jb at gcc dot gnu.org
2011-04-29 16:07 ` jb at gcc dot gnu.org
` (2 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: jb at gcc dot gnu.org @ 2011-04-29 16:00 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48488
--- Comment #6 from Janne Blomqvist <jb at gcc dot gnu.org> 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
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug libfortran/48488] Wrong default format for real numbers
2011-04-07 8:23 [Bug libfortran/48488] New: Wrong default format for real numbers thenlich at users dot sourceforge.net
` (5 preceding siblings ...)
2011-04-29 16:00 ` jb at gcc dot gnu.org
@ 2011-04-29 16:07 ` jb at gcc dot gnu.org
2011-04-29 16:10 ` jb at gcc dot gnu.org
2011-05-02 11:30 ` thenlich at users dot sourceforge.net
8 siblings, 0 replies; 10+ messages in thread
From: jb at gcc dot gnu.org @ 2011-04-29 16:07 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48488
--- Comment #8 from Janne Blomqvist <jb at gcc dot gnu.org> 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
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug libfortran/48488] Wrong default format for real numbers
2011-04-07 8:23 [Bug libfortran/48488] New: Wrong default format for real numbers thenlich at users dot sourceforge.net
` (6 preceding siblings ...)
2011-04-29 16:07 ` jb at gcc dot gnu.org
@ 2011-04-29 16:10 ` jb at gcc dot gnu.org
2011-05-02 11:30 ` thenlich at users dot sourceforge.net
8 siblings, 0 replies; 10+ messages in thread
From: jb at gcc dot gnu.org @ 2011-04-29 16:10 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48488
--- Comment #7 from Janne Blomqvist <jb at gcc dot gnu.org> 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
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug libfortran/48488] Wrong default format for real numbers
2011-04-07 8:23 [Bug libfortran/48488] New: Wrong default format for real numbers thenlich at users dot sourceforge.net
` (7 preceding siblings ...)
2011-04-29 16:10 ` jb at gcc dot gnu.org
@ 2011-05-02 11:30 ` thenlich at users dot sourceforge.net
8 siblings, 0 replies; 10+ messages in thread
From: thenlich at users dot sourceforge.net @ 2011-05-02 11:30 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48488
Thomas Henlich <thenlich at users dot sourceforge.net> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|ASSIGNED |RESOLVED
Resolution| |FIXED
--- Comment #9 from Thomas Henlich <thenlich at users dot sourceforge.net> 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.
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2011-05-02 11:30 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-04-07 8:23 [Bug libfortran/48488] New: Wrong default format for real numbers thenlich at users dot sourceforge.net
2011-04-07 9:08 ` [Bug libfortran/48488] " dominiq at lps dot ens.fr
2011-04-07 11:22 ` thenlich at users dot sourceforge.net
2011-04-08 23:54 ` jvdelisle at gcc dot gnu.org
2011-04-29 14:57 ` jvdelisle at gcc dot gnu.org
2011-04-29 15:18 ` jvdelisle at gcc dot gnu.org
2011-04-29 16:00 ` jb at gcc dot gnu.org
2011-04-29 16:07 ` jb at gcc dot gnu.org
2011-04-29 16:10 ` jb at gcc dot gnu.org
2011-05-02 11:30 ` thenlich at users dot sourceforge.net
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).