From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 702 invoked by alias); 27 Feb 2008 20:31:03 -0000 Received: (qmail 529 invoked by alias); 27 Feb 2008 20:30:20 -0000 Date: Wed, 27 Feb 2008 20:31:00 -0000 Message-ID: <20080227203020.528.qmail@sourceware.org> X-Bugzilla-Reason: CC References: Subject: [Bug c++/35389] error in norm() of STL In-Reply-To: Reply-To: gcc-bugzilla@gcc.gnu.org To: gcc-bugs@gcc.gnu.org From: "pluto at agmk dot net" Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2008-02/txt/msg02879.txt.bz2 ------- Comment #4 from pluto at agmk dot net 2008-02-27 20:30 ------- Subject: Re: error in norm() of STL On Wednesday 27 of February 2008 21:13:13 ywei at qualcomm dot com wrote: > ------- Comment #3 from ywei at qualcomm dot com 2008-02-27 20:13 ------- > Subject: RE: error in norm() of STL > > I did additional test based your test code. You are right that norm() > seems to be fine. The problem happens when I try to cast the return > double value of norm() to unsigned long long (please see my test code > below and the corresponding output). Still, it bothers me that if I > carry out the norm calculation explicitly, instead of calling norm(), > there is no such an issue. > > Thanks, > - Yongbin > > My test code: > ================================================================= > #include > #include > > using namespace std; > > main() { > > complex tt(8,1); > double x, y; > > x = norm(tt); > double r = tt.real(), i = tt.imag(); > y = r*r + i*i; > > cout << tt << "\t" << (unsigned long long)x << "\t" << (unsigned > long long)y << endl; > cout << tt << "\t" << x << "\t" << y << endl; > } > ====================================== > The output > (8,1) 64 65 > (8,1) 65 65 $ ./a.out (8,1) 64 65 (8,1) 64.999999999999985789 65 (long long)64.99999 -> 64. ------- Comment #5 from pluto at agmk dot net 2008-02-27 20:30 ------- Created an attachment (id=15239) --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=15239&action=view) -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35389