From jkr@jkr.cc.rl.ac.uk  Tue Mar 28 12:33:05 2000
Received: from nameserv.rl.ac.uk (nameserv.rl.ac.uk [130.246.135.129])
	by dkuug.dk (8.9.2/8.9.2) with ESMTP id MAA15828
	for <SC22WG5@dkuug.dk>; Tue, 28 Mar 2000 12:33:04 +0200 (CEST)
	(envelope-from jkr@jkr.cc.rl.ac.uk)
Received: from jkr.cc.rl.ac.uk (jkr.cc.rl.ac.uk [130.246.8.20])
	by nameserv.rl.ac.uk (8.8.8/8.8.8) with ESMTP id LAA16983
	for <SC22WG5@dkuug.dk>; Tue, 28 Mar 2000 11:33:00 +0100
Received: (from jkr@localhost)
	by jkr.cc.rl.ac.uk (8.8.8+Sun/8.8.8) id LAA11190
	for SC22WG5@dkuug.dk; Tue, 28 Mar 2000 11:34:06 +0100 (BST)
Date: Tue, 28 Mar 2000 11:34:06 +0100 (BST)
From: John Reid <J.Reid@letterbox.rl.ac.uk>
Message-Id: <200003281034.LAA11190@jkr.cc.rl.ac.uk>
To: SC22WG5@dkuug.dk
Subject: Interpretation 004
MIME-Version: 1.0
Content-Type: text/plain; charset="us-ascii"

Date: 28th March 2000
To: J3
From: John Reid
Subject: Interpretation 004

Here are drafts for the ANSWER and EDITS sections of 004. Also, I
propose that the addendum be removed. For your convenience, the current
004 is attached.

ANSWER:
Processors may support values that are not present in the model of
13.7.1. IEEE -inf is an example of such a number and this should be
returned on a machine that supports the IEEE standard.  If the negative
number of largest magnitude in the model had been intended, the model
would have been mentioned as, for example, in the definition of HUGE
(13.14.39).

A simple example of its use is to test whether a set of numbers SET1
has a value greater than any value in the set SET2. Consider the
expression MAXVAL(SET1)>MAXVAL(SET2). If SET1 is empty and SET2 is not,
this value is (correctly) false even if all the values are outside the
model with values less than -HUGE(SET1).

It may be helpful to consider how MAXVAL might be coded for an array
of rank one on an IEEE computer. The following code is suitable

     MAXVAL = IEEE_VALUE(1.0,IEEE_NEGATIVE_INF)
     DO I = 1, SIZE(ARRAY)
        MAXVAL = MAX(MAXVAL,ARRAY(I))
     END DO

EDITS: None. 


-------------------------------------------------------------------------------

NUMBER: 000004
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.
-------------------------------------------------------------------------------
