public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "sgk at troutmask dot apl.washington.edu" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug fortran/107753] gfortran returns NaN in complex divisions (x+x*I)/(x+x*I) and (x+x*I)/(x-x*I)
Date: Fri, 18 Nov 2022 23:32:58 +0000 [thread overview]
Message-ID: <bug-107753-4-0VJfOELvLU@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-107753-4@http.gcc.gnu.org/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107753
--- Comment #6 from Steve Kargl <sgk at troutmask dot apl.washington.edu> ---
On Fri, Nov 18, 2022 at 11:24:29PM +0000, sgk at troutmask dot
apl.washington.edu wrote:
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107753
>
> --- Comment #5 from Steve Kargl <sgk at troutmask dot apl.washington.edu> ---
> On Fri, Nov 18, 2022 at 10:05:21PM +0000, kargl at gcc dot gnu.org wrote:
> > https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107753
> >
> > --- Comment #4 from kargl at gcc dot gnu.org ---
> > (In reply to anlauf from comment #3)
> > > I guess the reporter assumes that gcc uses a clever algorithm like Smith's
> > > to handle such extreme cases of complex division. Not sure if that one is
> > > available by some compilation flag, and I think it would impact performance.
> > >
> > > In any case, if the reporter wants to get robust results and in a portable
> > > way, I would advise him to change/fix his algorithm accordingly. It appears
> > > that a few other compilers behave here like gfortran.
> >
> > It's likely coming from the middle-end where gcc.info has
> > the option
> >
> > '-fcx-fortran-rules'
> > Complex multiplication and division follow Fortran rules. Range
> > reduction is done as part of complex division, but there is no
> > checking whether the result of a complex multiplication or division
> > is 'NaN + I*NaN', with an attempt to rescue the situation in that
> > case.
>
> Does anyone know what is meant by "Fortran rules"? F66 does not
> have any particular algorithm specified. I'll look at F77 shortly.
>
I add the subroutine
subroutine ohno
complex(dp), parameter :: a = cmplx(huge(1.d0),huge(1.d0),dp)
complex(dp), parameter :: b = a / a
write(*,*) a
write(*,*) b
end subroutine ohno
% gfortran -o z a.f90 && ./z
(1.79769313486231571E+308,1.79769313486231571E+308)
(NaN,0.0000000000000000)
(1.79769313486231571E+308,1.79769313486231571E+308)
(1.0000000000000000,0.0000000000000000)
The last two lines are from ohno.
next prev parent reply other threads:[~2022-11-18 23:32 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-18 19:32 [Bug fortran/107753] New: " weslley.pereira at ucdenver dot edu
2022-11-18 19:50 ` [Bug fortran/107753] " anlauf at gcc dot gnu.org
2022-11-18 20:50 ` kargl at gcc dot gnu.org
2022-11-18 21:26 ` anlauf at gcc dot gnu.org
2022-11-18 22:05 ` kargl at gcc dot gnu.org
2022-11-18 23:24 ` sgk at troutmask dot apl.washington.edu
2022-11-18 23:32 ` sgk at troutmask dot apl.washington.edu [this message]
2022-11-18 23:45 ` weslley.pereira at ucdenver dot edu
2022-11-18 23:47 ` weslley.pereira at ucdenver dot edu
2022-11-19 0:25 ` sgk at troutmask dot apl.washington.edu
2022-11-19 19:11 ` kargl at gcc dot gnu.org
2022-11-19 20:14 ` anlauf at gcc dot gnu.org
2022-11-20 0:54 ` sgk at troutmask dot apl.washington.edu
2022-12-07 21:16 ` anlauf at gcc dot gnu.org
2022-12-07 21:50 ` kargl at gcc dot gnu.org
2022-12-07 22:31 ` anlauf at gcc dot gnu.org
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=bug-107753-4-0VJfOELvLU@http.gcc.gnu.org/bugzilla/ \
--to=gcc-bugzilla@gcc.gnu.org \
--cc=gcc-bugs@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).