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

  1. //  Module:     Cp_log
  2. //  Version:    2.20
  3. //
  4. //  Language:   C++ 2.0
  5. //  Environ:    Any
  6. //
  7. //  Purpose:    Logarithmic functions 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 "stdlib.h"
  17.     }
  18.  
  19. // logarithmic methods
  20. Complex exp(const Complex & c)
  21.     {
  22.     double X = exp(c.Real);
  23.  
  24.     Complex result;
  25.  
  26.     result.Real = X * cos(c.Imag);
  27.     result.Imag = X * sin(c.Imag);
  28.  
  29.     return result;
  30.     }
  31.  
  32. Complex log(const Complex & c)
  33.     {
  34.     double hypot = abs(c);
  35.  
  36.     Complex result;
  37.  
  38.     if (hypot > 0.0)
  39.         {
  40.         result.Real = log(hypot);
  41.         result.Imag = atan2(c.Imag, c.Real);
  42.         }
  43.     else
  44.         Complex::ErrorHandler();
  45.  
  46.     return result;
  47.     }
  48.