16template <
class T>
struct __align__(sizeof(T)) hr_complex_t {
20 constexpr visible hr_complex_t(
const T a = (T)0,
const T b = (T)0)
26 constexpr visible hr_complex_t(
const hr_complex_t<L> a)
32 template <
class L> hr_complex_t visible
inline __attribute__((always_inline)) &operator=(
const L x) {
38 template <
class L> hr_complex_t visible
inline __attribute__((always_inline)) &operator=(
const hr_complex_t<L> x) {
44 hr_complex_t visible
inline __attribute__((always_inline)) operator-(
void)
const {
45 return hr_complex_t(-re, -im);
49 template <
class L> hr_complex_t visible
inline __attribute__((always_inline)) &operator+=(
const L x) {
54 template <
class L> hr_complex_t visible
inline __attribute__((always_inline)) &operator+=(
const hr_complex_t<L> x) {
61 template <
class L> hr_complex_t visible
inline __attribute__((always_inline)) &operator-=(
const L x) {
66 template <
class L>
auto visible
inline __attribute__((always_inline)) &operator-=(
const hr_complex_t<L> x) {
73 template <
class L>
auto visible
inline __attribute__((always_inline)) &operator*=(
const L x) {
79 template <
class L>
auto visible
inline __attribute__((always_inline)) &operator*=(
const hr_complex_t<L> x) {
80 T re_new = re * x.re - im * x.im;
81 T im_new = re * x.im + im * x.re;
88 template <
class L>
auto visible
inline __attribute__((always_inline)) &operator/=(
const L x) {
94 template <
class L>
auto visible
inline __attribute__((always_inline)) &operator/=(
const hr_complex_t<L> x) {
95 T re_new = (re * x.re + im * x.im) / (x.re * x.re + x.im * x.im);
96 T im_new = (im * x.re - re * x.im) / (x.re * x.re + x.im * x.im);
103 hr_complex_t visible
inline __attribute__((always_inline)) conj() {
104 return hr_complex_t(re, -im);
109template <
class L,
class T>
auto visible
inline __attribute__((always_inline)) operator+(
const hr_complex_t<L> &c,
const T x) {
110 return hr_complex_t(c.re + x, c.im + (T)0);
113template <
class L,
class T>
auto visible
inline __attribute__((always_inline)) operator+(
const L x,
const hr_complex_t<T> &c) {
114 return hr_complex_t(c.re + x, c.im + (L)0);
117template <
class L,
class T>
118auto visible
inline __attribute__((always_inline)) operator+(
const hr_complex_t<L> &x,
const hr_complex_t<T> &c) {
119 return hr_complex_t(c.re + x.re, c.im + x.im);
123template <
class T,
class L>
auto visible
inline __attribute__((always_inline)) operator-(
const hr_complex_t<T> &c,
const L x) {
124 return hr_complex_t(c.re - x, c.im - (L)0);
127template <
class T,
class L>
auto visible
inline __attribute__((always_inline)) operator-(
const T x,
const hr_complex_t<L> &c) {
128 return hr_complex_t(x - c.re, (T)0 - c.im);
131template <
class T,
class L>
132auto visible
inline __attribute__((always_inline)) operator-(
const hr_complex_t<L> &x,
const hr_complex_t<T> &c) {
133 return hr_complex_t(x.re - c.re, x.im - c.im);
137template <
class T,
class L>
auto visible
inline __attribute__((always_inline)) operator*(
const hr_complex_t<T> &c,
const L x) {
138 return hr_complex_t(c.re * x, c.im * x);
141template <
class T,
class L>
auto visible
inline __attribute__((always_inline)) operator*(
const T x,
const hr_complex_t<L> &c) {
142 return hr_complex_t(c.re * x, c.im * x);
145template <
class T,
class L>
146auto visible
inline __attribute__((always_inline)) operator*(
const hr_complex_t<T> &a,
const hr_complex_t<L> &b) {
147 return hr_complex_t(a.re * b.re - b.im * a.im, a.im * b.re + b.im * a.re);
151template <
class T,
class L>
auto visible
inline __attribute__((always_inline)) operator/(
const hr_complex_t<T> &c,
const L x) {
152 return hr_complex_t(c.re / x, c.im / x);
155template <
class T,
class L>
auto visible
inline __attribute__((always_inline)) operator/(
const T x,
const hr_complex_t<L> &c) {
156 return hr_complex_t(x * c.re / (c.re * c.re + c.im * c.im), -x * c.im / (c.re * c.re + c.im * c.im));
159template <
class T,
class L>
160auto visible
inline __attribute__((always_inline)) operator/(
const hr_complex_t<T> x,
const hr_complex_t<L> c) {
161 return hr_complex_t((x.re * c.re + x.im * c.im) / (c.re * c.re + c.im * c.im),
162 (x.im * c.re - x.re * c.im) / (c.re * c.re + c.im * c.im));
165typedef struct hr_complex_t<double> hr_complex;
166typedef struct hr_complex_t<float> hr_complex_flt;
169#define I (hr_complex_flt(0.0f, 1.0f))
171constexpr hr_complex I = hr_complex_flt(0.0f, 1.0f);
173#define creal(a) ((a).re)
174#define cimag(a) ((a).im)
175#define conj(a) ((a).conj())
177visible
double carg(hr_complex c);
179visible hr_complex cpow(hr_complex c,
double pow);
Basic gpu imports and structs. Include this in files that define GPU logic.