home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c083 / 14.ddi / GENINC.PAK / COMPLEX.H < prev    next >
Encoding:
C/C++ Source or Header  |  1993-12-02  |  8.3 KB  |  287 lines

  1. /* complex.h
  2.  
  3.     Complex Number Library - Include File
  4.     class complex:  declarations for complex numbers.
  5.  
  6. All function names, member names, and operators have been borrowed
  7. from AT&T C++, except for the addition of:
  8.  
  9.     friend complex _Cdecl acos(complex _FAR &);
  10.     friend complex _Cdecl asin(complex _FAR &);
  11.     friend complex _Cdecl atan(complex _FAR &);
  12.     friend complex _Cdecl log10(complex _FAR &);
  13.     friend complex _Cdecl tan(complex _FAR &);
  14.     friend complex _Cdecl tanh(complex _FAR &);
  15.     complex _Cdecl operator+();
  16.     complex _Cdecl operator-();
  17. */
  18.  
  19. /*
  20.  *      C/C++ Run Time Library - Version 6.0
  21.  *
  22.  *      Copyright (c) 1990, 1993 by Borland International
  23.  *      All Rights Reserved.
  24.  *
  25.  */
  26.  
  27. #ifndef __cplusplus
  28. #error Must use C++ for the type complex.
  29. #endif
  30.  
  31. #if !defined(__COMPLEX_H)
  32. #define __COMPLEX_H
  33.  
  34. #pragma warn -nak   /* Ignore non-ansi keywords */
  35.  
  36. #if !defined(___DEFS_H)
  37. #include <_defs.h>
  38. #endif
  39.  
  40. #if !defined(__MATH_H)
  41. #include <math.h>
  42. #endif
  43.  
  44. #if !defined(__IOSTREAM_H)
  45. #include <iostream.h>
  46. #endif
  47.  
  48.  
  49. #pragma option -Vo-
  50. #if defined(__BCOPT__) && !defined(_RTL_ALLOW_po) && !defined(__FLAT__)
  51. #pragma option -po-
  52. #endif
  53.  
  54. class _EXPCLASS complex {
  55.  
  56. public:
  57.     // constructors
  58.     _RTLENTRY complex(double __re_val, double __im_val=0);
  59.     _RTLENTRY complex();
  60.  
  61.     // complex manipulations
  62.     friend double _RTLENTRY _EXPFUNC real(complex _FAR &);   // the real part
  63.     friend double _RTLENTRY _EXPFUNC imag(complex _FAR &);   // the imaginary part
  64.     friend complex _RTLENTRY _EXPFUNC conj(complex _FAR &);  // the complex conjugate
  65.     friend double _RTLENTRY _EXPFUNC norm(complex _FAR &);   // the square of the magnitude
  66.     friend double _RTLENTRY _EXPFUNC arg(complex _FAR &);    // the angle in the plane
  67.  
  68.     // Create a complex object given polar coordinates
  69.     friend complex _RTLENTRY _EXPFUNC polar(double __mag, double __angle=0);
  70.  
  71.     // Overloaded ANSI C math functions
  72.     friend double  _RTLENTRY _EXPFUNC abs(complex _FAR &);
  73.     friend complex _RTLENTRY _EXPFUNC acos(complex _FAR &);
  74.     friend complex _RTLENTRY _EXPFUNC asin(complex _FAR &);
  75.     friend complex _RTLENTRY _EXPFUNC atan(complex _FAR &);
  76.     friend complex _RTLENTRY _EXPFUNC cos(complex _FAR &);
  77.     friend complex _RTLENTRY _EXPFUNC cosh(complex _FAR &);
  78.     friend complex _RTLENTRY _EXPFUNC exp(complex _FAR &);
  79.     friend complex _RTLENTRY _EXPFUNC log(complex _FAR &);
  80.     friend complex _RTLENTRY _EXPFUNC log10(complex _FAR &);
  81.     friend complex _RTLENTRY _EXPFUNC pow(complex _FAR & __base, double __expon);
  82.     friend complex _RTLENTRY _EXPFUNC pow(double __base, complex _FAR & __expon);
  83.     friend complex _RTLENTRY _EXPFUNC pow(complex _FAR & __base, complex _FAR & __expon);
  84.     friend complex _RTLENTRY _EXPFUNC sin(complex _FAR &);
  85.     friend complex _RTLENTRY _EXPFUNC sinh(complex _FAR &);
  86.     friend complex _RTLENTRY _EXPFUNC sqrt(complex _FAR &);
  87.     friend complex _RTLENTRY _EXPFUNC tan(complex _FAR &);
  88.     friend complex _RTLENTRY _EXPFUNC tanh(complex _FAR &);
  89.  
  90.     // Binary Operator Functions
  91.     friend complex _RTLENTRY _EXPFUNC operator+(complex _FAR &, complex _FAR &);
  92.     friend complex _RTLENTRY _EXPFUNC operator+(double, complex _FAR &);
  93.     friend complex _RTLENTRY _EXPFUNC operator+(complex _FAR &, double);
  94.     friend complex _RTLENTRY _EXPFUNC operator-(complex _FAR &, complex _FAR &);
  95.     friend complex _RTLENTRY _EXPFUNC operator-(double, complex _FAR &);
  96.     friend complex _RTLENTRY _EXPFUNC operator-(complex _FAR &, double);
  97.     friend complex _RTLENTRY _EXPFUNC operator*(complex _FAR &, complex _FAR &);
  98.     friend complex _RTLENTRY _EXPFUNC operator*(complex _FAR &, double);
  99.     friend complex _RTLENTRY _EXPFUNC operator*(double, complex _FAR &);
  100.     friend complex _RTLENTRY _EXPFUNC operator/(complex _FAR &, complex _FAR &);
  101.     friend complex _RTLENTRY _EXPFUNC operator/(complex _FAR &, double);
  102.     friend complex _RTLENTRY _EXPFUNC operator/(double, complex _FAR &);
  103.     friend int _RTLENTRY _EXPFUNC operator==(complex _FAR &, complex _FAR &);
  104.     friend int _RTLENTRY _EXPFUNC operator!=(complex _FAR &, complex _FAR &);
  105.     complex _FAR & _RTLENTRY operator+=(complex _FAR &);
  106.     complex _FAR & _RTLENTRY operator+=(double);
  107.     complex _FAR & _RTLENTRY operator-=(complex _FAR &);
  108.     complex _FAR & _RTLENTRY operator-=(double);
  109.     complex _FAR & _RTLENTRY operator*=(complex _FAR &);
  110.     complex _FAR & _RTLENTRY operator*=(double);
  111.     complex _FAR & _RTLENTRY operator/=(complex _FAR &);
  112.     complex _FAR & _RTLENTRY operator/=(double);
  113.     complex _RTLENTRY operator+();
  114.     complex _RTLENTRY operator-();
  115.  
  116. // Implementation
  117. private:
  118.         double re, im;
  119. };
  120.  
  121.  
  122. // Inline complex functions
  123.  
  124. inline _RTLENTRY complex::complex(double __re_val, double __im_val)
  125. {
  126.     re = __re_val;
  127.     im = __im_val;
  128. }
  129.  
  130. inline _RTLENTRY complex::complex()
  131. {
  132. /* if you want your complex numbers initialized ...
  133.     re = im = 0;
  134. */
  135. }
  136.  
  137. inline complex _RTLENTRY complex::operator+()
  138. {
  139.     return *this;
  140. }
  141.  
  142. inline complex _RTLENTRY complex::operator-()
  143. {
  144.     return complex(-re, -im);
  145. }
  146.  
  147.  
  148. // Definitions of compound-assignment operator member functions
  149.  
  150. inline complex _FAR & _RTLENTRY complex::operator+=(complex _FAR & __z2)
  151. {
  152.     re += __z2.re;
  153.     im += __z2.im;
  154.     return *this;
  155. }
  156.  
  157. inline complex _FAR & _RTLENTRY complex::operator+=(double __re_val2)
  158. {
  159.     re += __re_val2;
  160.     return *this;
  161. }
  162.  
  163. inline complex _FAR & _RTLENTRY complex::operator-=(complex _FAR & __z2)
  164. {
  165.     re -= __z2.re;
  166.     im -= __z2.im;
  167.     return *this;
  168. }
  169.  
  170. inline complex _FAR & _RTLENTRY complex::operator-=(double __re_val2)
  171. {
  172.     re -= __re_val2;
  173.     return *this;
  174. }
  175.  
  176. inline complex _FAR & _RTLENTRY complex::operator*=(double __re_val2)
  177. {
  178.     re *= __re_val2;
  179.     im *= __re_val2;
  180.     return *this;
  181. }
  182.  
  183. inline complex _FAR & _RTLENTRY complex::operator/=(double __re_val2)
  184. {
  185.     re /= __re_val2;
  186.     im /= __re_val2;
  187.     return *this;
  188. }
  189.  
  190.  
  191. // Definitions of non-member complex functions
  192.  
  193. inline double _RTLENTRY real(complex _FAR & __z)
  194. {
  195.     return __z.re;
  196. }
  197.  
  198. inline double _RTLENTRY imag(complex _FAR & __z)
  199. {
  200.     return __z.im;
  201. }
  202.  
  203. inline complex _RTLENTRY conj(complex _FAR & __z)
  204. {
  205.     return complex(__z.re, -__z.im);
  206. }
  207.  
  208. inline complex _RTLENTRY polar(double __mag, double __angle)
  209. {
  210.     return complex(__mag*cos(__angle), __mag*sin(__angle));
  211. }
  212.  
  213.  
  214. // Definitions of non-member binary operator functions
  215.  
  216. inline complex _RTLENTRY operator+(complex _FAR & __z1, complex _FAR & __z2)
  217. {
  218.     return complex(__z1.re + __z2.re, __z1.im + __z2.im);
  219. }
  220.  
  221. inline complex _RTLENTRY operator+(double __re_val1, complex _FAR & __z2)
  222. {
  223.     return complex(__re_val1 + __z2.re, __z2.im);
  224. }
  225.  
  226. inline complex _RTLENTRY operator+(complex _FAR & __z1, double __re_val2)
  227. {
  228.     return complex(__z1.re + __re_val2, __z1.im);
  229. }
  230.  
  231. inline complex _RTLENTRY operator-(complex _FAR & __z1, complex _FAR & __z2)
  232. {
  233.     return complex(__z1.re - __z2.re, __z1.im - __z2.im);
  234. }
  235.  
  236. inline complex _RTLENTRY operator-(double __re_val1, complex _FAR & __z2)
  237. {
  238.     return complex(__re_val1 - __z2.re, -__z2.im);
  239. }
  240.  
  241. inline complex _RTLENTRY operator-(complex _FAR & __z1, double __re_val2)
  242. {
  243.     return complex(__z1.re - __re_val2, __z1.im);
  244. }
  245.  
  246. inline complex _RTLENTRY operator*(complex _FAR & __z1, double __re_val2)
  247. {
  248.     return complex(__z1.re*__re_val2, __z1.im*__re_val2);
  249. }
  250.  
  251. inline complex _RTLENTRY operator*(double __re_val1, complex _FAR & __z2)
  252. {
  253.     return complex(__z2.re*__re_val1, __z2.im*__re_val1);
  254. }
  255.  
  256. inline complex _RTLENTRY operator/(complex _FAR & __z1, double __re_val2)
  257. {
  258.     return complex(__z1.re/__re_val2, __z1.im/__re_val2);
  259. }
  260.  
  261. inline int _RTLENTRY operator==(complex _FAR & __z1, complex _FAR & __z2)
  262. {
  263.     return __z1.re == __z2.re && __z1.im == __z2.im;
  264. }
  265.  
  266. inline int _RTLENTRY operator!=(complex _FAR & __z1, complex _FAR & __z2)
  267. {
  268.     return __z1.re != __z2.re || __z1.im != __z2.im;
  269. }
  270.  
  271.  
  272. // Complex stream I/O
  273.  
  274. ostream _FAR & _RTLENTRY _EXPFUNC operator<<(ostream _FAR &, complex _FAR &);
  275. istream _FAR & _RTLENTRY _EXPFUNC operator>>(istream _FAR &, complex _FAR &);
  276.  
  277.  
  278. #pragma option -Vo.
  279. #if defined(__BCOPT__) && !defined(_RTL_ALLOW_po) && !defined(__FLAT__) 
  280. #pragma option -po.   
  281. #endif
  282.  
  283. #pragma warn .nak   /* Ignore non-ansi keywords */
  284.  
  285. #endif  // __COMPLEX_H
  286.  
  287.