summaryrefslogtreecommitdiff
path: root/cplx.h
blob: 5e1538d6fc0277e639d41dbdfabe9479f176b03c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#pragma once


struct device_complex {
	double x, y;
};

template <int N>
__host__ __device__ inline device_complex complex_power(double x, double y, double x2, double y2) {
	device_complex next = complex_power<N - 1>(x, y, x2, y2);
	return device_complex{
		x * next.x - y * next.y,
		x * next.y + y * next.x
	};
}

template <>
__host__ __device__ inline device_complex complex_power<2>(double x, double y, double x2, double y2) {
	return device_complex{x2 - y2, 2 * x * y};
}

template <>
__host__ __device__ inline device_complex complex_power<1>(double x, double y, double x2, double y2) {
	(void)x2; (void)y2;
	return device_complex{x, y};
}