J3/97-207
Date: 1997 August 01
To: J3
From: Loren P. Meissner
Subject: Edits for M.5: Extend Max and Min Intrinsics to Character Type
References: X3J3/96-007r1, X3J3/96-131r1, J3/97-156r1
PROPOSAL:
Extend the intrinsic functions Max, Min, MaxLoc, MinLoc, MaxVal, and MinVal to
accept arguments of character data type.
PROPOSED ADDITIONAL EDITS:
[218:14+] Add paragraph:
The arguments to MAX or MIN may be character expressions. The largest or
smallest character value is the one that would be selected by application of
intrinsic relational operators: i.e., the processor collating sequence is
applied.
[221: 24+] Add paragraph:
The argument of MAXVAL or MINVAL may be a character array. The largest or
smallest character value is the one that would be selected by application of
intrinsic relational operators: i.e., the processor collating sequence is
applied.
[222: 11+] Add paragraph:
The argument of MAXLOC or MINLOC may be a character array. The largest or
smallest character value is the one that would be selected by application of
intrinsic relational operators: i.e., the processor collating sequence is
applied.
[252: 28] Add sentence: For character arguments, if the selected argument is
shorter than the longest argument the result is padded with blanks on the
right to the length of the longest argument.
[252: 29] Add examples: MAX ("Z", "BB") is "Z#", and MAX ( (/ "A", "Z" /), (/
"BB", "Y" /) ) is (/ "BB", "Z#" /), where # represents a blank character.
[255: 15] Add sentence: For character arguments, if the selected argument is
shorter than the longest argument the result is padded with blanks on the
right to the length of the longest argument.
[252: 16] Add examples: MIN ("A", "YY") is "A#", and MIN ( (/ "Z", "A" /), (/
"YY", "B" /) ) is (/ "YY", "A#" /), where # represents a blank character.
============================================================
EDITS APPROVED AT MEETING 141:
MAX (13.14.64):
[252:25] Change "shall be integer or real" to "shall be integer, real, or
character"
[252:27] Change "Result Characteristics" to:
Result Characteristics. Type and kind type parameter are the same as the
arguments. For arguments of character type, the length of the result is the
length of the longest argument.
MAXLOC (13.14.66):
[253:3] Change "shall be of type integer or real" to "shall be of type
integer, real, or character"
MAXVAL (13.14.67):
[254:6] Change "shall be of type integer or real" to "shall be of type
integer, real, or character"
[254:11] Change "The result is of the same type and kind type parameter as
ARRAY" to "The result is of the same type and type parameters as ARRAY"
[254:16-24] Replace Result Value Case(i) and Case (ii) as follows (no change
to Case(iii)):
Case(i): If the size of ARRAY is not zero, the result of MAXVAL (ARRAY) has a
value equal to the maximum value of all the elements of ARRAY. If ARRAY has
size zero and type integer or real, the result of MAXVAL (ARRAY) 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
and type character, the result of MAXVAL (ARRAY) has the value of a string of
characters of length LEN (ARRAY) with each character equal to CHAR (0, KIND =
KIND (ARRAY)).
Case(ii): The result of MAXVAL (ARRAY, MASK = MASK), if MASK has at least one
true element, has a value equal to the maximum value of the elements of ARRAY
corresponding to true elements of MASK. If MASK has no true elements and the
type of ARRAY is integer or real, the result of MAXVAL (ARRAY, MASK = MASK)
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 MASK
has no true elements and the type of ARRAY is character, the result of MAXVAL
(ARRAY, MASK = MASK) has the value of a string of characters of length LEN
(ARRAY) with each character equal to CHAR (0, KIND = KIND (ARRAY)).
MIN (13.14.69):
[255:12] Change "shall be integer or real" to "shall be integer, real, or
character"
[255:14] Change "Result Characteristics" to:
Result Characteristics. Type and kind type parameter are the same as the
arguments. For arguments of character type, the length of the result is the
length of the longest argument.
MINLOC (13.14.71):
[255:32] Change "shall be of type integer or real" to "shall be of type
integer, real, or character"
MINVAL (13.14.72):
[256:39] Change "shall be of type integer or real" to "shall be of type
integer, real, or character"
[256:44] Change "The result is of the same type and kind type parameter as
ARRAY" to "The result is of the same type and type parameters as ARRAY"
[257:4-12] Replace Result Value Case(i) and Case (ii) as follows (no change
to Case(iii)):
Case(i): If the size of ARRAY is not zero, the result of MINVAL (ARRAY) has a
value equal to the minimum value of all the elements of ARRAY. If ARRAY has
size zero and type integer or real, the result of MINVAL (ARRAY) has the value
of the positive 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
and type character, the result of MINVAL (ARRAY) has the value of a string of
characters of length LEN (ARRAY) with each character equal to CHAR (n - 1,
KIND = KIND (ARRAY)) where n is the number of characters in the collating
sequence for characters with the kind type parameter of ARRAY.
Case(ii): The result of MINVAL (ARRAY, MASK = MASK), if MASK has at least one
true element, has a value equal to the minimum value of the elements of ARRAY
corresponding to true elements of MASK. If MASK has no true elements and the
type of ARRAY is integer or real, the result of MINVAL (ARRAY, MASK = MASK)
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 MASK
has no true elements and the type of ARRAY is character, the result of MINVAL
(ARRAY, MASK = MASK) has the value of a string of characters of length LEN
(ARRAY) with each character equal to CHAR (n - 1, KIND = KIND (ARRAY)) where n
is the number of characters in the collating sequence for characters with the
kind type parameter of ARRAY.
BACKGROUND:
Specification and Syntax were approved at Meeting 138 (August 1996) - see
X3J3/96-131r1. Edits were approved at Meeting 141 (May 1997). It was suggested
that additional informative text be incorporated.
This Minor Technical Enhancement adds text to the specifications of several
Max and Min intrinsic functions mentioned, to permit ordering of character
arguments in a manner that is consistent with character relational operators:
for example, when A and B are character strings Max (A, B) returns a string
equivalent to A if the relational expression A > B is true. Max and Min are
applied elementally with padding to the longest argument, and are consistent
with relational operators. For example, the value of
Max ((/ A, Z /), (/ BB, YY /))
is
(/ BB, Z# /)
where # denotes a blank character.
For integer or real arrays with no elements (after masking), Fortran 95
defines MaxVal as "the negative number of the largest magnitude supported by
the processor" and MinVal as "the positive number of the largest magnitude
supported by the processor" {and not as Huge, the largest model number}. A
similar concept is needed for character arrays with no elements. For the
implementation suggested here, the "most negative" value corresponds to a
string of characters all equal to Char (0) and the "most positive" value
corresponds to a string of characters all equal to Char (n - 1) where n is the
number of characters in the collating sequence for the kind type parameter of
the argument array. Similar terminology appears in the current definition of
Char.
Regularity is the primary reason for this extension. In Fortran 95, these
intrinsic functions accept arguments of the other two ordered intrinsic types,
integer and real. This extension recognizes character data type as a
first-class type and extends the ordering intrinsics so that they accept all
intrinsic types for which they make sense. This extension facilitates
constuction of families of similar routines in applications (such as sorting)
for integer, real, and character data.