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]

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



Hi Kaveh,


Kaveh R. Ghazi wrote:
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.

I agree with everything you say, but I'd like to point out that one thing you should make sure is, that compiled code (or code generated by the optimizers) and code evaluated by the frontend yield the same results, i.e.


FUNCTION f(z, e)
 complex :: f, z, e
 f = z**e
END

PRINT *, f((2.0, -4.3), huge(0))
END

should behave the same. With gfortran 4.1.2 this prints NaN.

Cheers,
- Tobi


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