summaryrefslogtreecommitdiff
path: root/lib/libm/cpowl.c
blob: aa6141f878b182851efe6dce800c1bc36544620a (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, cabsl, cargl, cimagl, cpowl, creall
#include <math.h>    // for cosl, expl, logl, powl, sinl

long double complex cpowl(long double complex a, long double complex z)
{
	long double x, y, r, theta, absa, arga;
	x = creall(z);
	y = cimagl(z);
	absa = cabsl(a);
	if (absa == 0.0L) {
		return (0.0L + 0.0L * (long double complex)I);
	}
	arga = cargl(a);
	r = powl(absa, x);
	theta = x * arga;
	if (y != 0.0L) {
		r = r * expl(-y * arga);
		theta = theta + y * logl(absa);
	}
	return r * cosl(theta) + (r * sinl(theta)) * (long double complex)I;
}