piggy@GARGOYLE.UCHICAGO.EDU (10/31/89)
------- Forwarded Message Received: by gargoyle.uchicago.edu from tartarus.uchicago.edu (5.59/1.14) id AA18981; Thu, 26 Oct 89 16:47:36 198 Received: by tartarus.uchicago.edu (4.0/4.7) id AA15018; Thu, 26 Oct 89 16:49:06 CDT Date: Thu, 26 Oct 89 16:49:06 CDT From: keenan@tartarus.UChicago.EDU (Philip Keenan) Message-Id: <8910262149.AA15018@tartarus.uchicago.edu> To: bugs@tartarus.uchicago.edu Subject: Another bug in GNU C++ Cc: keenan@tartarus.uchicago.edu Here is another bug you can forward to the GNU people. It is an especially nasty and subtle one, where something internal has the wrong value, but when you print the value to check, the act of printing gets rid of the bug, so it prints the correct value, leaving you to wonder why it fails when you comment out the print line! - -- Phil Kenan *************************************************************** /* bug.cc Phil Keenan 10-25-89. This short program illustrates a bug in GNU C++ v. 1.35.1- As it stands, it produces as output "0" and "1", which is incorrect. They should both be "1". If you simply uncomment the commented out line in function complex::cabsv(), it does compute them correctly. */ #include <stream.h> double absv(double d) { if(d>=0) return d; else return -d; } struct complex { double r, i; complex(double re=0, double im=0) { r=re; i=im; } double cabsv(); }; double complex::cabsv() { double x,y; x = absv(r); y = absv(i); // cout << x << " " << y << "\n"; if(x==0.0) return y; if(y==0.0) return x; return 100; } void main() { complex e; e = complex(0,1); cout << e.cabsv() << "\n"; e = complex(1,0); cout << e.cabsv() << "\n"; } *************************************************************** The end. ------- End of Forwarded Message