This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug fortran/57749] -ffpe-trap=zero or invalid produces SIGFPE on complex zero ** 1e0
- From: "anlauf at gmx dot de" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Tue, 02 Jul 2013 17:41:32 +0000
- Subject: [Bug fortran/57749] -ffpe-trap=zero or invalid produces SIGFPE on complex zero ** 1e0
- Auto-submitted: auto-generated
- References: <bug-57749-4 at http dot gcc dot gnu dot org/bugzilla/>
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57749
--- Comment #19 from Harald Anlauf <anlauf at gmx dot de> ---
(In reply to Vittorio Zecca from comment #16)
> You are being a little too hard on me, but so be it.
>
> I believe there is only one special case, base==0,
> and that there are only two ifs to put in cpow to avoid the floating
> exception
> and give the expected result(I am simplifying here, also because I do
> not use C):
>
> if(base==0)
> {
> if(exponent>0) return 0; else raise hell;
> }
>
> The actual code where the original issue occurred had the exponentiation
> in the deep of nested loops, it would have been rather time consuming
> to test base==0
> at the Fortran level
>
>
> And I still do not understand why if the exponent is integer no
> exception is raised and
> the expected result zero is delivered.
> As in the following fragment (with option -ffpe-trap=zero,invalid):
> complex x
> x=cmplx(0e0,0e0)
> i=2
> r=2e0
> print *,x**i ! no exception raised delivers zero
> print *,x**r ! exception raised
> end
> The Intel ifort and NAG nagfor compilers raise no exceptions and
> deliver the expected result.
> With my best wishes of good work to everybody.
You obviously haven't tried other compilers.
With xlf, the result also depends on compiler flags:
Either (0.,0.), (NaNQ,NaNQ), or
Trace/BPT trap (core dumped)
I think you should accept that your code invokes undefined behavior
and needs fixing.