From: steve on
On Sep 9, 7:26 pm, e p chandler <e...(a)juno.com> wrote:
> On Sep 9, 9:36 pm, "sumesh.pt" <sumesh...(a)gmail.com> wrote:
>
> > In mixed mode operations, is it advisable to convert integers to
> > double using the command dble() in the expressions or would it be
> > better for the compiler to do this job? I am asking this NOT from the
> > point of view of understanding the program easily, but in terms of
> > speed and accuracy. ie
> > real*8 :: x
> > integer :: i=10
> > x = x/i    or    x=x/dble(i)   which is faster and accurate.
>
> In general for integer constants it should not make a difference.
> However, do not expect a real constant to be promoted to a higher
> precision because it is in a mixed mode expression or it is assigned
> to a variable of higher precision. Instead specify, for example,
> 9.237543521d0 (or the appropriate kind _ suffix).

While I believe the intent on what you wanted to write is correct, how
you wrote the above is incorrect. In

double precision x
x = 1.d0
x = x * 0.3333333
end

The 0.3333333 is converted to a double precision entity. It, however,
doesn't automagically acquire an addition 29-bits of precision
(assuming
24-bit and 53-bit precision for real and double precision).

--
steve
From: e p chandler on
On Sep 9, 10:57 pm, steve <kar...(a)comcast.net> wrote:
> On Sep 9, 7:26 pm, e p chandler <e...(a)juno.com> wrote:
>
>
>
>
>
> > On Sep 9, 9:36 pm, "sumesh.pt" <sumesh...(a)gmail.com> wrote:
>
> > > In mixed mode operations, is it advisable to convert integers to
> > > double using the command dble() in the expressions or would it be
> > > better for the compiler to do this job? I am asking this NOT from the
> > > point of view of understanding the program easily, but in terms of
> > > speed and accuracy. ie
> > > real*8 :: x
> > > integer :: i=10
> > > x = x/i    or    x=x/dble(i)   which is faster and accurate.
>
> > In general for integer constants it should not make a difference.
> > However, do not expect a real constant to be promoted to a higher
> > precision because it is in a mixed mode expression or it is assigned
> > to a variable of higher precision. Instead specify, for example,
> > 9.237543521d0 (or the appropriate kind _ suffix).
>
> While I believe the intent on what you wanted to write is correct, how
> you wrote the above is incorrect.  In
>
>   double precision x
>   x = 1.d0
>   x = x * 0.3333333
>   end
>
> The 0.3333333 is converted to a double precision entity.  It, however,
> doesn't automagically acquire an addition 29-bits of precision
> (assuming
> 24-bit and 53-bit precision for real and double precision).
>
> --
> steve

I did not explain that well. It may be converted to double precision
but without incorporating the extra digits normally associated with
double precision. [Where do I sign up for technical writing lessons
from Richard Maine??]

-- elliot
From: Ron Shepard on
In article
<52e82606-6d12-40b1-8b11-e7227294a922(a)a21g2000yqc.googlegroups.com>,
"sumesh.pt" <sumesh.pt(a)gmail.com> wrote:

> real*8 :: x
> integer :: i=10
> x = x/i or x=x/dble(i) which is faster and accurate.

Just as a matter of style, I would recommend using a KIND parameter
for the declaration of "x", and I would recommend using the REAL()
intrinsic (with the KIND parameter argument) rather than the DBLE()
intrinsic.

Assuming real*8 is the same as double precision, there should be no
difference in a simple expression with the implicit or explicit type
conversion. The assembler code should be the same, except possibly
for the use of extended precision registers or some such
technicality related to optimizations.

I used to dislike using implicit type conversion because I thought
it was confusing, if not to me then possibly to others reading my
code. As a compromise between explicit conversions and brevity, I
would sometimes write these expressions like

x = x / (i)

with redundant parentheses. I've mellowed since then, and I don't
do this as much as I used to.

$.02 -Ron Shepard
From: nmm1 on
In article <4AA85D3A.8020806(a)nospamcomputer.org>,
Tim Prince <tprince(a)nospamcomputer.org> wrote:
>sumesh.pt wrote:
>
>> real*8 :: x
>> integer :: i=10
>> x = x/i or x=x/dble(i) which is faster and accurate.
>>
>> I am doing some kind of recursion calculations with x and hence error
>> gets accumulated and I am not able to decide which is best.
>
>I see no reason for this to make a difference. ...

It used to. But that's a long, long time back!


Regards,
Nick Maclaren.
From: robin on
"sumesh.pt" <sumesh.pt(a)gmail.com> wrote in message
news:52e82606-6d12-40b1-8b11-e7227294a922(a)a21g2000yqc.googlegroups.com...
| In mixed mode operations, is it advisable to convert integers to
| double using the command dble() in the expressions or would it be
| better for the compiler to do this job? I am asking this NOT from the
| point of view of understanding the program easily, but in terms of
| speed and accuracy. ie
| real*8 :: x
| integer :: i=10
| x = x/i or x=x/dble(i) which is faster and accurate.

There should be no difference whatsoever.
The conversion is from integer to double precision
in both cases.
The integer in x = x/i is not, for instance, converted first to single precision REAL,
and then to DOUBLE PRECISION.