This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug libfortran/48488] New: Wrong default format for real numbers


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)


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]