https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107753

--- Comment #12 from Steve Kargl <sgk at troutmask dot apl.washington.edu> ---
On Sat, Nov 19, 2022 at 08:14:01PM +0000, anlauf at gcc dot gnu.org wrote:
> 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.
> 

The optimization level is irrelevant.  gfortran unilaterally
uses -fcx-fortran-rules, and there is no way to disable this
option to user the slower, but stricter, evaluation.  One
will always get complex division computed by

a+ib   a + b(d/c)     b - a(d/c) 
---- = ---------- + i ------------  |c| > |d|
c+id   c + d(d/c)     c + d(d/c)

and similar for |d| > |c|.

There are a few problems with this. d/c can trigger an invalid underflow
exception.  If d == c, you then have numerators of a + b and b - a, you
can get a invalid overflow for a = huge() and b > 1e291_8.

Reply via email to