Depends on what you want, of course. The first version requests a minimum
precision for REAL_8. If the compiler can accommodate it in its basic
precision, it will do so. If it requires a "non-standard" (I don't mean the
Fortran standard here), like quadruple precision (because, for example, your
machine has an unusual split between mantissa and exponent), it will use
that. If it can't, it will complain.
Advantage: You get the precision you request. If it can be done in single
precision, you don't waste memory and CPU time. If not even double precision
is good enough, you get something better (if available).
Disadvantage: You may get into trouble with libraries (e.g. blas) on
machines where your request is for a non-default storage size. You may get
something really slow (like quadruple precision).
The second request is for what your compiler considers "double precision".
The Fortran standard requires at least two real storage formats, and this is
the more accurate one. Whatever it may be.
Advantage: It's always available, and there are probably libraries for it.
Disadvantage: You don't know exactly what precision you get. You may use 128
bits on a machine with 64-bit basic precision, even though you don't need
that. Or you actually expected more precision than a certain platform will
give you.
What's recommended.. No idea. I generally prefer double precision, with
#ifdef (not Fortran, but generally available) for 64-bit single precision
machines. But that's just me being old-fashioned and performance conscious.
The selected_real_kind approach is more platform independent, so it's
probably more in the spirit of "modern" Fortran.
Herbert
-----Original Message-----
From: Blackwell, Bennie F [mailto:[log in to unmask]]
Sent: 12 February 2003 14:33
To: [log in to unmask]
Subject: preferred way of setting precision in F90
I have seen (and used) the following two ways of setting machine precision.
What is recommended way and why?
method A
INTEGER, PARAMETER :: REAL_8 = SELECTED_REAL_KIND(15,30)
REAL(KIND=REAL_8), PARAMETER :: PI = 3.141592653589793238462643383_REAL_8
method B
INTEGER, PARAMETER :: SP = KIND(1.0) ! single precision
INTEGER, PARAMETER :: DP = KIND(1.0D0) ! double precision
REAL (DP), PARAMETER :: PI = 3.141592653589793238462643383_DP
Thanks,
Ben
===================================================================
Ben Blackwell, PhD E-mail: [log in to unmask]
Sandia National Laboratories
Validation and Uncertainty
Quantification 9133
MS 0828
PO Box 5800 Phone: (505) 845-8844
Albuquerque, NM 87185-0828 FAX: (505) 844-4523
UPS/FedEx: SNL / MS 0828 / 1515 Eubank Blvd SE / Albuq, NM 87123
"Build only what you can model. Model only what you can build." 1999
===================================================================
This e-mail has been scanned by Trend InterScan Software.
This e-mail (and its attachment(s) if any) is intended for the named
addressee(s) only. It may
contain information which is privileged and confidential within the
meaning of the applicable law.
Unauthorised use, copying or disclosure is strictly prohibited and may
be unlawful.
If you are not the intended recipient please delete this email and
contact the sender via email return.
Fujitsu Laboratories of Europe Ltd (FLE) does not accept responsibility
for changes made to this email after
it was sent. The views expressed in this email may not necessarily be
the views held by FLE.
Unless expressly stated otherwise, this email does not form part of a
legally binding contract
or agreement between the recipient and Fujitsu Laboratories of Europe Ltd (FLE).
|