question on ** operator

  • Follow


In a**b are there any restrictions on the data types of a and b - or
will the language handle all numeric cases?

Thanks.




0
Reply analyst41 (232) 7/17/2010 1:42:59 PM

On Jul 17, 3:42=A0pm, "analys...@hotmail.com" <analys...@hotmail.com>
wrote:
> In a**b are there any restrictions on the data types of a and b - or
> will the language handle all numeric cases?
>
> Thanks.

All combinations of intrinsic numeric types are permitted (MR&C, Table
3.2) but you cannot raise a negative real value to a real power.

Regards,

Mike Metcalf
0
Reply m_b_metcalf 7/17/2010 2:37:50 PM


In article
<83d9c160-d7f6-4c1b-9b4b-2e6fe7e68ccb@s9g2000yqd.googlegroups.com>,
m_b_metcalf <michaelmetcalf@compuserve.com> writes: 

> On Jul 17, 3:42=A0pm, "analys...@hotmail.com" <analys...@hotmail.com>
> wrote:
> > In a**b are there any restrictions on the data types of a and b - or
> > will the language handle all numeric cases?
> >
> > Thanks.
> 
> All combinations of intrinsic numeric types are permitted (MR&C, Table
> 3.2) but you cannot raise a negative real value to a real power.

$  create test.f90
print*, (-1.0)**2.0
end
 Exit
$  foro test
$  link test
$  r test
  1.000000

The "foro" symbol includes "/STANDARD=F95/WARNINGS=ALL".

What am I missing?

0
Reply helbig 7/17/2010 3:08:39 PM

On Jul 17, 8:08=A0am, hel...@astro.multiCLOTHESvax.de (Phillip Helbig---
undress to reply) wrote:
> In article
> <83d9c160-d7f6-4c1b-9b4b-2e6fe7e68...@s9g2000yqd.googlegroups.com>,
>
> m_b_metcalf <michaelmetc...@compuserve.com> writes:
> > On Jul 17, 3:42=3DA0pm, "analys...@hotmail.com" <analys...@hotmail.com>
> > wrote:
> > > In a**b are there any restrictions on the data types of a and b - or
> > > will the language handle all numeric cases?
>
> > > Thanks.
>
> > All combinations of intrinsic numeric types are permitted (MR&C, Table
> > 3.2) but you cannot raise a negative real value to a real power.
>
> $ =A0create test.f90
> print*, (-1.0)**2.0
> end
> =A0Exit
> $ =A0foro test
> $ =A0link test
> $ =A0r test
> =A0 1.000000
>
> The "foro" symbol includes "/STANDARD=3DF95/WARNINGS=3DALL".
>
> What am I missing?

A descent compiler?

laptop:kargl[203] gfc4x -o z a.f90
a.f90:1.9:

print*, (-1.0)**2.0
         1
Error: Raising a negative REAL at (1) to a REAL power is prohibited

--
steve
0
Reply kargls (354) 7/17/2010 3:16:46 PM

m_b_metcalf wrote in message <83d9c160-d7f6-4c1b-9b4b-2e6fe7e68ccb@s9g2000yqd.googlegroups.com>...
>On Jul 17, 3:42 pm, "analys...@hotmail.com" <analys...@hotmail.com>
>wrote:
>> In a**b are there any restrictions on the data types of a and b - or
>> will the language handle all numeric cases?

>All combinations of intrinsic numeric types are permitted (MR&C, Table
>3.2) but you cannot raise a negative real value to a real power.

As we're dealing with exceptions, 0**0 in their various forms
is not permitted either.


0
Reply robin 7/17/2010 3:47:21 PM

analyst41@hotmail.com <analyst41@hotmail.com> wrote:

> In a**b are there any restrictions on the data types of a and b - or
> will the language handle all numeric cases?

Now I believe all numeric types are allowed.

Fortran 66 didn't allow complex powers.  I am not sure when that
restriction was removed.

-- glen
0
Reply glen 7/17/2010 3:47:42 PM

In article
<aacabb4b-c8f0-41a5-ad9d-5256306515c6@l25g2000prn.googlegroups.com>,
steve <kargls@comcast.net> writes: 

> > The "foro" symbol includes "/STANDARD=3DF95/WARNINGS=3DALL".
> >
> > What am I missing?
> 
> A descent compiler?

Maybe.  It is rather old, 10 years or so.

Is the consensus here that 

   print*, (-1.0)**2.0
   end

is illegal (i.e. doesn't conform to the standard)?  (If so, presumably
the compiler should warn about it, at least if asked to warn about
non-standard stuff.) 

Changing the values slightly so that they are no longer "round" values, 
I get 

   %MTH-F-UNDEXP, undefined exponentiation

at run time but not at compile time.

0
Reply helbig 7/17/2010 3:54:26 PM

On Jul 17, 8:54=A0am, hel...@astro.multiCLOTHESvax.de (Phillip Helbig---
undress to reply) wrote:
> In article
> <aacabb4b-c8f0-41a5-ad9d-525630651...@l25g2000prn.googlegroups.com>,
>
> steve <kar...@comcast.net> writes:
> > > The "foro" symbol includes "/STANDARD=3D3DF95/WARNINGS=3D3DALL".
>
> > > What am I missing?
>
> > A descent compiler?
>
> Maybe. =A0It is rather old, 10 years or so.
>
> Is the consensus here that
>
> =A0 =A0print*, (-1.0)**2.0
> =A0 =A0end
>
> is illegal (i.e. doesn't conform to the standard)?

Of course, otherwise, gfortran would says it is prohibited.
But, if you want the exact text from F2003 (Sec. 7.1.8):

   The execution of any numeric operation whose result is
   not defined by the arithmetic used by the processor is
   prohibited.  Raising a negative-valued primary of type
   real to a real power is prohibited.

--
steve
0
Reply steve 7/17/2010 4:08:57 PM

On Jul 17, 9:08=A0am, steve <kar...@comcast.net> wrote:
> On Jul 17, 8:54=A0am, hel...@astro.multiCLOTHESvax.de (Phillip Helbig---
>
>
>
> undress to reply) wrote:
> > In article
> > <aacabb4b-c8f0-41a5-ad9d-525630651...@l25g2000prn.googlegroups.com>,
>
> > steve <kar...@comcast.net> writes:
> > > > The "foro" symbol includes "/STANDARD=3D3DF95/WARNINGS=3D3DALL".
>
> > > > What am I missing?
>
> > > A descent compiler?
>
> > Maybe. =A0It is rather old, 10 years or so.
>
> > Is the consensus here that
>
> > =A0 =A0print*, (-1.0)**2.0
> > =A0 =A0end
>
> > is illegal (i.e. doesn't conform to the standard)?
>
> Of course, otherwise, gfortran would says it is prohibited.
> But, if you want the exact text from F2003 (Sec. 7.1.8):

Replying to self :(

s/would says/would not say/

(Sigh. Not enough coffee, yet!)

--
steve

0
Reply steve 7/17/2010 4:10:33 PM

On 2010-07-17 12:54:26 -0300, helbig@astro.multiCLOTHESvax.de (Phillip 
Helbig---undress to reply) said:

> In article
> <aacabb4b-c8f0-41a5-ad9d-5256306515c6@l25g2000prn.googlegroups.com>,
> steve <kargls@comcast.net> writes:
> 
>>> The "foro" symbol includes "/STANDARD=3DF95/WARNINGS=3DALL".
>>> 
>>> What am I missing?
>> 
>> A descent compiler?
> 
> Maybe.  It is rather old, 10 years or so.
> 
> Is the consensus here that
> 
>    print*, (-1.0)**2.0
>    end
> 
> is illegal (i.e. doesn't conform to the standard)?  (If so, presumably
> the compiler should warn about it, at least if asked to warn about
> non-standard stuff.)
> 
> Changing the values slightly so that they are no longer "round" values,
> I get
> 
>    %MTH-F-UNDEXP, undefined exponentiation
> 
> at run time but not at compile time.

A common extension/optimization is to treat x**2.0 as if it were x**2 which
allows for simpler algorithms. (-1.0)**2 would be OK.

0
Reply Gordon 7/17/2010 4:15:37 PM

Phillip Helbig---undress to reply <helbig@astro.multiCLOTHESvax.de>
wrote:

> Is the consensus here that 
> 
>    print*, (-1.0)**2.0
....
> is illegal (i.e. doesn't conform to the standard)?

I would hope so. I  don't have a copy of the standard here to cite, but
it isn't as if the restriction is in the lest bit subtle. I shouldn't
say that I don't see how anyone could manage to interpret it differently
(because last time I made such an audacious claim on another matter, I
was wrong), but I sure don't. The words are something along the line of
"a negative-valued real shall not be raised to a complex value". That's
from recollection and thus might not be quite right, but it was
something about that straightforward.

> (If so, presumably
> the compiler should warn about it, at least if asked to warn about
> non-standard stuff.)

Ah. You asked about the part that seems obvious (at least to me), but
you just presume the part that seems far from obvious. The restriction
is not a constraint or anything else that the standard requires warning
about. Most cases are likely to involve variables, whose values are not
evident at compile time and thus could not plausibly generate
compilation errors. I suppose the compiler could warn for every
exponentation of a real that there might be a problem if the value was
negative, but I'd find that incredibly annoying in that it would give
more bogus warnings than useful ones. I wouldn't have even thought about
the possibility if I hadn't seen warnings that I considered just as
annoying for other prefectly innocuous things that I do a lot.

I can thus see argument for not being worth the bother to check for the
particular case of doing this with literal constants. Might be minorly
nice, but it sure is not very high on the list of quality of
implementation issues. In particular, I would not put it high enough on
the list of minorly nice things for me to say a compiler "should" do it.

> Changing the values slightly so that they are no longer "round" values,
> I get 
> 
>    %MTH-F-UNDEXP, undefined exponentiation
> 
> at run time but not at compile time.

That just suggests that somewhere along the line, the compiler optimized
the case with round values. That's a plausible, possibly even common,
optimization.

-- 
Richard Maine                    | Good judgment comes from experience;
email: last name at domain . net | experience comes from bad judgment.
domain: summertriangle           |  -- Mark Twain
0
Reply nospam 7/17/2010 4:26:45 PM

Richard Maine <nospam@see.signature> wrote:

> The words are something along the line of
> "a negative-valued real shall not be raised to a complex value".

Make that s/complex/real/. I had complex on my mind and the fingers just
typed it by themselves or something.

-- 
Richard Maine                    | Good judgment comes from experience;
email: last name at domain . net | experience comes from bad judgment.
domain: summertriangle           |  -- Mark Twain
0
Reply nospam 7/17/2010 4:31:34 PM

Richard Maine <nospam@see.signature> wrote:
> Richard Maine <nospam@see.signature> wrote:
 
>> The words are something along the line of
>> "a negative-valued real shall not be raised to a complex value".
 
> Make that s/complex/real/. 

Yes.  Negative values to complex powers should be allowed.

> I had complex on my mind and the fingers just
> typed it by themselves or something.

I have had that happen, though usually only one or two letters off.
I once registered the wrong domain name, thinking I typed the
right one.  That was when you didn't have to pay immediately,
though.  

-- glen 
0
Reply glen 7/17/2010 4:53:00 PM

12 Replies
197 Views

(page loaded in 0.171 seconds)


Reply: