KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I'm trying to create a complex infinity equal to Inf+Inf*j where j is the complex variable. When I do this : #include <complex> #include <limits> using std; ... complex<double> attempt1 = complex<double>( numeric_limits<double>::infinity(), numeric_limits<double>::infinity() ); returns the complex number (NaN + Inf*j). But complex<double> attempt2 = complex<double>( numeric_limits<double>::infinity() ); returns the complex number (Inf + 0*j). Also : complex<double> attempt_at_imag_inf = complex<double>(any_value_here, numeric_limits<double>::infinity()); returns the complex number (NaN + Inf*j). Does anybody know what's going on here? Any time I attempt to have infinty for the imaginary part, then NaN is written on the real part. The above only applies to types that support NaN and Infinity of course. I am using g++ v4.6.1. I've looked at the numeric_limits header and there is no indication that the above should happen at all. To put the above into context, I'm actually doing the above in a partial specialization of numeric_limits for complex. Many thanks for considering this problem. REVISION TO ORIGINAL POST I'm providing a complete but short program to illustrate the problem. I've also included some more qualifying information on how the program should be compiled to generate the results. #include <iostream> #include <complex> #include <limits> using namespace std; int main(int argc, char* argv[]) { complex<double> my_complex_inf = complex<double>(numeric_limits<double>::infinity(), numeric_limits<double>::infinity()); cout << "my_complex_inf = " << my_complex_inf << endl; complex&l
Tags (comma-separated)
Save Edits
Cancel