11-218
To: J3
From: Van Snyder
Subject: Interpretation request F03/0084 revisited
Date: 2011 June 30
----------------------------------------------------------------------
NUMBER: F03/0084
TITLE: IEEE_SET_ROUNDING_MODE in a subroutine
KEYWORDS: IEEE_ARITHMETIC
DEFECT TYPE: Interpretation
STATUS: J3 consideration in progress
QUESTION:
Section 7.1.7 of the Fortran 2008 standard says that if the value of an
expression can be determined before execution of the program, it is
standard-conforming to use the predetermined value.
Consider the subprogram
SUBROUTINE S()
USE, INTRINSIC :: IEEE_ARITHMETIC
USE, INTRINSIC :: IEEE_FEATURES
INTEGER, PARAMETER :: sp = IEEE_SELECTED_REAL_KIND(6,30)
real(sp) :: X = 0.5559013_sp
real(sp) :: Y = 1.2092481_sp
real(sp) :: Z1, Z2
IF (IEEE_SUPPORT_ROUNDING(IEEE_NEAREST,X) .AND. &
IEEE_SUPPORT_ROUNDING(IEEE_UP,X)) THEN
Z1 = X*Y
CALL IEEE_SET_ROUNDING_MODE(IEEE_NEAREST)
Z2 = X*Y
PRINT *, 'Residual: ', Z1 - Z2
ENDIF
END
(1) Is a processor permitted always to print zero for the residual
Z1 - Z2 ?
(2) Same question, after giving X and Y the PARAMETER attribute.
ANSWER:
(1) Yes. The processor is allowed to evaluate constant expressions in
any mathematically equivalent way. In particular, it is permitted to
evaluate using higher precision than any precision available when the
program is executed. For example, it might compute Z1 == Z2 ==
0.67222259081253, then compute Z1 - Z2 == 0.0, regardless of how the
program might do rounding at the seventh decimal digit when it is
executed.
(2) Yes, for the same reasons as question (1).
EDITS:
None.
SUBMITTED BY: Michael Ingrassia
HISTORY: 06-372 m178 F03/0084 submitted
11-xxx m195 Revised answer for Fortran 2008.
----------------------------------------------------------------------