This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug libstdc++/20758] New: operator-(const T&, const complex<T>&) vs operator-(const complex<T>&, const complex<T>&)
- From: "kreckel at ginac dot de" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 4 Apr 2005 21:38:03 -0000
- Subject: [Bug libstdc++/20758] New: operator-(const T&, const complex<T>&) vs operator-(const complex<T>&, const complex<T>&)
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
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
- Follow-Ups:
- [Bug libstdc++/20758] operator-(const T&, const complex<T>&) vs operator-(const complex<T>&, const complex<T>&)
- From: kreckel at ginac dot de
- [Bug libstdc++/20758] operator-(const T&, const complex<T>&) vs operator-(const complex<T>&, const complex<T>&)
- From: kreckel at ginac dot de
- [Bug libstdc++/20758] operator-(const T&, const complex<T>&) vs operator-(const complex<T>&, const complex<T>&)
- From: kreckel at ginac dot de
- [Bug libstdc++/20758] operator-(const T&, const complex<T>&) vs operator-(const complex<T>&, const complex<T>&)
- From: pinskia at gcc dot gnu dot org
- [Bug libstdc++/20758] operator-(const T&, const complex<T>&) vs operator-(const complex<T>&, const complex<T>&)
- From: kreckel at ginac dot de
- [Bug libstdc++/20758] operator-(const T&, const complex<T>&) vs operator-(const complex<T>&, const complex<T>&)
- From: pinskia at gcc dot gnu dot org
- [Bug libstdc++/20758] operator-(const T&, const complex<T>&) vs operator-(const complex<T>&, const complex<T>&)
- From: pcarlini at suse dot de
- [Bug libstdc++/20758] operator-(const T&, const complex<T>&) vs operator-(const complex<T>&, const complex<T>&)
- From: kreckel at ginac dot de
- [Bug libstdc++/20758] operator-(const T&, const complex<T>&) vs operator-(const complex<T>&, const complex<T>&)
- From: pcarlini at suse dot de
- [Bug libstdc++/20758] operator-(const T&, const complex<T>&) vs operator-(const complex<T>&, const complex<T>&)
- From: pcarlini at suse dot de
- [Bug libstdc++/20758] operator-(const T&, const complex<T>&) vs operator-(const complex<T>&, const complex<T>&)
- From: pcarlini at suse dot de
- [Bug libstdc++/20758] operator-(const T&, const complex<T>&) vs operator-(const complex<T>&, const complex<T>&)
- From: gdr at integrable-solutions dot net
- [Bug libstdc++/20758] operator-(const T&, const complex<T>&) vs operator-(const complex<T>&, const complex<T>&)
- From: pcarlini at suse dot de
- [Bug libstdc++/20758] operator-(const T&, const complex<T>&) vs operator-(const complex<T>&, const complex<T>&)
- From: pcarlini at suse dot de
- [Bug libstdc++/20758] operator-(const T&, const complex<T>&) vs operator-(const complex<T>&, const complex<T>&)
- From: kreckel at ginac dot de
- [Bug libstdc++/20758] operator-(const T&, const complex<T>&) vs operator-(const complex<T>&, const complex<T>&)
- From: pcarlini at suse dot de
- [Bug libstdc++/20758] operator-(const T&, const complex<T>&) vs operator-(const complex<T>&, const complex<T>&)
- From: kreckel at ginac dot de
- [Bug libstdc++/20758] operator-(const T&, const complex<T>&) vs operator-(const complex<T>&, const complex<T>&)
- From: pcarlini at suse dot de
- [Bug libstdc++/20758] operator-(const T&, const complex<T>&) vs operator-(const complex<T>&, const complex<T>&)
- From: kreckel at ginac dot de
- [Bug libstdc++/20758] operator-(const T&, const complex<T>&) vs operator-(const complex<T>&, const complex<T>&)
- From: pcarlini at suse dot de
- [Bug libstdc++/20758] operator-(const T&, const complex<T>&) vs operator-(const complex<T>&, const complex<T>&)
- From: gdr at integrable-solutions dot net
- [Bug libstdc++/20758] operator-(const T&, const complex<T>&) vs operator-(const complex<T>&, const complex<T>&)
- From: gdr at integrable-solutions dot net
- [Bug libstdc++/20758] operator-(const T&, const complex<T>&) vs operator-(const complex<T>&, const complex<T>&)
- From: kreckel at ginac dot de
- [Bug libstdc++/20758] operator-(const T&, const complex<T>&) vs operator-(const complex<T>&, const complex<T>&)
- From: kreckel at ginac dot de