// ------------------------------------------------------------ // complex.h 7 Sept 2000 // ------------------------------------------------------------ // use class Complex to avoid confusion with the standard class complex #ifndef Complex_h #define Complex_h class Complex { // The usual convention is to put public first, but ... private: double re,im; // put first to be 'visible' public: Complex( double x = 0, double y = 0); Complex(const Complex &z); // copy constructor Complex &operator=(const Complex &); // assignment operator inline double &real() { return re; } // note the & inline double &imag() { return im; } friend double real(const Complex &); friend double imag(const Complex &); friend Complex conj(const Complex &); friend Complex operator-(const Complex &); friend Complex operator+(const Complex &, const Complex &); friend Complex operator-(const Complex &, const Complex &); friend Complex operator*(const Complex &, const Complex &); // Capper (259) points out the next line is redundant, by casting // friend Complex operator*( double r, const Complex &); friend double norm2(const Complex &); friend double norm(const Complex &); friend double arg(const Complex &); friend Complex powi(const Complex &, int); // int powers friend Complex power(const Complex &, double); friend Complex exp(const Complex &c); }; // optional format apparatus for use with p(Complex) char Cstr[10] = ".6g"; // GLOBAL format-string for Complex inline void setCstr(char *s) { strcpy(Cstr,s); } #endif