// // Complex Elementary Functions defined in C++ Standard Library // Copyright (c) 2008- Tomonori Kouya // #include #include using namespace std; // print usage void usage(const char *progname) { cout << "Usage: " << progname << " x_real x_image" << endl; } int main(int argc, char *argv[]) { double x_real, x_image; complex x; // input x_real, x_image if argc == 1 if(argc <= 1) { cout << "Input x_real and x_image" << endl; cout << "x_real = "; cin >> x_real; cout << "x_image = "; cin >> x_image; } else { x_real = atof(argv[1]); x_image = 0.0; if(argc >= 3) x_image = atof(argv[2]); } // convert to complex number x.real(x_real); x.imag(x_image); // print x as standard style printf("x = ( %25.17g ) + ( %25.17g ) * I\n", x.real(), x.imag()); // print conjugate of x printf("conj(x) = ( %25.17g ) + ( %25.17g ) * I\n", conj(x).real(), conj(x).imag()); // print x as polar style printf("|x|,arg(x) = %25.17g , %25.17g\n", abs(x), arg(x)); // print sqrt(x) printf("sqrt(x) = ( %25.17g ) + ( %25.17g ) * I\n", sqrt(x).real(), sqrt(x).imag()); // print pow(x, 0.5) (= sqrt(x)) printf("pow(x,1/2) = ( %25.17g ) + ( %25.17g ) * I\n", pow(x, 0.5).real(), pow(x, 0.5).imag()); // print exp(x) printf("exp(x) = ( %25.17g ) + ( %25.17g ) * I\n", exp(x).real(), exp(x).imag()); // print sinh(x) printf("sinh(x) = ( %25.17g ) + ( %25.17g ) * I\n", sinh(x).real(), sinh(x).imag()); // print cosh(x) printf("cosh(x) = ( %25.17g ) + ( %25.17g ) * I\n", cosh(x).real(), cosh(x).imag()); // print sinh(x) printf("tanh(x) = ( %25.17g ) + ( %25.17g ) * I\n", tanh(x).real(), tanh(x).imag()); // print sin(x) printf("sin(x) = ( %25.17g ) + ( %25.17g ) * I\n", sin(x).real(), sin(x).imag()); // print cos(x) printf("cos(x) = ( %25.17g ) + ( %25.17g ) * I\n", cos(x).real(), cos(x).imag()); // print tan(x) printf("tan(x) = ( %25.17g ) + ( %25.17g ) * I\n", tan(x).real(), tan(x).imag()); // print log(x) printf("log(x) = ( %25.17g ) + ( %25.17g ) * I\n", log(x).real(), log(x).imag()); // print log10(x) printf("log10(x) = ( %25.17g ) + ( %25.17g ) * I\n", log10(x).real(), log10(x).imag()); // print pow(x, x) (= x^x) printf("pow(x, x) = ( %25.17g ) + ( %25.17g ) * I\n", pow(x, x).real(), pow(x, x).imag()); // Exit return 0; }