Re: About portable programming in fortran
From: Steven G. Kargl (kargl_at_troutmask.apl.washington.edu)
Date: 03/29/05
- Next message: James Van Buskirk: "Re: About portable programming in fortran"
- Previous message: James Giles: "Re: About portable programming in fortran"
- In reply to: James Giles: "Re: About portable programming in fortran"
- Next in thread: Kamaraju Kusumanchi: "Re: About portable programming in fortran"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Tue, 29 Mar 2005 00:52:59 +0000 (UTC)
In article <9i12e.475815$w62.338806@bgtnsc05-news.ops.worldnet.att.net>,
"James Giles" <jamesgiles@worldnet.att.net> writes:
> Steven G. Kargl wrote:
>> Don't use the specific names of the intrinsic procedures. That is,
>> don't use dabs, dsqrt, zsqrt, zexp, dexp. Actually, zsqrt and zexp
>> aren't specific names within the standard and aren't portable.
>>
>> Try
>>
>> program a
>> integer, parameter :: sp = kind(1.e0)
>> integer, parameter :: dp = kind(1.d0)
>> real(sp) s
>> real(dp) d
>> complex(sp) c
>> complex(dp) z
>> s = 1.e0_sp
>> d = 1.e0_dp
>> c = cmplx(1.e0_sp,0.e0_sp)
>> z = cmplx(1.e0_dp,0.e0_dp)
>> print *, sqrt(s), sqrt(d), sqrt(c), sqrt(z)
>> end program
>
> The above is incorrect. It is portable, but doesn't do as you
> expect. The two arg version of CMPLX *always* returns a
> single precision COMPLEX result. This is regardless of the
> precision of the arguments. Well, as it happens, zero and one
> are probably exactly represented in both single and double
> precision so you will almost certainly get away with this
> particular example. In general, you should always use the
> three argument form of CMPLX (or use something completely
> different) if the operands or result are expected to be of non-
> default KIND.
It was a one-off, quickly written example to show the
original poster the use of the generic names. The important
portion of the code is the print statement.
-- Steve http://troutmask.apl.washington.edu/~kargl/
- Next message: James Van Buskirk: "Re: About portable programming in fortran"
- Previous message: James Giles: "Re: About portable programming in fortran"
- In reply to: James Giles: "Re: About portable programming in fortran"
- Next in thread: Kamaraju Kusumanchi: "Re: About portable programming in fortran"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|