This is the mail archive of the
fortran@gcc.gnu.org
mailing list for the GNU Fortran project.
Re: [gfortran,patch] Fix constant exponentiation with integer exponent
- From: Toon Moene <toon at moene dot indiv dot nluug dot nl>
- To: FX Coudert <fxcoudert at gmail dot com>
- Cc: Fortran List <fortran at gcc dot gnu dot org>, gcc-patches List <gcc-patches at gcc dot gnu dot org>
- Date: Tue, 20 Mar 2007 20:41:52 +0100
- Subject: Re: [gfortran,patch] Fix constant exponentiation with integer exponent
- Organization: Moene Computational Physics, Maartensdijk, The Netherlands
- References: <EB425BFB-CDFC-451A-B300-B52DB5CA46EA@gmail.com>
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