home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_09_01 / 9n01124a < prev    next >
Text File  |  1990-06-10  |  3KB  |  90 lines

  1. // complex.hpp
  2. #include <math.h>
  3. #include <stdio.h>
  4.  
  5. class complex {
  6.    protected: 
  7.       double x,y;
  8.    public:
  9. //      complex( double xx = 0., double yy = 0.) //create
  10. //         { x=xx;y=yy;}
  11.         complex( double xx , double yy = 0.) //create
  12.          { x=xx;y=yy;}
  13.         complex( ) //create
  14.          { x=0.;y=0.;}
  15.       inline void operator=(complex rvalue)
  16.          {x=rvalue.x;y=rvalue.y;}
  17.       inline void operator-=(complex rvalue)
  18.          {x-=rvalue.x;y-=rvalue.y;}
  19.       inline void operator+=(complex rvalue)
  20.          {x+=rvalue.x;y+=rvalue.y;}
  21.       inline void operator*=(complex rvalue)
  22.          {
  23.           *this=complex(rvalue.x*x-rvalue.y*y, 
  24.             rvalue.x*y+rvalue.y*x);
  25.           //return *this;
  26.          }
  27.       inline void operator*=(double rvalue)
  28.          {
  29.          *this=complex(rvalue*x, rvalue*y);//return *this;
  30.          }
  31.       inline complex operator+(complex rvalue)
  32.          {return complex(x+rvalue.x,y+rvalue.y);}
  33.       inline complex operator-(complex rvalue)
  34.          {return complex(x-rvalue.x,y-rvalue.y);}
  35.       inline complex operator-() //unary minus
  36.          {return complex(-x,-y);}
  37.       inline complex operator*(complex rvalue)
  38.          {return complex(
  39.           rvalue.x*x-rvalue.y*y,
  40.           rvalue.x*y+rvalue.y*x);}
  41.       inline friend complex operator/(double dividend,complex divisor)
  42.          { double temp;
  43.          temp=1./(divisor.x*divisor.x+divisor.y*divisor.y);
  44.            return complex((dividend*divisor.x)*temp,
  45.            (-dividend*divisor.y)*temp);
  46.          }
  47.       inline complex operator/(complex divisor)
  48.          { 
  49.          double temp;
  50.          temp=1./(divisor.x*divisor.x+divisor.y*divisor.y);
  51.                return complex((divisor.x*x+divisor.y*y)*temp,
  52.             (divisor.x*y-divisor.y*x)*temp);
  53.          }
  54.       inline int operator==(complex rvalue)
  55.          {return (x==rvalue.x && y==rvalue.y);}
  56.       inline double real() {return x;}
  57.       inline double imaginary() {return y;}
  58.       inline complex conjugate()
  59.          {return complex(x,-y);}
  60.       inline friend complex operator*(complex num,double real)
  61.          {return complex(num.x*real,num.y*real);}
  62.       inline friend complex operator*(double real,complex num)
  63.          {return complex(num.x*real,num.y*real);}
  64.       inline friend complex operator+(complex num,double real)
  65.          {return complex(num.x+real,num.y);}
  66.       inline friend complex operator+(double real,complex num)
  67.          {return complex(num.x+real,num.y);}
  68.       inline complex operator+=(double real)
  69.          {return complex(x+=real,y);}
  70.       inline complex operator-=(double real)
  71.          {
  72.          return complex(x-=real,y);}
  73.       inline complex operator++()
  74.          {x+=1.;return *this;}
  75.       inline friend complex operator/(complex num,double real)
  76.          {return complex(num.x/real,num.y/real);}
  77.       inline friend complex operator-(complex num,double real)
  78.          {return complex(num.x-real,num.y);}
  79.       inline friend complex operator-(double real,complex num)
  80.          {return complex(real-num.x,-num.y);}
  81.       double abs();
  82.       complex cexp();
  83.       complex clog();
  84.       complex operator^(double expon);
  85.       complex operator^(complex expon);
  86.       friend complex operator^(double base, complex expon);
  87.       void print( char *ahead="",char *behind="");
  88.       complex hurwitz(complex );
  89.    };
  90.