[gfortran,patch] Fix constant exponentiation with integer exponent

François-Xavier Coudert fxcoudert@gmail.com
Tue Mar 20 21:11:00 GMT 2007


> 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



More information about the Fortran mailing list