From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id A3A583854178; Fri, 18 Nov 2022 23:32:58 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A3A583854178 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1668814378; bh=081lorjc72idEzUHFBwe8929GQKJEcAjdc+LxAhp/gQ=; h=From:To:Subject:Date:In-Reply-To:References:From; b=UeQAyLeBwVRNIWrvvk4qfKrbETP6YpDldXTayggIPDoYAWPRR9DROOYI/2MMKEi55 WMsZ3JkGkYb+e92dz5FkmxWaInJoMDz+5blfPB8mSx/rDbtCAQHOG4xz4PZRb034ZT nv6hY/2tYlBzmXj/00dPgu1h09gjFm59lKMgbBrk= From: "sgk at troutmask dot apl.washington.edu" 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 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: fortran X-Bugzilla-Version: 12.2.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: sgk at troutmask dot apl.washington.edu X-Bugzilla-Status: WAITING X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D107753 --- Comment #6 from Steve Kargl -= -- 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=3D107753 >=20 > --- Comment #5 from Steve Kargl = --- > 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=3D107753 > >=20 > > --- 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 Sm= ith's > > > to handle such extreme cases of complex division. Not sure if that o= ne is > > > available by some compilation flag, and I think it would impact perfo= rmance. > > >=20 > > > In any case, if the reporter wants to get robust results and in a por= table > > > way, I would advise him to change/fix his algorithm accordingly. It = appears > > > that a few other compilers behave here like gfortran. > >=20 > > It's likely coming from the middle-end where gcc.info has > > the option > >=20 > > '-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. >=20 > Does anyone know what is meant by "Fortran rules"? F66 does not > have any particular algorithm specified. I'll look at F77 shortly. >=20 I add the subroutine subroutine ohno complex(dp), parameter :: a =3D cmplx(huge(1.d0),huge(1.d0),dp) complex(dp), parameter :: b =3D a / a write(*,*) a write(*,*) b end subroutine ohno=20 % 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.=