J3/10-240
To: J3
From: Malcolm Cohen
Subject: Precise FP semantics of the REAL intrinsic
Date: 2010 October 12
----------------------------------------------------------------------
NUMBER: F03/0121
TITLE: Precise FP semantics of the REAL intrinsic
KEYWORDS: REAL intrinsic
DEFECT TYPE: Clarification
STATUS: J3 consideration in progress
QUESTION:
Must the intrinsic function REAL with KIND parameter wp return a value
that is a REAL (KIND=wp) floating point number?
RATIONALE FOR THE QUESTION:
Computer hardware may use a wider floating-point format for registers
than for memory; e.g., 80 bits for registers and 64 bits for memory
for the case of standard double precision floating point numbers.
Some algorithms require a high level of control over floating point
semantics. If the intrinsic function REAL with KIND parameter wp is
guaranteed to return a REAL (KIND=wp) result then a programmer can use
this to force intermediate results into main memory format, never mind
that the optimizing compiler may have placed the intermediate in a
register.
I am interested in a J3 interpretation of this matter, especially a
loud and clear affirmative interpretation, because it appears that
some present Fortran compilers optimize away my explicit use of the
REAL intrinsic. The context is code for compensated summation (Kahan
summation). I appreciate that parentheses are inviolable courtesy of
the Fortran standard, but in order to have code that cannot be broken
by an optimizing compiler I seem to need also a language mechanism to
force intermediate results into main memory format.
Bas Braams
Chemistry Department and
Emerson Center for Scientific Computation
Emory University
Atlanta, GA
ANSWER:
Yes, the result of the intrinsic function REAL with KIND argument wp
returns a value that is of type REAL(KIND=wp). However, the
description of REAL says that in this case
"the result is equal to a processor-dependent approximation to A".
Furthermore, if it is used within an expression involving intrinsic
operations,
"the processor may evaluate any mathematically equivalent
expression, provided that the integrity of parentheses is not
violated."
and
"mathematically equivalent expressions of numeric type may produce
different computational results",
which means that it is unlikely to serve your purpose.
Intermediate results can be rounded to storage format by using
assignment to a VOLATILE variable.
EDIT:
None.
HISTORY: 08-208r1 m185 F03/0121 submitted
10-nnn m193 Draft answer
----------------------------------------------------------------------