Changing the Intrinsic Functions MAX and MIN

The intrinsic functions MAX and MIN have an arbitrary number of arguments. In the emulated code, each argument may be an emulated real number or a native literal real number. Further, as a widely used extension to the Fortran standard, the arguments may be of different real kinds. This leads to a factorial explosion of the number of functions which must be written to overload MAX and MIN.

The code for invocations of MAX and MIN is therefore modified as follows:

  1. A check is made that no more than one of the arguments is a literal real value. If two or more arguments are literal reals, the MAX or MIN of the literals is computed and the appropriate value is left in place. The others are removed. It makes no sense to write a = MAX(1.0, b, 2.0) although it is perfectly legal to do so.

  2. The kind of every argument is examined, and all of the arguments are converted to the kind with the highest precision. This is the observed behaviour of the compilers which have been examined. The return value is of this kind.

If r8 is an 8-byte real number and r4 is a 4-byte real number, the statement

r8 = MAX(r4, 0.0, r8)

is replaced by

r8 = MAX(DBLE(r4), 0.0D0, r8)