home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / CTECHAPP.ZIP / CLASSES.ZIP / CP_MISC.CPP < prev    next >
C/C++ Source or Header  |  1990-01-28  |  968b  |  58 lines

  1. //  Module:     Cp_Misc
  2. //  Version:    2.20
  3. //
  4. //  Language:   C++ 2.0
  5. //  Environ:    Any
  6. //
  7. //  Purpose:    Miscellaneous methods for Complex class
  8. //
  9. //  Written by: Scott Robert Ladd
  10.  
  11. #include "Complex.hpp"
  12.  
  13. extern "C"
  14.     {
  15.     #include "math.h"
  16.     #include "stdio.h"
  17.     #include "stdlib.h"
  18.     }
  19.  
  20. // polar coordinate methods
  21. Complex polar(const double radius, const double theta)
  22.     {
  23.     Complex result;
  24.  
  25.     result.Real = radius * cos(theta);
  26.     result.Imag = radius * sin(theta);
  27.  
  28.     return result;
  29.     }
  30.  
  31. Complex conj(const Complex & c)
  32.     {
  33.     Complex result;
  34.  
  35.     result.Real =  c.Real;
  36.     result.Imag = -c.Imag;
  37.  
  38.     return result;
  39.     }
  40.  
  41. // output method
  42. int Complex::Print() const
  43.     {
  44.     int out_len;
  45.  
  46.     out_len = printf("(%g", Real);
  47.  
  48.     if (Imag >= 0.0)
  49.         {
  50.         ++out_len;
  51.         putchar('+');
  52.         }
  53.  
  54.     out_len += printf("%g)", Imag);
  55.  
  56.     return out_len;
  57.     }
  58.