Index Home About Blog
From: robert.corbett@sun.com (Robert Corbett)
Newsgroups: comp.lang.fortran
Subject: Re: What do you prefer: real(8) or double precision and why?
Date: 24 Aug 2004 21:41:15 -0700
Message-ID: <cb977dbc.0408242041.264ea84b@posting.google.com>

bv <bvoh@Xsdynamix.com> wrote in message news:<412BC788.6C9C13F0@Xsdynamix.com>...
>
> Why not keep it simple,
>
> 	real*8  a

A REAL FORTRANner.  You're not alone.  I estimate that about 80%
of the programs I have seen from Sun's users use star typing.
Many of those programs are still essentially FORTRAN 77 programs,
but even most programs written using what is otherwise good
Fortran 90/95 style use star typing.

Star typing is not part of the official standard, but it is a
defacto standard.  I know of implementations that didn't provide
star typing, but I don't know of any that are still in production.

                                          Sincerely,
                                          Bob Corbett


From: Richard Maine <nospam@see.signature>
Newsgroups: comp.lang.fortran
Subject: Re: What do you prefer: real(8) or double precision and why?
Date: 24 Aug 2004 11:09:03 -0700
Message-ID: <m1u0uswgqo.fsf@macfortran.local>

arimail77@yahoo.com (Arindam Chakraborty) writes:

>  Right now i always use
>      double precision :: a
>  in my FORTRAN 90 codes.
>
> But I am not sure if this is same as
>      real(8) :: a
> in FORTRAN 90.

It is compiler-dependent whether 8 is a valid kind number for
reals at all.  On some compilers, a kind of 8 will mean the same
thing as your double precision.  On others, it won't be a valid
kind at all and will fail compilation.  On some it might mean
the same thing as single precision, or mean some other precision.

> I am planning to switch from
>     double precision :: a
> to
>     integer, parameter :: WP=8
>     real(kind=WP) :: a
>
> I am curious to know what experienced FORTRAN 90
> programmers prefer and why?

Well, that's an improvement, but I'd go farther.  The reason that
is an improvement is that, assuming you put the definition of
WP in a module (or an include file will also do), it becomes a
one-line change if you want to convert everything to some other
precision...or if you need to use a different kind number on
different machines.  You might have to use a different number,
but at least it is easy to do so.  With the "double precision"
spelled out, it is considerably more work to do such a change.

On some compilers, you won't want double precision, because
single precision is already 64-bits for them.  Using double
precision in that case will be a 128-bit real, which will
just make everything bigger and slower.  The KIND mechanism
lets you use the same syntax to select a 64-bit real, regardless
of whether that happens to be single or double.

The step that I'd go farther is to use the selected_real_kind
intrinsic instead of the hard-wited value 8.  If you do something
more like

  integer, parameter :: WP = selected_real_kind(12,30)

then you will get excellent portability.  That will give you
a real that has at least 12 decimal digits of precision and
a range of at least 10**(-30) to 10**30.  Adjust as might be
appropriate for the application.  Anyway, this will generally get
you a 64-bit real.  You don't have to worry about whether that
is single or double precision or about what the particular
kind number for it is; this will work with *ALL* f90 compilers
that support a real at least that big (which is all f90 compilers
that exist now or are ever likely to).


--
Richard Maine                       |  Good judgment comes from experience;
email: my first.last at org.domain  |  experience comes from bad judgment.
org: nasa, domain: gov              |        -- Mark Twain

Index Home About Blog