http://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=221319 raises a question whether: std::complex<double> (1.0, 1.0) / 0.0 and std::complex<double> (1.0, 1.0) / std::complex<double> (0.0, 0.0) can or can't be NaN. In C say: #define I (__extension__ 1.0iF) _Complex double d = 1.0 + 0.0 * I, e, f, z = 0.0 + 0.0 * I;
int main (void) { e = d / 0.0; f = d / z; __builtin_printf ("%g %g %g %g\n", __real__ e, __imag__ e, __real__ f, __imag__ f); return 0; } in -std=c99 always prints inf (where complex inf is even when just one of the parts is inf), no matter what optimization options, in C89 the first division when optimizing is usually optimized into the simpler __real__ d / 0.0, __imag__ d / 0.0 division and thus gives inf too, but the latter and when not optimizing even the first one gives NaN. What do we want in C++? C++ doesn't use flag_complex_method = 2, so unless that changes, only the division by double (rather than std::complex <double>) could generally (when not optimizing) return inf - with a help in the specialization, see the above URL. -- Summary: <complex> division by 0 Product: gcc Version: 4.1.2 Status: UNCONFIRMED Severity: normal Priority: P3 Component: libstdc++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: jakub at gcc dot gnu dot org http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30482