> Phillip Helbig writes:
> > > real( double_k) :: pi = 3.1415926_double_k
> > >
> > > The "_double_k" on the literal is necessary
> > > to get a double_k value. Otherwise, it's
> > > a default real value, which may not be double_k.
> >
> > If it weren't for the restriction on initialisation expressions, one
> > could write dble(3.1415926).
> >
> > Of course, if you are using such precision, you probably want to include
> > more places.
>
> *NO*. This will *NOT* get you a value better than single precision.
> There is no real rocket science here. The constant 3.1415926 (even
> with more digits) is a single precision constant. If it has a
> "d0" or a "_some_kind_number" on the end, then it may be a different
> kind. But just writing it as an argument of a function does not
> do so. The intrinsic dble has no magic properties here - it's just
> like any other function in this regard. It takes its arguments
> and computes a result value based on them. It does *NOT* look at
> its arguments and decide that they really should have had some
> other values.
>
> Dble will convert its argument to a double precision format,
> as will the REAL intrinsic with an appropriate kind, but this will
> not magically make its argument more precise. Once you have
> expressed 3.1415926 as a single precision value, any extra precision
> is lost, never to bee seen again. There is no function to fix it
> up after the fact.
Richard is right, of course, but so was I---at least in what I meant. My
example about dble was wrong, but my point about more digits was not (I
hope). I meant that if precision is important to you, presumably why
one would be using something other than the default kind, then when the
value for the parameter is specified as in real( double_k) :: pi =
3.1415926_double_k, then one should include more places, e.g.
real( double_k) :: pi = 3.141592653589793238462643383279_double_k
In other words, I meant that specifying _double_k does not magically
produce the 53589793238462643383279. :-)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|