| Author |
x**2 or x**2.0 or x*x
|
|
| Ralf Schaa 2005-12-05, 9:58 pm |
| makes this any difference ?
x**2 or x**2.0 or x*x
x is real
Cheers
-Ralf
| |
|
|
"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
| |
| Tim Prince 2005-12-06, 3:57 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
| |
|
| 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.
| |
|
| not necessarily high power. Low power (2,3,4) is what I meant.
| |
| Richard Maine 2005-12-07, 4:01 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
| |
| Greg Lindahl 2005-12-07, 4:01 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
|
|
|
|