From Bugzilla Helper: User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.5) Gecko/20041111 Firefox/1.0 Description of problem: The following program produces "nan" output instead of correct 0. #include <complex> #include <iostream> int main() { std::complex<double> z1(1.0,-1.0); double x = 1.0/0.0; std::complex<double> z3 = z1/x; std::cout << "z1: " << z1 << std::endl << "x: " << x << std::endl << "z3: " << z3 << std::endl; return 0; } Version-Release number of selected component (if applicable): gcc-3.4.3-10 (and quite a few versions before) How reproducible: Always Steps to Reproduce: 1. compile program 2. run it 3. Actual Results: z1: (1,-1) x: inf z3: (nan,nan) Expected Results: z1: (1,-1) x: inf z3: 0 Additional info: As alois.schloegl pointed out <<<< Prof. W .Kahan mentions in his "Lecture Notes on the Status of IEEE 754" p.10 http://www.cs.berkeley.edu/~wkahan/ieee754status/IEEE754.PDF "when (0+3i)/inf is turned naively into (0+3i)*(inf-i)/(inf^2+0^2) it generates a NaN instead of the expected 0." >>>>
Please file this upstream (http://gcc.gnu.org/bugzilla), it is better discussed there. Reproduceable even with: #include <stdio.h> _Complex double a, r; double b = 1.0 / 0.0; int main (void) { __real__ a = 1.0; __imag__ a = -1.0; r = a / b; printf ("%f %f\n", __real__ r, __imag__ r); return 0; }
Done. See Bug c/19138