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

Kaveh R. Ghazi ghazi@caip.rutgers.edu
Thu Jun 25 16:22:00 GMT 2009


From: "Tobias Schlüter" <tobias.schlueter@physik.uni-muenchen.de>

> 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.
> [...]
> should behave the same.  With gfortran 4.1.2 this prints NaN.

I agree with that.  However when investigating *why* it returns NaN I get
confused.  I did -fdump-tree-original on your program and it appears in
function "F" it just calls __builtin_cpowf on the two arguments.  The
equivalent C program that calls f(2-4.3I, INT_MAX) where f() just calls
cpowf returns (inf inf).

However when I print the two arguments inside the Fotran function I get:

 (  2.0000000    , -4.3000002    )
 (            NaN,  2.0000000    )
             NaN

So for some reason the exponent is turning into (NaN, 2) prior to
calculating the power value!

My Fortran is weak, here's what I had.  Can you explain it?

Also why does it print one NaN instead of a complex NaN NaN?

Finally, if I use huge(0) - 1000000000, I get:

 (  2.0000000    , -4.3000002    )
 (  916.84369    ,  2.0000000    )
       +Infinity

Again, I can't explain the exponent values nor why it prints a real response
instead of a complex.  (This is all with mainline on x86_64-linux-gnu).

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

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



More information about the Fortran mailing list