public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "dominiq at lps dot ens dot fr" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug fortran/40318] Complex division by zero in gfortran returns wrong results
Date: Mon, 01 Jun 2009 10:19:00 -0000	[thread overview]
Message-ID: <20090601101917.7217.qmail@sourceware.org> (raw)
In-Reply-To: <bug-40318-578@http.gcc.gnu.org/bugzilla/>



------- Comment #3 from dominiq at lps dot ens dot fr  2009-06-01 10:19 -------
In http://gcc.gnu.org/ml/fortran/2009-06/msg00006.html, Dennis Wassel 
wrote:
> Complex numbers have a well-defined concept of infinity, which I like to
> visualise as the "infinite-diameter" ring around the finite complex
> numbers, so its argument is, of course, not well-defined.  This is
> conceptually somewhat different from the two points +/-Inf on the real
> line, and it is not signed.

My understanding of infinity in the complex plane is what is called (I
call?)  "directed inifinity": if abs((a,b)) goes to +Inf and atan2(a,b) has
a defined value in this limit, then (a,b) goes to infinity in the direction
given by atan2(a,b).  However (+/-Inf,+/-Inf) defines only four directions
and is unable to represent general "directed inifinity".  So I think that
from a "mathematical" point of view the problem is ill-posed,
(+/-Inf,+/-Inf) is in the same class of "undefined" values as 0/0 or
Inf/Inf, and should give NaNs.

Now atan2(a,b) is DEFINED such that atan2(+0,+/-0)=+/-0,
atan2(-0,+/-0)=+/-Pi, atan2(+Inf,+/-Inf)=+/-Pi/4,
atan2(-Inf,+/-Inf)=+/-3*Pi/4 (it seems that it is even built in the Intel
hardware).  With this definition of atan2, it is possible to give a
definition of (+/-Inf,+/-Inf) as the directions of the corners of the
"infinite square".  I have nothing against this defintion, except it should
be documented.

Part of the problem originates from the optimization of (a,b)/(c,0.0) as
(a/c,b/c), see pr30482, and it limit when c goes to 0 (the latter giving
(+/-Inf,+/-Inf) if b/=0.0 or has a unknown value at compile time,
(+/-Inf,+/-0) if b known to be zero at compile time, optimized as
(a/c,+/-0.0), or (+/-Inf,-/+Nan) if b==0 at run time).

Note that due to the definition of atan2(+/-0,+/-0),
(+/-0,+/-0)=0*exp((+/-k*Pi,+/-0)) (k being 0 or 1), then to be consistent
1.0/(+/-0.0,+/-0.0) should give 1/0.0*exp((-/+k*Pi,-/+0))=(+/-Inf,-/+Nan).

Last remark, if I remember correctly (I cannot find the right pointer) C99 
defines precisely how complex multiplications should behave in the 
exception limits, with the drawback of a large increase of the computation 
cost avoided with the -fcx-fortran-rules option.

As far as I can tell:

(1) Without the IEEE module, using or producing Inf or NaN makes the code 
non (fortran) standard comforming, so the "processor" can give any answer.

(2) With the IEEE module, Inf and NaN are part of the numerical model, 
however I did not find any definition of the values that intrinsincs 
should return in such cases.

To conclude, I'll repeat that in my opinion the only relevant answer for
overflow, divide by zero, or invalid argument exceptions is "call abort()".
Since I know that it is a lost battle, I think at least the behavior shall
not increase the computation time with complex numbers (or provide a way to
avoid the penalty).  Now if the fxxxx standard does not define the expected
result, but the C99 does, the best answer to this ill-posed problem is
probably to follow the C99 standard if possible (I have no idea of what
does mpc).  In this case the results at compile and run times should be the
same ("least surprising approach").


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40318


  parent reply	other threads:[~2009-06-01 10:19 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-06-01  6:15 [Bug fortran/40318] New: " ghazi at gcc dot gnu dot org
2009-06-01  6:55 ` [Bug fortran/40318] " kargl at gcc dot gnu dot org
2009-06-01  8:35 ` ghazi at gcc dot gnu dot org
2009-06-01 10:19 ` dominiq at lps dot ens dot fr [this message]
2009-06-01 11:10 ` burnus at gcc dot gnu dot org
2009-06-01 11:24 ` dominiq at lps dot ens dot fr
2009-06-01 12:15 ` dennis dot wassel at googlemail dot com
2009-06-01 12:25 ` dominiq at lps dot ens dot fr
2009-06-01 14:21 ` jb at gcc dot gnu dot org
2009-06-01 14:56 ` sgk at troutmask dot apl dot washington dot edu
2009-06-01 18:15 ` ghazi at gcc dot gnu dot org
2009-06-01 19:16 ` sgk at troutmask dot apl dot washington dot edu
2009-06-01 20:34 ` burnus at gcc dot gnu dot org
2009-06-02 15:17 ` ghazi at gcc dot gnu dot org
2009-12-18 14:42 ` pault at gcc dot gnu dot org
2009-12-18 15:52 ` sgk at troutmask dot apl dot washington dot edu
2009-12-18 17:16 ` ghazi at gcc dot gnu dot org
2009-12-19 19:46 ` kargl at gcc dot gnu dot 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=20090601101917.7217.qmail@sourceware.org \
    --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).