Robert Kernell wrote:
>
> Hi. I am teaching a Fortran class and I was wondering...
>
> Is there any use for specifying kinds for constants?
>
> Bob Kernell
> Research Scientist
> Surface Validation Group
> Atmospheric Sciences Competency
> Analytical Services & Materials, Inc.
> email: [log in to unmask]
> tel: 757-827-4631
yes,
on a compiler where the default KIND for reals is 32 bits, the definition
integer, parameter :: R64=selected_real_kind(13)
real(kind=R64), parameter :: OneOnThree = 0.333333333333333
can consider the litteral constant 0.333333333333333 as a 32 bits real
and assign 0.33333333 to OneOnThree, creating a precision lost.
the right notation is :
integer, parameter :: R64=selected_real_kind(13)
real(kind=R64), parameter :: OneOnThree = 0.333333333333333_R64
You can have similar problems when using a litteral constant in
arithmetic expressions or as routine parameters.
--
Pascal RICHARD Bpi 1311
DEE/IR/ISM/IS Centre National d'Etudes Spatiales
tel: +33 5 61.28.32.54 18, avenue Edouard Belin
fax: +33 5 61.28.18.93 F-31401 TOULOUSE CEDEX 4
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|