public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/20758] New: operator-(const T&, const complex<T>&) vs operator-(const complex<T>&, const complex<T>&)
@ 2005-04-04 21:38 kreckel at ginac dot de
  2005-04-04 21:39 ` [Bug libstdc++/20758] " kreckel at ginac dot de
                   ` (23 more replies)
  0 siblings, 24 replies; 27+ messages in thread
From: kreckel at ginac dot de @ 2005-04-04 21:38 UTC (permalink / raw)
  To: gcc-bugs

Here are three ways to express complex<double>(-4.,0.):

    // complex<double> operator-<double>(const double&, const complex<double>&)
    complex<double> a1 = 1.
	               - complex<double>(5.0, 0.0);
    cout << a1 << endl;  // (-4,-0)
    // complex<double> operator-<double>(const complex<double>&, const
complex<double>&)
    complex<double> a2 = complex<double>(1.0, 0.0)
	               - complex<double>(5.0, 0.0);
    cout << a2 << endl;  // (-4,0)
    // complex<double> operator-<double>(const complex<double>&, const double&)
    complex<double> a3 = complex<double>(1.0, 0.0)
                       - 5.0;
    cout << a3 << endl;  // (-4,0)

In the first version, the imaginary part gets a spurious minus sign.  That is
quite disruptive when you consider that a1 could be the argument of a logarithm
because it then ends up on the wrong side of the branch cut.

While I am currently unable to track this to any standard, I would guess that
the resulting imaginary part should be governed by what 0.0-0.0 is.  By analogy,
the first result would be wrong, unless its undefined behavior (which would be a
pity).

The problem is in libstdc++-v3/include/std/std_complex.h:366.  I propose to
change the function body to not use unary operator- in the imaginary part.  I'm
going to attach two analogous patches.

-- 
           Summary: operator-(const T&, const complex<T>&) vs operator-
                    (const complex<T>&, const complex<T>&)
           Product: gcc
           Version: 4.0.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: libstdc++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: kreckel at ginac dot de
                CC: gcc-bugs at gcc dot gnu dot org


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


^ permalink raw reply	[flat|nested] 27+ messages in thread
[parent not found: <bug-20758-1882@http.gcc.gnu.org/bugzilla/>]

end of thread, other threads:[~2010-01-06 16:37 UTC | newest]

Thread overview: 27+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-04-04 21:38 [Bug libstdc++/20758] New: operator-(const T&, const complex<T>&) vs operator-(const complex<T>&, const complex<T>&) kreckel at ginac dot de
2005-04-04 21:39 ` [Bug libstdc++/20758] " kreckel at ginac dot de
2005-04-04 21:40 ` kreckel at ginac dot de
2005-04-04 21:42 ` kreckel at ginac dot de
2005-04-04 21:45 ` pinskia at gcc dot gnu dot org
2005-04-04 21:52 ` kreckel at ginac dot de
2005-04-04 23:18 ` pinskia at gcc dot gnu dot org
2005-04-04 23:37 ` pcarlini at suse dot de
2005-04-05 14:01 ` kreckel at ginac dot de
2005-04-05 14:36 ` pcarlini at suse dot de
2005-04-05 14:48 ` pcarlini at suse dot de
2005-04-05 15:29 ` pcarlini at suse dot de
2005-04-06  8:59 ` gdr at integrable-solutions dot net
2005-04-06  9:17 ` pcarlini at suse dot de
2005-04-06  9:27 ` pcarlini at suse dot de
2005-04-07 20:51 ` kreckel at ginac dot de
2005-04-07 21:17 ` pcarlini at suse dot de
2005-04-07 22:06 ` kreckel at ginac dot de
2005-04-07 22:19 ` pcarlini at suse dot de
2005-04-08  8:23 ` kreckel at ginac dot de
2005-04-08  9:55 ` pcarlini at suse dot de
2005-04-08 14:16 ` gdr at integrable-solutions dot net
2005-04-08 14:20 ` gdr at integrable-solutions dot net
2005-04-08 22:16 ` kreckel at ginac dot de
2005-04-24 22:49 ` kreckel at ginac dot de
     [not found] <bug-20758-1882@http.gcc.gnu.org/bugzilla/>
2006-01-30  4:40 ` pinskia at gcc dot gnu dot org
2010-01-06 16:37 ` paolo dot carlini at oracle dot com

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).