http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47567
Summary: Wrong output for small absolute values with F editing
Product: gcc
Version: 4.6.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: libfortran
AssignedTo: [email protected]
ReportedBy: [email protected]
Fortran 2008, 10.7.2.3.2(9):
For an internal value that is neither an IEEE infinity nor a NaN, the output
field consists of blanks, if necessary, followed by a minus sign if the
internal value is negative, or an optional plus sign otherwise, followed by a
string of digits that contains a decimal symbol and represents the magnitude of
the internal value, as modified by the established scale factor and rounded
(10.7.2.3.7) to d fractional digits. Leading zeros are not permitted except
for an optional zero immediately to the left of the decimal symbol if the
magnitude of the value in the output field is less than one. The optional zero
shall appear if there would otherwise be no digits in the output field.
In gfortran, with an (F0.0) edit descriptor, some small values are formatted as
".", e.g.
print "(F0.0)", 0.0 ! => 0.
print "(F0.0)", 0.001 ! => . expected 0.
print "(F0.0)", 0.01 ! => . expected 0.
print "(F0.0)", 0.1 ! => 0.
Reason: "The optional zero shall appear if there would otherwise be no digits
in the output field."
Any formatting of non-negative values with (F1.n) should always result in
asterisks, because "a string of digits that contains a decimal symbol", where
"the optional zero shall appear if there would otherwise be no digits in the
output field" can never fit in 1. E. g.
print "(F1.0)", 0.0 ! => 0 expected *
print "(F1.0)", 0.001 ! => . expected *
print "(F1.0)", 0.01 ! => . expected *
print "(F1.0)", 0.1 ! => *
Similarly, for negative values and (F2.n):
print "(F2.0)", -0.001 ! => -. expected **
print "(F2.0)", -0.01 ! => -. expected **
print "(F2.0)", -0.1 ! => **
The exact value "0.0" is formatted with a leading zero with (F0.n) formatting,
but this is incorrect, see bug 47434:
print "(F0.2)", 0.0 ! => 0.00 expected .00