public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "anlauf at gcc dot gnu.org" <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: Sat, 19 Nov 2022 20:14:01 +0000 [thread overview] Message-ID: <bug-107753-4-Lvw8witxJs@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 #11 from anlauf at gcc dot gnu.org --- (In reply to Weslley da Silva Pereira from comment #7) > More data for the discussion: > 1. In a Ubuntu 18.04.5 LTS, using GNU Fortran 7.5.0, I tested optimization > flags `-O` but still reproduce the wrong result for complex divisions with > huge numbers. See It is possible that gfortran's dependence on optimization level depends on the version. If one wants to test run-time behavior and avoid compile-time simplification, it may be helpful to add: volatile :: x, y, z I then get consistent results for -O0 / -O1. > 4. My Ubuntu 20.04.5 LTS with compiler ifort 2021.7.1 computes the complex > division `x/x` accurately even for the case of huge numbers. Scenarios > tested: > - I tested the program in > https://github.com/Reference-LAPACK/lapack/blob/master/INSTALL/ > test_zcomplexdiv.f and the one in https://godbolt.org/z/b3WKWodvn. > - I tested ifort with flags -fp-model precise and -fp-model fast. The > latter enables more aggressive optimizations on floating-point data. > - I tested compilation with optimization flags -O0, -O, -O1, -O2, -O3. Intel might be fine, but at least some current llvm-based compilers (Nvidia, AMD flang) show more or less similar behavior to gfortran. E.g. nvfortran 22.11: (1.7976931348623157E+308,1.7976931348623157E+308) (8.9884656743115795E+307,8.9884656743115795E+307) (4.4942328371557898E+307,4.4942328371557898E+307) (NaN,0.000000000000000) (NaN,0.000000000000000) (1.000000000000000,0.000000000000000) As a sidenote: we are really discussing borderline cases here, valid but only rarely occuring in normal code execution. If I replace x = cmplx( huge(0.0d0), huge(0.0d0), dp ) y = cmplx( b**(E-1), b**(E-1), dp ) by x = cmplx( nearest(huge(0.0d0),-1.d0), nearest(huge(0.0d0),-1.d0), dp ) y = cmplx( nearest(b**(E-1), -1.d0), nearest(b**(E-1), -1.d0), dp ) then I get (1.0000000000000000,0.0000000000000000) (1.0000000000000000,0.0000000000000000) instead of NaN.
next prev parent reply other threads:[~2022-11-19 20:14 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 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 [this message] 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-Lvw8witxJs@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: linkBe 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).