This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [gfortran,patch] Fix constant exponentiation with integer exponent
- From: "François-Xavier Coudert" <fxcoudert at gmail dot com>
- To: "Toon Moene" <toon at moene dot indiv dot nluug dot nl>
- 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 21:08:35 +0100
- Subject: Re: [gfortran,patch] Fix constant exponentiation with integer exponent
- References: <EB425BFB-CDFC-451A-B300-B52DB5CA46EA@gmail.com> <46003900.6060606@moene.indiv.nluug.nl>
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
That's precisely what I had come to write on a piece of paper. My
patch handles (AFA I have tested) all these cases right. The very
existence of the (j<0) cases is, in my opinion, the production of a
truly insane (collective) mind :)
FX