public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "kreckel at ginac dot de" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug libstdc++/20758] New: operator-(const T&, const complex<T>&) vs operator-(const complex<T>&, const complex<T>&) Date: Mon, 04 Apr 2005 21:38:00 -0000 [thread overview] Message-ID: <20050404213802.20758.kreckel@ginac.de> (raw) 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
next reply other threads:[~2005-04-04 21:38 UTC|newest] Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top 2005-04-04 21:38 kreckel at ginac dot de [this message] 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
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=20050404213802.20758.kreckel@ginac.de \ --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).