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


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


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