Everyone:
There is no need for a drand() function that calls Random_Number(). By rule, the
intrinsic subroutine Random_Number() is generic. It returns a result of type real of the
kind of the argument.
If you need confirmation of this, please look carefully at the description of the
argument. The standard says, "HARVEST shall be of type real." It does NOT say, "default
real". Since "type real" is unqualified, that means ANY kind of real supported by the
processor. Thus, if the actual argument is DP, you get a DP result. If your Fortran
compiler supports quad precision (often spelled Real (Kind=16)), then if you give
Random_Number() a QP argument, you get a QP result.
Reference: Fortran 2008 standard, section 13.7.135.
Sincerely,
Craig T. Dedo
17130 W. Burleigh Place
P. O. Box 423 Mobile Phone: (414) 412-5869
Brookfield, WI 53008-0423 E-mail: <[log in to unmask]>
USA
Linked-In: http://www.linkedin.com/in/craigdedo
> -----Original Message-----
> From: Fortran 90 List [mailto:[log in to unmask]] On Behalf Of Adriano
> Amaricci
> Sent: Wednesday, November 16, 2011 09:18
> To: [log in to unmask]
> Subject: Re: sorting eigenvalues of a complex nonsymmetric matrix
>
> No reason in particular I would say. It is an old code and perhaps I was not aware
> that double precision random number was available.
>
> Anyway, thanks for pointing this out. I'll updated it.
>
> Cheers,
> AA
>
>
> On Wed, Nov 16, 2011 at 4:06 PM, W.J. Metzger <[log in to unmask]> wrote:
> > Why do you convert a single-precision random number to double
> > precision when you can generate a double-precision random number directly?
> >
> > !---------------------------------------------!
> > function drand()
> > implicit none
> > real(8) :: r
> > call random_number(r)
> > drand = r
> > end function drand
> > !---------------------------------------------!
> >
> > Cheers, Wes
> >
> > On Wed, 16 Nov 2011, Adriano Amaricci wrote:
> >
> >> !---------------------------------------------!
> >> function drand()
> >> implicit none
> >> real(8) :: drand
> >> real(4) :: r
> >> call random_number(r)
> >> drand=dble(r)
> >> end function drand
> >> !---------------------------------------------!
> >
|