amath  1.8.5
Simple command line calculator
cpow.c File Reference
#include "prim.h"
Include dependency graph for cpow.c:

Go to the source code of this file.

Functions

complex cpow (complex a, complex z)
 Complex number raised to a power. More...
 

Function Documentation

◆ cpow()

complex cpow ( complex  a,
complex  z 
)

Complex number raised to a power.

Definition at line 42 of file cpow.c.

References atan2(), cabs(), cimag(), cos(), cpack(), creal(), exp(), log(), pow(), and sin().

Referenced by ComplexNumber::Raise().

43 {
44  complex w;
45  double x, y, r, theta, absa, arga;
46 
47  x = creal(z);
48  y = cimag(z);
49  absa = cabs(a);
50  if (absa == 0.0)
51  {
52  return cpack(0.0, + 0.0);
53  }
54  arga = atan2(cimag(a), creal(a));
55 
56  r = pow(absa, x);
57  theta = x * arga;
58  if (y != 0.0)
59  {
60  r = r * exp(-y * arga);
61  theta = theta + y * log(absa);
62  }
63 
64  w = cpack(r * cos(theta), r * sin(theta));
65  return w;
66 }
double sin(double x)
Sine function.
Definition: sin.c:86
Definition: mathi.h:48
complex cpack(double x, double y)
Pack two real numbers into a complex number.
Definition: prim.c:68
double cimag(complex z)
Imaginary part of complex number.
Definition: prim.c:46
double cos(double x)
Cosine function.
Definition: cos.c:87
double atan2(double y, double x)
Inverse tangent function.
Definition: atan2.c:87
double creal(complex z)
Real part of complex number.
Definition: prim.c:38
double pow(double x, double y)
Expontation function.
Definition: pow.c:138
double exp(double x)
Returns the exponential of x.
Definition: exp.c:138
double log(double x)
Natural logarithm function (base e)
Definition: log.c:109
double cabs(complex z)
Absolute value of complex number.
Definition: prim.c:54
Here is the call graph for this function:
Here is the caller graph for this function: