// test1_complex.cc simple test to see if complex template is working #include #include using namespace std; int main(int argc, char *argv[]) { complex aa(1.2, 3.4); // construct variable aa with value 1.2+i3.4 complex bb(-9.8, -7.6); complex cc; cc = complex(2.3, 3.2);// NOT just (2.3, 3.2), would get 3.2+i0 aa += bb; // just try a few arithmetic operations aa /= sin(bb) * cos(aa); // just try a few functions bb *= log(bb) + exp(aa); cc = sqrt(pow(cc, 2.0)); cout << "aa= " << aa << ", bb= " << bb << ", cc= " << cc << endl; complex a(1.2F, 3.4F); // now repeat with float rather than double complex b(-9.8F, -7.6F); complex c; c = complex(2.3F, 3.2F); a += b; a /= sin(b) * cos(a); b *= log(b) + exp(a); c = sqrt(pow(c, 2.0)); cout << "a = " << a << ", b = " << b << ", c = " << c << endl; return 0; } // results: // aa= (1.42804e-06,-0.0002873), bb= (-53.3398,-2.40943), cc= (2.3,3.2) // a = (1.42818e-06,-0.0002873), b = (-53.3398,-2.40943), c = (2.3,3.2)