This is the mail archive of the fortran@gcc.gnu.org mailing list for the GNU Fortran 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]

Fortran pow (complex ** huge) returns NaN instead of Inf ?


Hi,

I'm integrating mpc_pow with the fortran frontend and I'm getting one
regression related to raising a value to a huge integer.

FAIL: gfortran.dg/integer_exponentiation_4.f90 -O (test for errors, line 41)
FAIL: gfortran.dg/integer_exponentiation_4.f90 -O (test for errors, line 42)
FAIL: gfortran.dg/integer_exponentiation_4.f90 -O (test for excess errors)


The testcase has on lines 41/42 these statements:

 print *, (2.0,-4.3)**huge(0) ! { dg-error "Arithmetic NaN" }
 print *, (2.0,-4.3)**(-huge(0)) ! { dg-error "Arithmetic NaN" }

I.e. it expects a NaN for both cases.  What I'm getting with MPC is
"Arithmetic overflow" on the first line because it overflows to Inf, and no
error for the second presumably because it underflows to zero.

I think perhaps expecting a NaN here is bogus and is an artifact of the
hand-written algorithm chosen to evaluate complex**int inside the fortran
frontend.  The code is in fortran/arith.c:complex_pow().  I suspect the
algorithm is getting confused somewhere along the way.

E.g. if I write in C:

cpow (2 - 4.3i, INT_MAX);

I get (Inf - Inf I).

I propose that we change the lines in the testcase to instead say:

 print *, (2.0,-4.3)**huge(0) ! { dg-error "Arithmetic overflow" }
 print *, (2.0,-4.3)**(-huge(0))

Note this matches the non-complex behavior of pow (2**huge) and
pow(2**-huge) in the testcase.  Also if I write e.g. (2.0,-4.3) ** (8.e9/3)
I also get arithmetic overflow for the non-integer calculation of a huge
number.

I don't know if it's worth fixing arith.c:complex_pow() since it'll be
removed when we convert to MPC.  However the flip side would be that fortran
"failures" would appear until the switchover if I correct the testcase.
Also older versions of gfortran would still have the bug.  I can open a PR
for this (like the complex division by zero issue.)

       Thoughts?
       --Kaveh
--
Kaveh R. Ghazi


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