[PATCH]: Integrate gfortran with MPC
Tobias Burnus
burnus@net-b.de
Fri May 29 20:40:00 GMT 2009
Summary: Try the C program with and without -fcx-fortran-rules; for
details, see below.
Tobias
Steve Kargl wrote:
> There appears to be a middle-end issue here as well. Consider,
> the following program:
>
[...]
> troutmask:sgk[205] ./z
> NaN NaN NaN NaN
> NaN NaN NaN NaN
>
I tried a couple of other Fortran compilers - and the result is:
Intel Fortran Compiler 11.1:
NaN NaN NaN NaN
NaN NaN (NaN,NaN)
InfinityInfinity NaN NaN
g95, openf95:
NaN NaN NaN NaN
NaN NaN (NaN,NaN)
NaN NaN NaN NaN
Sunf95:
InfinityInfinityInfinityInfinity
Inf Inf (Inf,Inf)
InfinityInfinityInfinityInfinity
NAG f95 (with IEEE_SET_HALTING_MODE set to .false. and with compile-time
foldings removed):
NaN NaN
NaN NaN (NaN,NaN)
InfinityInfinity
* * *
However, more interesting is the following C program. The equivalent
Fortran program produces NaN (with gfortran) but in C one gets with GCC:
inf + inf i
inf + inf i
inf + inf i
and with Intel's icc (9.1):
nan + nan i
nan + nan i
nan + nan i
And here is something interesting: "gcc -fcx-fortran-rules" (!!!!!) gives:
inf + inf i
nan + nan i
nan + nan i
which hints at the problem.
Here is the C code:
#include <stdio.h>
#include <complex.h>
int main()
{
complex double z1, z2, z3;
z1 = 0.0;
z2 = 1.0 + 2.0*I;
z3 = (1.0 + 2.0*I)/0.0;
printf("%f + %f i\n", __real__ (z3), __imag__ (z3));
printf("%f + %f i\n", __real__ (z2/z1), __imag__ (z2/z1));
z3 = z2/z1;
printf("%f + %f i\n", __real__ (z3), __imag__ (z3));
}
And here the Fortran code:
Program test
complex(kind=8) z1, z2, z3;
z1 = 0.0
z2 = cmplx(1.0d0,2.0d0)
z3 = cmplx(1.0d0 + 2.0d0)/0.0d0;
print *, real(z3,kind=8),aimag(z3)
print *, real(z2/z1,kind=8),aimag(z2)
z3 = z2/z1;
print *, real(z3,kind=8),aimag(z3)
end program test
More information about the Gcc-patches
mailing list