[gfortran] Exponentiation by integral exponents

Tobias Schlüter tobias.schlueter@physik.uni-muenchen.de
Thu Apr 29 12:20:00 GMT 2004


[ forwarding to gcc@gcc.gnu.org so more knowledgeable people can comment 
on the point I make in the last paragraph ]

Feng Wang wrote:
> Hi, Tobi, Paul, etc
>   I missed the discussion because of my poor modem. But I have implemented this
> and the patch is under test. IMHO, we have to implement the algorithm described
> by Knuth in the FE. BUILT_IN_POW only deals with Real type. How about complex
> type? There are also many problems to consider when an integer is raised to an
> negative integer. The result is just 0, -1, or 1. So it is not correct to
> convert integer to real. 

This is a good point that I hadn't thought about.

> I think we should also implement the runtime library
> function powi. When a value is raised to an varible integer, we just call the
> library function. The value may be of integer type, real type or complex type.

Yeah, I thought so as well. I was already looking for an implementation.

> I have done these and in a few days I will give the patch. I didn't port Andy's
> implementation. Andy's vertion only deal with exponent under 100 and don't
> consider (integer ** negative integer). The main algorithm in my implementation
> is from builtins.c and can deal with an arbitrary integer exponent. The
> algorithm in powi library function is from libf77.

If your patch is finished I agree that we should go with your patch, as 
mine is far from finished. I chose to port Andy's implementation as this 
was my first step in GCC trees, and I didn't want to do something from 
scratch :-)

I don't necessarily agree that this should be handled in the FE, though. 
There might be other languages that have an "integral exponent" idiom, 
so a language independent solution might be preferable.

- Tobi



More information about the Gcc mailing list