J3/97-240
Date: 15 October 1997
To: J3
From: Larry Rolison
Subject: Interpretation Request: Value Returned by MAXVAL/MINVAL
NUMBER: 4
TITLE: Value returned by MAXVAL/MINVAL
KEYWORDS: MAXVAL, MINVAL
DEFECT TYPE: Interpretation
STATUS: X3J3 consideration in progress
QUESTION:
The Result Value section of the MAXVAL intrinsic function description uses the
phrasing:
or has the value of the negative number of the largest magnitude supported
by the processor for numbers of the type and kind type parameter of ARRAY
if ARRAY has size zero
This phrasing has generated at least the two following views on the return
value:
* If the machine supports the IEEE standard then the implementation should
return -inf.
* For portability, the implementation should return -HUGE(ARRAY).
These views lead to the following questions:
1. Is the intent of the standard to describe the result in terms of machine
values rather than model values?
2. If the answer to 1 is "yes", how are programmers expected to use this
intrinsic function portably?
ANSWER:
EDITS:
SUBMITTED BY: Larry Rolison
HISTORY: J3/97-240 m143 submitted
------------------------------------------------------------------------------
Date: Thu, 18 Sep 1997 13:38:50 -0500
[ From a coworker here at SGI/CRI ]
The first question boils down to: on an IEEE-like hardware platform
which has a bit pattern for -infinity, does this qualify as "a value ...
supported by the processor"? The result of MAXVAL must be of the same
type and kind as the argument. Since -infinity would only be possible if
the arguments were of type real, one would have to conclude that -infinity was
a valid real value. If that is true, then there would be at least one argument
for which some intrinsics (EXPONENT, FRACTION) would fail. Based on
this I would argue that returning -infinity should be invalid. I also
think it is unwise, based on the discussion below.
I think that the real problem is that there is no clean way to return a
"failed" status from MAXVAL. Both the -huge() and the -infinity methods
are defective attempts at solving that problem.
It is not clear that the choice of -infinity is in any way superior to
-HUGE(). If a machine allows -infinity, and all the tested elements in
the array were -infinity, then you would expect that -infinity would be
returned. But then is it the "answer" or is it an "error"? There is no
way to tell. Returning -HUGE() suffers from exactly the same defect.
I believe that there are a couple of drawbacks to the use of -infinity.
1) You might like to write code of the following form:
answer = maxval(array, mask=larray)
if (answer == xxxxx) then
! code for the case that all the elements in larray are .false.
else
! code the the cae that answer is a meaningful result
end if
What do you use for xxxxx? In the current model, -HUGE(array) should be
a workable and portable form. If the alternate -infinity version were
used, then there would have to be a way in Fortran to represent
-infinity. It's not clear that is always possible, and most likely not
in a portable fashion.
2) The MAXVAL function allows either real or integer arguments. On an
IEEE machine (for example) -infinity only has meaning for reals; the
concept of -infinity makes no sense for integer arguments. It seems an
unnecessary complication to have one scheme for reals and a different
one for integers.
----------------------------------------------------------------------------
Larry Rolison lrr@cray.com
Cray Research, A Silicon Graphics Company
655F Lone Oak Drive
Eagan, MN 55121
----------------------------------------------------------------------------