public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/28408]  New: What should be value of complex<double>(1.0,0.0) *= -1?
@ 2006-07-17 10:21 mec at google dot com
  2006-07-18 13:34 ` [Bug c++/28408] " bangerth at dealii dot org
                   ` (20 more replies)
  0 siblings, 21 replies; 22+ messages in thread
From: mec at google dot com @ 2006-07-17 10:21 UTC (permalink / raw)
  To: gcc-bugs

Test program:

// Copyright 2006, Google Inc.  All rights reserved.
// Author: mec@google.com  (Michael Chastain)
//
// Compute (1.0, 0.0) *= -1.0

#include <complex>
#include <iostream>

std::complex<double> d_1(1.0, 0.0);

int main() {
  std::complex<double> d_m1(1.0, 0.0);
  d_m1 *= -1.0;
  std::cout << "d_m1: " << d_m1 << std::endl;
  std::cout << std::endl;
  return 0;
}

===

This gives different results with the same version of gcc at different
optimization options.  All of these are with glibc 2.3.5.

hollerith:~/exp-i$ /home/mec/gcc-3.4.6/install/bin/g++ z4.cc && a.out
d_m1: (-1,0)

hollerith:~/exp-i$ /home/mec/gcc-3.4.6/install/bin/g++ -O2 z4.cc && a.out
d_m1: (-1,0)

hollerith:~/exp-i$ /fast/mec/gcc-4.0.3/install/bin/g++ z4.cc && a.out
d_m1: (-1,0)

hollerith:~/exp-i$ /fast/mec/gcc-4.0.3/install/bin/g++ -O2 z4.cc && a.out
d_m1: (-1,0)

hollerith:~/exp-i$ /home/mec/gcc-4.1.1/install/bin/g++ z4.cc && a.out
d_m1: (-1,0)

hollerith:~/exp-i$ /home/mec/gcc-4.1.1/install/bin/g++ -O2 z4.cc && a.out
d_m1: (-1,-0)

hollerith:~/exp-i$ /home/mec/gcc-4.2-20060624/install/bin/g++ z4.cc && a.out
d_m1: (-1,0)

hollerith:~/exp-i$ /home/mec/gcc-4.2-20060624/install/bin/g++ -O2 z4.cc &&
a.out
d_m1: (-1,-0)

===

One might argue that (-1,0) is equals to (-1,-0).  In that case, consider this
code:

  std::complex<double> d_m1(1.0, 0.0);
  d_m1 *= -1.0;
  std::complex<double> d_i(sqrt(d_m1));

See PR 28406, which shows that sqrt((-1,0)) != sqrt((-1,-0)).  So code like the
above produces materially different results with gcc 4.1.1 -O0 and gcc 4.1.1
-O2.


-- 
           Summary: What should be value of complex<double>(1.0,0.0) *= -1?
           Product: gcc
           Version: 4.1.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: mec at google dot com
 GCC build triplet: i686-pc-linux-gnu
  GCC host triplet: i686-pc-linux-gnu
GCC target triplet: i686-pc-linux-gnu


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


^ permalink raw reply	[flat|nested] 22+ messages in thread

end of thread, other threads:[~2006-09-27  8:08 UTC | newest]

Thread overview: 22+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-07-17 10:21 [Bug c++/28408] New: What should be value of complex<double>(1.0,0.0) *= -1? mec at google dot com
2006-07-18 13:34 ` [Bug c++/28408] " bangerth at dealii dot org
2006-09-06 17:11 ` pcarlini at suse dot de
2006-09-06 17:12 ` pcarlini at suse dot de
2006-09-06 18:43 ` pcarlini at suse dot de
2006-09-06 18:50 ` pinskia at gcc dot gnu dot org
2006-09-06 19:19 ` pluto at agmk dot net
2006-09-06 20:23 ` pcarlini at suse dot de
2006-09-06 20:27 ` pinskia at gcc dot gnu dot org
2006-09-06 20:59 ` pcarlini at suse dot de
2006-09-07  0:44 ` pcarlini at suse dot de
2006-09-07  1:24 ` joseph at codesourcery dot com
2006-09-07  1:33 ` pcarlini at suse dot de
2006-09-07  1:51 ` pcarlini at suse dot de
2006-09-07  1:52 ` joseph at codesourcery dot com
2006-09-07  1:58 ` joseph at codesourcery dot com
2006-09-07  2:04 ` pcarlini at suse dot de
2006-09-07  2:30 ` bangerth at math dot tamu dot edu
2006-09-07  2:47 ` pcarlini at suse dot de
2006-09-07  9:11 ` pcarlini at suse dot de
2006-09-27  7:51 ` jan at etpmod dot phys dot tue dot nl
2006-09-27  8:08 ` pcarlini at suse dot de

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