(j3.2006) Asymmetry of REAL, CMPLX

Kurt W Hirchert hirchert
Thu Jan 10 21:53:07 EST 2008

Van Snyder wrote:
> This does nothing for existing codes. Of those that have double
> precision arguments for CMPLX, and no kind argument, I'd bet at least a
> dollar that 98% of them are expecting a double precision result.  So
> introducing an incompatibility, to correct a blunder in the design of
> Fortran 90, does them a favor.
Unless my memory is failing me, you are 13 years off -- this was a 
"feature" of FORTRAN 77.  We wanted to do "the right thing" in Fortran 
90 but couldn't because that would have been incompatible with F77.

I'm not certain how much I trust your 98% estimate.  How many of those 
codes using CMPLX on double precision arguments predate Fortran 90?  
None of those should be expecting a double precision result, because F77 
didn't have double complex as a standard type.  If we were to change 
CMPLX now or in the future, we risk breaking codes that have been 
standard-conforming for more than a quarter century.  (Codes from that 
era that actually expected to produce a double complex result probably 
use the non-standard intrinsic DCMPLX.)

If we create a COMPLEX intrinsic as an alternative to CMPLX, I suspect 
we will see people switch to it, not because of the better symmetry, but 
because of the more natural spelling.

Rather than "fixing" existing codes by breaking other existing codes, it 
may be better to encourage compiler writers to generate warnings when 
programs do legal but questionable things.  If the result of applying 
CMPLX to double precision arguments is assigned to a single precision 
variable or in an operation combining it with another single precision 
value, then the reduction in precision probably does no harm and many 
well be exactly what the programmer wanted.  If the result is assigned 
to a double precision variable or combined with a double precision 
value, then the loss of precision likely is not what the programmer 
intended and a warning would be appropriate.  In general, a warning 
might be appropriate any time precision is reduced and then coerced back 
up, not just as a result of this particular intrinsic.


More information about the J3 mailing list