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

  1. //  Module:     Cp_Pow
  2. //  Version:    2.20
  3. //
  4. //  Language:   C++ 2.0
  5. //  Environ:    Any
  6. //
  7. //  Purpose:    Power function 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. // "power" methods
  20. Complex pow(const Complex & c, const Complex & power)
  21.     {
  22.     Complex result;
  23.  
  24.     if (power.Real == 0.0 && power.Imag == 0.0)
  25.         {
  26.         result.Real = 1.0;
  27.         result.Imag = 0.0;
  28.         }
  29.     else
  30.         {
  31.         if (c.Real != 0.0 || c.Imag != 0.0)
  32.             result = exp(log(c) * power);
  33.         else
  34.             Complex::ErrorHandler();
  35.         }
  36.  
  37.     return result;
  38.     }
  39.  
  40. Complex sqrt(const Complex & c)
  41.     {
  42.     return pow(c,Complex(0.5,0.0));
  43.     }
  44.