f



x**2 or x**2.0 or x*x

makes this any difference ?

x**2 or x**2.0 or x*x
x is real

Cheers
-Ralf

0
schaa (57)
12/6/2005 1:36:29 AM
comp.lang.fortran 11941 articles. 2 followers. Post Follow

6 Replies
1276 Views

Similar Articles

[PageSpeed] 32

"Ralf Schaa" <schaa@geo.uni-koeln.de> wrote in message 
news:1133832989.230157.34130@g49g2000cwa.googlegroups.com...
> makes this any difference ?
>
> x**2 or x**2.0 or x*x
> x is real
>
> Cheers
> -Ralf
>
It might be.  Some would implement the first as x*x.  Some would also 
implement the second as X*x as a special case of the more general expansion 
of exp(ln(x)*2)) (providing my math is correct anyway)..
Jim 


0
j.n (117)
12/6/2005 2:01:28 AM
Ralf Schaa wrote:
> makes this any difference ?
> 
> x**2 or x**2.0 or x*x
> x is real
> 
x**2.0 is not required to be interpreted the same as the others.  For 
example, negative x will be an error condition on some, not on others. 
Most compilers will generate identical code for x*x and x**2
0
tprince (584)
12/6/2005 5:37:25 AM
x**2 = x*x
x**2. = exp(ln(x^2)) ---> compiler uses Taylor series for calculation

For power 2, it does not make much difference. But for higher power, it
is better to use **integer than **real since Taylor expansion takes
more CPU time. If in the code there are numerous number of such
computations with high powers, then the first is encouraged.

0
12/7/2005 5:21:25 AM
not necessarily high power. Low power (2,3,4) is what I meant.

0
12/7/2005 5:24:24 AM
kis <kisitanggang@gmail.com> wrote:

> x**2 = x*x
> x**2. = exp(ln(x^2)) ---> compiler uses Taylor series for calculation
> 
> For power 2, it does not make much difference. But for higher power, it
> is better to use **integer than **real since Taylor expansion takes
> more CPU time. If in the code there are numerous number of such
> computations with high powers, then the first is encouraged.

Yes it does make a difference for low powers. As mentioned elsewhere,
x**2. is not valid Fortran if x is negative. Some compilers might
translate it into what you meant instead of what you said, but it is not
valid standard Fortran and will cause some compilers to give an error.

-- 
Richard Maine                    | Good judgement comes from experience;
email: last name at domain . net | experience comes from bad judgement.
domain: summertriangle           |  -- Mark Twain
0
nospam47 (9747)
12/7/2005 6:05:24 AM
In article <1133932885.605292.132930@g44g2000cwa.googlegroups.com>,
kis <kisitanggang@gmail.com> wrote:
>x**2 = x*x
>x**2. = exp(ln(x^2)) ---> compiler uses Taylor series for calculation

Many compilers will implement x**2. as x**2, this is one of the
standard tricks.

-- greg
0
lindahl (697)
12/7/2005 7:11:25 AM
Reply: