This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [gfortran,patch] Fix constant exponentiation with integer exponent


FX Coudert wrote:

> Integer exponentiation
needs more thinking, and I had to write many cases to get it right every single time (integer exponentiation with negative exponents shouldn't be allowed, let me tell you!)

This is what I wrote about it to the g77-bug mailing list on the 22nd of January, 1996:


This all sounds very reasonable, but it is plain wrong.  In Fortran
integers are _signed_ quantities in arithmetic context, so we have
the following 5 x 5 matrix of possibilities for i ** j:

i ** j j < -1 j = -1 j = 0 j = 1 j > 1

i < -1 0 0 1 i i**j

i = -1 i**(-j) -1 1 -1 i**j

i = 0 Error Error 1 (!) 0 0

i = 1 1 1 1 1 1

i > 1 0 0 1 i i**j

based on the truncation rules I think are valid for Fortran.

I hope I didn't make a mistake.  In that case, row 1 and 5 can be
folded, and row 2 can be dumbed down to -1 for j odd and +1 for j
even.  The remaining i**j case can be implemented with the loop as
generated by g77 now (see my previous mail).

Hope this helps,

--
Toon Moene - e-mail: toon@moene.indiv.nluug.nl - phone: +31 346 214290
Saturnushof 14, 3738 XG Maartensdijk, The Netherlands
At home: http://moene.indiv.nluug.nl/~toon/
Who's working on GNU Fortran: http://gcc.gnu.org/ml/gcc/2007-01/msg00059.html



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]