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

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).