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 ?


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

Sorry, Kaveh, my Fortran was wrong, the exponent was not correctly typed. Here's a corrected program:
Tobias.Schlueter@zuppc13 src$ cat t.f90
FUNCTION f(z, e)
complex :: f, z
real e
print *, z
print *, e
f = z**e
print *, f
end


print *, f((2.0, -4.3), huge(0.))
END
Tobias.Schlueter@zuppc13 src$ gfortran t.f90
Tobias.Schlueter@zuppc13 src$ ./a.out
 (  2.000000    , -4.300000    )
  3.4028235E+38
 (     +Infinity,           NaN)
            NaN
Tobias.Schlueter@zuppc13 src$

Cheers,
- Tobi

--
Tobias Schlüter
Am Coulombwall 1, Zi. 326
85748 Garching b. München
Tel.: +49/89/289-14139


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