/*
cuda_complex.h
*/

#include <math.h>
#include <cuComplex.h>

// double

__host__ __device__ __inline__
static cuDoubleComplex cuCrmul(double r, cuDoubleComplex z)
{
	cuDoubleComplex ret;
	ret.x = r * z.x;
	ret.y = r * z.y;
	return ret;
}

__host__ __device__ __inline__
static cuDoubleComplex cuCexp(double x)
{
	cuDoubleComplex ret;
	ret.x = cos(x);
	ret.y = sin(x);
	return ret;
}

__host__ __device__ __inline__
static cuDoubleComplex cuCinv(cuDoubleComplex z)
{
	cuDoubleComplex ret;
	double denom = (z.x * z.x) + (z.y * z.y);
	if (denom <= 0) {
		ret.x = ret.y = 0;
	}
	else {
		ret.x = +z.x / denom;
		ret.y = -z.y / denom;
	}
	return ret;
}

__host__ __device__ __inline__
static cuDoubleComplex cuCadd4(cuDoubleComplex a, cuDoubleComplex b, cuDoubleComplex c, cuDoubleComplex d)
{
	cuDoubleComplex ret;
	ret.x = a.x + b.x + c.x + d.x;
	ret.y = a.y + b.y + c.y + d.y;
	return ret;
}

__host__ __device__ __inline__
static cuDoubleComplex cuCneg(cuDoubleComplex z)
{
	cuDoubleComplex ret;
	ret.x = -z.x;
	ret.y = -z.y;
	return ret;
}

__host__ __device__ __inline__
static cuDoubleComplex cuCcast(d_complex_t z)
{
	cuDoubleComplex ret;
	ret.x = z.r;
	ret.y = z.i;
	return ret;
}
