23 #ifndef HIP_INCLUDE_HIP_AMD_DETAIL_HIP_COMPLEX_H
24 #define HIP_INCLUDE_HIP_AMD_DETAIL_HIP_COMPLEX_H
38 #define COMPLEX_NEG_OP_OVERLOAD(type) \
39 __device__ __host__ static inline type operator-(const type& op) { \
46 #define COMPLEX_EQ_OP_OVERLOAD(type) \
47 __device__ __host__ static inline bool operator==(const type& lhs, const type& rhs) { \
48 return lhs.x == rhs.x && lhs.y == rhs.y; \
51 #define COMPLEX_NE_OP_OVERLOAD(type) \
52 __device__ __host__ static inline bool operator!=(const type& lhs, const type& rhs) { \
53 return !(lhs == rhs); \
56 #define COMPLEX_ADD_OP_OVERLOAD(type) \
57 __device__ __host__ static inline type operator+(const type& lhs, const type& rhs) { \
59 ret.x = lhs.x + rhs.x; \
60 ret.y = lhs.y + rhs.y; \
64 #define COMPLEX_SUB_OP_OVERLOAD(type) \
65 __device__ __host__ static inline type operator-(const type& lhs, const type& rhs) { \
67 ret.x = lhs.x - rhs.x; \
68 ret.y = lhs.y - rhs.y; \
72 #define COMPLEX_MUL_OP_OVERLOAD(type) \
73 __device__ __host__ static inline type operator*(const type& lhs, const type& rhs) { \
75 ret.x = lhs.x * rhs.x - lhs.y * rhs.y; \
76 ret.y = lhs.x * rhs.y + lhs.y * rhs.x; \
80 #define COMPLEX_DIV_OP_OVERLOAD(type) \
81 __device__ __host__ static inline type operator/(const type& lhs, const type& rhs) { \
83 ret.x = (lhs.x * rhs.x + lhs.y * rhs.y); \
84 ret.y = (rhs.x * lhs.y - lhs.x * rhs.y); \
85 ret.x = ret.x / (rhs.x * rhs.x + rhs.y * rhs.y); \
86 ret.y = ret.y / (rhs.x * rhs.x + rhs.y * rhs.y); \
90 #define COMPLEX_ADD_PREOP_OVERLOAD(type) \
91 __device__ __host__ static inline type& operator+=(type& lhs, const type& rhs) { \
97 #define COMPLEX_SUB_PREOP_OVERLOAD(type) \
98 __device__ __host__ static inline type& operator-=(type& lhs, const type& rhs) { \
104 #define COMPLEX_MUL_PREOP_OVERLOAD(type) \
105 __device__ __host__ static inline type& operator*=(type& lhs, const type& rhs) { \
110 #define COMPLEX_DIV_PREOP_OVERLOAD(type) \
111 __device__ __host__ static inline type& operator/=(type& lhs, const type& rhs) { \
116 #define COMPLEX_SCALAR_PRODUCT(type, type1) \
117 __device__ __host__ static inline type operator*(const type& lhs, type1 rhs) { \
119 ret.x = lhs.x * rhs; \
120 ret.y = lhs.y * rhs; \
147 return z.x * z.x + z.y * z.y;
151 return make_hipFloatComplex(p.x + q.x, p.y + q.y);
155 return make_hipFloatComplex(p.x - q.x, p.y - q.y);
159 return make_hipFloatComplex(p.x * q.x - p.y * q.y, p.y * q.x + p.x * q.y);
163 float sqabs = hipCsqabsf(q);
165 ret.x = (p.x * q.x + p.y * q.y) / sqabs;
166 ret.y = (p.y * q.x - p.x * q.y) / sqabs;
194 return z.x * z.x + z.y * z.y;
198 return make_hipDoubleComplex(p.x + q.x, p.y + q.y);
202 return make_hipDoubleComplex(p.x - q.x, p.y - q.y);
206 return make_hipDoubleComplex(p.x * q.x - p.y * q.y, p.y * q.x + p.x * q.y);
210 double sqabs = hipCsqabs(q);
212 ret.x = (p.x * q.x + p.y * q.y) / sqabs;
213 ret.y = (p.y * q.x - p.x * q.y) / sqabs;
272 return make_hipFloatComplex(x, y);
276 return make_hipFloatComplex((
float)z.x, (
float)z.y);
280 return make_hipDoubleComplex((
double)z.x, (
double)z.y);
284 float real = (p.x * q.x) + r.x;
285 float imag = (q.x * p.y) + r.y;
287 real = -(p.y * q.y) + real;
288 imag = (p.x * q.y) + imag;
290 return make_hipComplex(real, imag);
295 double real = (p.x * q.x) + r.x;
296 double imag = (q.x * p.y) + r.y;
298 real = -(p.y * q.y) + real;
299 imag = (p.x * q.y) + imag;
301 return make_hipDoubleComplex(real, imag);
304 #endif //HIP_INCLUDE_HIP_AMD_DETAIL_HIP_COMPLEX_H