summaryrefslogtreecommitdiff
path: root/lib/libm/cpowf.c
blob: b63c6969048adf274160c6f1c52d29060f52b481 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <complex.h> // for complex, I, cabsf, cargf, cimagf, cpowf, crealf
#include <math.h>    // for cosf, expf, logf, powf, sinf

float complex cpowf(float complex a, float complex z)
{
	float x, y, r, theta, absa, arga;
	x = crealf(z);
	y = cimagf(z);
	absa = cabsf(a);
	if (absa == 0.0f) {
		return (0.0f + 0.0f * I);
	}
	arga = cargf(a);
	r = powf(absa, x);
	theta = x * arga;
	if (y != 0.0f) {
		r = r * expf(-y * arga);
		theta = theta + y * logf(absa);
	}
	return r * cosf(theta) + (r * sinf(theta)) * I;
}