J3/06-372
Date: October 31, 2006
To: J3
From: Michael Ingrassia
Subject: IEEE rounding
NUMBER: F03/0084
TITLE: IEEE_SET_ROUNDING_MODE in a subroutine
DEFECT TYPE: CLARIFICATION/ERRATUM
STATUS: J3 consideration in progress
QUESTION:
Section 7.1.8.1 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) :: Z
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) No, for a high quality implementation.
Given that the processor supports execution with both
rounding modes IEEE_NEAREST and IEEE_UP, this subprogram
might be executed in either rounding mode (since the rounding
mode is inherited from the caller, see [367:20-22]), and the value
zero is a bad approximation in the latter case.
No edits are necessary.
(2) Yes. In this case "X*Y" is an initialization expression, whose value does
not change from one appearance to the next.
EDITS:
Note 14.6 should note additionally that the value of an
initialization expression is not affected by changes in the rounding mode.
SUBMITTED BY: Michael Ingrassia
HISTORY: J3/06-372 at meeting 178