I'm going to display my ignorance here, but I've been following this thread
for a while and I am perplexed. What I do is define the following integer
parameters in a module:
Integer,parameter :: sp = kind(1.0e0),dp = kind(1.0d0)
Integer,parameter :: streal = sp ! standard precision.
!Integer,parameter :: streal = dp ! one of these commented out, depending on
! platform
Integer,parameter :: extreal = dp ! extended precision.
I always declare all reals to be real(streal), or real(extreal), depending
on my intentions. This way, you can declare accumulating variables to be
"extreal", and if it so happens that standard precision on the platform is
enough to handle everything (and double is slower due to lack of hardware
support, for example) then I simply declare
Integer,parameter :: extreal = sp
and the code is none the wiser. (The trick is that I _never_ overload based
on kind - too easy to create ambiguities.) I do agree with the poster in the
sense that saying "real :: x" is not enough for serious programs - too
little control over what precision x may or may not be.
My only regret with the way kind() is handled is precisely the fact that one
can create ambiguities where none were supposed to exist - i.e. overloading
based on kind may not work depending on the processor. On a PC, for example,
I want to use double precision always; but on a Cray (when I dealt with
them) double was slow, and single was a PCs double.
Alvaro Fernandez
-----Original Message-----
From: Fortran 90 List [mailto:[log in to unmask]] On Behalf Of
[log in to unmask]
Sent: Sunday, March 07, 2004 11:28 AM
To: [log in to unmask]
Subject: Re: configurable default real
James Giles wrote:
> [log in to unmask] wrote:
> ...
> > Yes, but it introduces new problems when there is no obvious
> > way to correct a "mistake" do to this promotion.
> >
> > Things like
> > call expects_a_single_precision_arg (3.14)
> > or
> > call expects_a_single_precision_arg (3.14*single_prec_variable)
> > or
> > single_prec = max(single_prec, 1.0)
> >
> > For good or for bad, Fortran has a ton of rules about what types
> > can be used where and what the results of mixed type operations
> > are, and trying to change (or even improve) them will make old
> > programs fail in strange ways.
>
> Well, of course "old programs" won't use the new syntax that says
> to assume all KINDless literals are of some particular precision.
Umm, Yes and no. Old programs are often modified as time goes along.
Adding new syntax like IMPLICIT NONE to an old program as part of the
enhance/modify/maintain/fool-around-with cycle is a good thing to do
because it detects potential bugs at compile time. Adding syntax
like IMPLICIT TREAT ALL REAL LITERALS AS DOUBLE is riskier
because it could silently break something that works. Sure, everybody
who modifies a program should read the whole thing through and
understand everything, but ....
I think adding some sort of default literal to Fortran is a very
good idea and it's too bad it didn't happen earlier. It's just not
trivial to do it in a way that is reasonably consistent with the
way people code in real life.
Dick Hendrickson
|