home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / dos / math / zpp / complex.h < prev    next >
Encoding:
C/C++ Source or Header  |  1992-04-03  |  4.3 KB  |  116 lines

  1. /* -------------------------------------------------------------------- */
  2. /* complex.h                                */
  3. /*                                    */
  4. /* Z++ Version 1.0                Last revised 04/03/92    */
  5. /*                                    */
  6. /* Complex number class for Turbo C++/Borland C++.            */
  7. /* Copyright 1992 by Carl W. Moreland                    */
  8. /* This source code may be freely distributed as long as the copyright    */
  9. /* notice remains intact.                        */
  10. /* -------------------------------------------------------------------- */
  11.  
  12. #ifndef COMPLEXdotH
  13. #define COMPLEXdotH
  14.  
  15. #include <math.h>
  16. #include <iostream.h>
  17.  
  18. #define Z_RADIANS    0
  19. #define Z_DEGREES    1
  20. #define Z_COMMA        0        // (x, y)
  21. #define Z_LETTER    1        // x + iy
  22.  
  23. class complex
  24. {
  25. public:
  26.   double re, im;
  27.  
  28. //private:
  29.   static unsigned char zArgMode;
  30.   static unsigned char zPrintMode;
  31.   static unsigned char zLetter;
  32.  
  33. public:
  34.   complex(void);
  35.   complex(const double re, const double im=0);
  36.   complex(const complex& z);
  37.  
  38.   friend double    re(const complex& z); // real part
  39.   friend double    im(const complex& z); // imaginary part
  40.   friend double  real(const complex& z); // real part
  41.   friend double  imag(const complex& z); // imaginary part
  42.   friend double   mag(const complex& z); // magnitude
  43.   friend double   arg(const complex& z); // argument
  44.   friend double   ang(const complex& z) { return arg(z);}
  45.   friend double    ph(const complex& z) { return arg(z);}
  46.   friend complex conj(const complex& z); // complex conjugate
  47.   friend double  norm(const complex& z); // the square of the magnitude
  48.  
  49.   friend complex rtop(double x,   double y=0);
  50.   friend complex ptor(double mag, double angle=0);
  51.   complex& topolar(void);
  52.   complex& torect(void);
  53.  
  54.   void     operator  = (const complex&); // z1  = z2
  55.   complex& operator += (const complex&); // z1 += z2
  56.   complex& operator -= (const complex&); // z1 -= z2
  57.   complex& operator *= (const complex&); // z1 *= z2
  58.   complex& operator /= (const complex&); // z1 /= z2
  59.   complex  operator +  (void) const;     // +z1
  60.   complex  operator -  (void) const;     // -z1
  61.  
  62.   friend complex operator +  (const complex&, const complex&);
  63.   friend complex operator +  (const complex&, const double);
  64.   friend complex operator +  (const double,   const complex&);
  65.   friend complex operator -  (const complex&, const complex&);
  66.   friend complex operator -  (const complex&, const double);
  67.   friend complex operator -  (const double,   const complex&);
  68.   friend complex operator *  (const complex&, const complex&);
  69.   friend complex operator *  (const complex&, const double);
  70.   friend complex operator *  (const double,   const complex&);
  71.   friend complex operator /  (const complex&, const complex&);
  72.   friend complex operator /  (const complex&, const double);
  73.   friend complex operator /  (const double,   const complex&);
  74.   friend complex operator ^  (const complex&, const complex&);
  75.   friend int     operator == (const complex&, const complex&);
  76.   friend int     operator != (const complex&, const complex&);
  77.  
  78.   friend double    abs(const complex& z);
  79.   friend complex  sqrt(const complex& z);
  80.   friend complex   pow(const complex& base, const complex& exp);
  81.   friend complex   pow(const complex& base, const double   exp);
  82.   friend complex   pow(const double   base, const complex& exp);
  83.  
  84.   friend complex   exp(const complex& z);
  85.   friend complex   log(const complex& z);
  86.   friend complex    ln(const complex& z) { return log(z); }
  87.   friend complex log10(const complex& z);
  88.  
  89.   friend complex   cos(const complex& z);
  90.   friend complex   sin(const complex& z);
  91.   friend complex   tan(const complex& z);
  92.  
  93.   friend complex  acos(const complex& z);
  94.   friend complex  asin(const complex& z);
  95.   friend complex  atan(const complex& z);
  96.  
  97.   friend complex  cosh(const complex& z);
  98.   friend complex  sinh(const complex& z);
  99.   friend complex  tanh(const complex& z);
  100.  
  101.   void SetArgMode(unsigned char mode) const;
  102.   void SetPrintMode(unsigned char mode) const;
  103.   void SetLetter(unsigned char letter) const;
  104. };
  105.  
  106. ostream& operator<<(ostream&, const complex&);
  107. istream& operator>>(istream&, const complex&);
  108.  
  109. static const complex Z0(0, 0);        // complex number 0
  110. static const complex Z1(1, 0);        // complex number 1
  111. static const complex Zi(0, 1);        // complex number i
  112. static const complex Zinf(HUGE_VAL, HUGE_VAL); // complex number infinity
  113. static const complex Complex;
  114.  
  115. #endif
  116.