From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 23590 invoked by alias); 4 Apr 2005 21:38:06 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org Received: (qmail 23525 invoked by uid 48); 4 Apr 2005 21:38:03 -0000 Date: Mon, 04 Apr 2005 21:38:00 -0000 From: "kreckel at ginac dot de" To: gcc-bugs@gcc.gnu.org Message-ID: <20050404213802.20758.kreckel@ginac.de> Reply-To: gcc-bugzilla@gcc.gnu.org Subject: [Bug libstdc++/20758] New: operator-(const T&, const complex&) vs operator-(const complex&, const complex&) X-Bugzilla-Reason: CC X-SW-Source: 2005-04/txt/msg00366.txt.bz2 List-Id: Here are three ways to express complex(-4.,0.): // complex operator-(const double&, const complex&) complex a1 = 1. - complex(5.0, 0.0); cout << a1 << endl; // (-4,-0) // complex operator-(const complex&, const complex&) complex a2 = complex(1.0, 0.0) - complex(5.0, 0.0); cout << a2 << endl; // (-4,0) // complex operator-(const complex&, const double&) complex a3 = complex(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&) vs operator- (const complex&, const complex&) 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