This is the mail archive of the fortran@gcc.gnu.org mailing list for the GNU Fortran 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]

Re: non-compatible round-off when printing for gfortran


I have extracted the following from the F2003 draft:

10.6.1.2.6 Rounding mode

The rounding mode can be specified by an OPEN statement (9.4.1), a data
transfer input/output statement (9.5.1.12), or an edit descriptor (10.7.7).

In what follows, the term "decimal value" means the exact 1 decimal number
as given by the character string, while the term "internal value" means the
number actually stored (typically in binary form) in the processor.  For
example, in dealing with the decimal constant 0.1, the decimal value is the
exact mathematical quantity 1/10, which has no exact representation on most
processors.  Formatted output of real data involves conversion from an
internal value to a decimal value; formatted input involves conversion from
a decimal value to an internal value.

When the I/O rounding mode is UP, the value resulting from conversion shall
be the smallest repre8 sentable value that is greater than or equal to the
original value.  When the I/O rounding mode is DOWN, the value resulting
from conversion shall be the largest representable value that is less than
or equal to the original value.  When the I/O rounding mode is ZERO, the
value resulting from conversion shall be the value closest to the original
value and no greater in magnitude than the original value.  When the I/O
rounding mode is NEAREST, the value resulting from conversion shall be the
closer of the two nearest representable values if one is closer than the
other.  If the two nearest representable values are equidistant from the
original value, it is processor dependent which one of them is chosen.
When the I/O rounding mode is COMPATIBLE, the value resulting from
conversion shall be the closer of the two nearest representable values or
the value away from zero if halfway between them.  When the I/O rounding
mode is PROCESSOR DEFINED, rounding during conversion shall be a processor
dependent default mode, which may correspond to one of the other modes.

On processors that support IEEE rounding on conversions, NEAREST shall
correspond to round to nearest, as specified in the IEEE International
Standard.

NOTE 10.14

On processors that support IEEE rounding on conversions, the I/O rounding
modes COMPATIBLE and NEAREST will produce the same results except when the
datum is halfway between the two representable values.  In that case,
NEAREST will pick the even value, but COMPATIBLE will pick the value away
from zero.  The I/O rounding modes UP, DOWN, and ZERO have the same effect
as those specified in the IEEE International Standard for round toward
+Infinity, round toward -Infinity, and round toward 0, respectively.

10.6.4.1.2 Generalized real and complex editing

I/O Rounding Mode r
COMPATIBLE 	0.5
NEAREST 	0.5 if the higher value is even
		-0.5 if the lower value is even
UP 		1
DOWN 		0
ZERO
		1 if internal value is negative
		0 if internal value is positive

		
10.7.7 RU, RD, RZ, RN, RC, and RP editing

The round edit descriptors temporarily change (9.4.1) the connection?s I/O
rounding mode (9.4.5.13, 9.5.1.12, 10.6.1.2.6).  The round edit descriptors
RU, RD, RZ, RN, RC, and RP set the I/O rounding mode corresponding to the
ROUND= specifier values UP, DOWN, ZERO, NEAREST, COMPATIBLE, and PROCESSOR
DEFINED, respectively.  The I/O rounding mode affects the conversion of
real and complex values in formatted input/output.  It affects only D, E,
EN, ES, F, and G editing.

It follows that the gfortran output mode is COMPATIBLE while xlf and g95
is NEAREST. This is the case since a quite long time (probably the time I have
shown on this list!-) and I got interested because this is the reason why
one of the test of the test suite fails with g95.

Dominique

PS 
> Perhaps, everyone should use gfortran on FreeBSD-*-amd64 :-)

why not OSX on PPC?-)


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