Re: Caught out by cmplx



"James Van Buskirk" <not_valid@xxxxxxxxxxx> wrote in message news:hb27ru$ee7$1@xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
| "albert" <acp693@xxxxxxxxxxx> wrote in message
| news:387c5515-d35c-4ff6-a9a9-dc6b82be849b@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
| > I recently discovered that the precision of my code was being
| > compromised by my use of the intrinsic function Cmplx. The output of
| > this function doesn't assume the precision of the inputs to it, as far
| > as I have seen most other functions such as Abs, Real, Aimag, etc. do
| > so. One has to state the precision explicitly with an extra input.
| > I have fixed the problem in my code by replacing Cmplx with Dcmplx.
|
| > Does anyone know why the decision was made to let Cmplx default to
| > single precision irrespective of the precision of it's inputs?
|
| There are a couple of reasons. CMPLX, like REAL, can convert variables
| of the same type to different kinds. Also CMPLX was defined to
| return a single-precision complex result in f77 because f77 didn't
| define a double precision complex kind. If this were changed with
| f90, programs would behave differently and this would violate
| compatibility.

Compatability with F77 could be maintained as well as providing
a proper generic CMPLX, merely by providing an option.

That could (and should) have been done from F90, when generic functions
were introduced.


.



Relevant Pages

  • Re: fftw - loosing accuracy in cosine transform
    ... > the CMPLX intrinsic, the KIND of the result defaults to KIND? ... > double precision flavor of COS) you would be the happier. ... accuracy as that of the usual fourier transform. ...
    (comp.lang.fortran)
  • Re: complex arithmetics
    ... CMPLX existed as a generic in f77. ... > only precision available, even when the arguments were double. ... Walt Spector ...
    (comp.lang.fortran)
  • Re: Caught out by cmplx
    ... Does anyone know why the decision was made to let Cmplx default to ... single precision irrespective of the precision of it's inputs? ... (big snip) ... code with a new feature using features not available in Fortran 77. ...
    (comp.lang.fortran)
  • Re: How can I use dreal and dimag in a f90 program?
    ... Richard Maine wrote: ... precision, but COMPLEXis single precision. ... being no double complex prior to f90. ... And note it is cmplx. ...
    (comp.lang.fortran)
  • Re: Caught out by cmplx (yet again)
    ... Cmplx is generic; ... Robin probably has ... for the f77 version of CMPLXto have taken only real arguments. ... for double precision arguments, ...
    (comp.lang.fortran)