Home > Archive > Fortran > September 2006 > Exponentiation operator precedence
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Exponentiation operator precedence
|
|
| Rich Townsend 2006-09-21, 7:04 pm |
| Hi all --
I've run into a problem relating to the precedence of the exponentiation (**)
operator. Sample program:
program foo
print *,2.**-3.*8.
print *,(2.**(-3.))*8.
end program foo
As I understand it, the precedence order (from high to low) for the operations
in the print statements is **, *, unary -. But I'm unclear how this sequence
applies to the above expression.
On the one hand, in the first print statement the higher precedence of * over -
suggests that 3.*8 is first evaluated, and then negated; so the final result
will be 2**-24. = 5.96e-8. However, this then seems to be violating the high
precedence of **.
To complicate matters, my available compilers don't agree with one another. With
gfortran, both print statements give the same result (1.0000). With Intel ifort,
I get 5.96e-8 from the first, and 1.00000 from the second. With Lahey lf95, the
code won't compile, throwing an 'Invalid operator' error. It seems it doesn't
like two consecutive operators -- is this mandated by the Standard?
cheers,
Rich
| |
| Richard E Maine 2006-09-21, 7:04 pm |
| Rich Townsend <rhdt@barVOIDtol.udel.edu> wrote:
> print *,2.**-3.*8.
That is an illegal expression, which is why...
> my available compilers don't agree with one another.
Have you tried turning on the compiler's switch to diagnose all
extensions? If you have that switch on and the compiler doesn't XXXXX
about this, then XXXXX at the vendor.
--
Richard Maine | Good judgment comes from experience;
email: my first.last at org.domain| experience comes from bad judgment.
org: nasa, domain: gov | -- Mark Twain
| |
| Rich Townsend 2006-09-21, 7:04 pm |
| Richard E Maine wrote:
> Rich Townsend <rhdt@barVOIDtol.udel.edu> wrote:
>
>
> That is an illegal expression, which is why...
>
>
> Have you tried turning on the compiler's switch to diagnose all
> extensions? If you have that switch on and the compiler doesn't XXXXX
> about this, then XXXXX at the vendor.
>
Thanks. And for the record, both "naughty" compilers behave when standards
conformance is enabled.
cheers,
Rich
|
|
|
|
|