isce3 0.25.0
Loading...
Searching...
No Matches
float2.h
1/*
2 * @file float2.h
3 * @brief Define operators and functions on float2 (cuComplex) datatype
4 *
5 */
6
7#ifndef __FLOAT2_H
8#define __FLOAT2_H
9
10#include <vector_types.h>
11
12inline __host__ __device__ void zero(float2 &a) { a.x = 0.0f; a.y = 0.0f; }
13
14// negative
15inline __host__ __device__ float2 operator-(float2 &a)
16{
17 return make_float2(-a.x, -a.y);
18}
19
20// complex conjugate
21inline __host__ __device__ float2 conjugate(float2 a)
22{
23 return make_float2(a.x, -a.y);
24}
25
26// addition
27inline __host__ __device__ float2 operator+(float2 a, float2 b)
28{
29 return make_float2(a.x + b.x, a.y + b.y);
30}
31inline __host__ __device__ void operator+=(float2 &a, float2 b)
32{
33 a.x += b.x;
34 a.y += b.y;
35}
36
37inline __host__ __device__ float2 operator+(float2 a, float b)
38{
39 return make_float2(a.x + b, a.y);
40}
41inline __host__ __device__ void operator+=(float2 &a, float b)
42{
43 a.x += b;
44}
45
46// subtraction
47inline __host__ __device__ float2 operator-(float2 a, float2 b)
48{
49 return make_float2(a.x - b.x, a.y - b.y);
50}
51inline __host__ __device__ void operator-=(float2 &a, float2 b)
52{
53 a.x -= b.x;
54 a.y -= b.y;
55}
56inline __host__ __device__ float2 operator-(float2 a, float b)
57{
58 return make_float2(a.x - b, a.y);
59}
60inline __host__ __device__ void operator-=(float2 &a, float b)
61{
62 a.x -= b;
63}
64
65// multiplication
66inline __host__ __device__ float2 operator*(float2 a, float2 b)
67{
68 return make_float2(a.x*b.x - a.y*b.y, a.y*b.x + a.x*b.y);
69}
70inline __host__ __device__ void operator*=(float2 &a, float2 b)
71{
72 a.x = a.x*b.x - a.y*b.y;
73 a.y = a.y*b.x + a.x*b.y;
74}
75inline __host__ __device__ float2 operator*(float2 a, float b)
76{
77 return make_float2(a.x * b, a.y * b);
78}
79inline __host__ __device__ void operator*=(float2 &a, float b)
80{
81 a.x *= b;
82 a.y *= b;
83}
84inline __host__ __device__ float2 operator*(float2 a, int b)
85{
86 return make_float2(a.x * b, a.y * b);
87}
88inline __host__ __device__ void operator*=(float2 &a, int b)
89{
90 a.x *= b;
91 a.y *= b;
92}
93inline __host__ __device__ float2 complexMul(float2 a, float2 b)
94{
95 return a*b;
96}
97inline __host__ __device__ float2 complexMulConj(float2 a, float2 b)
98{
99 return make_float2(a.x*b.x + a.y*b.y, a.y*b.x - a.x*b.y);
100}
101
102inline __host__ __device__ float2 operator/(float2 a, float b)
103{
104 return make_float2(a.x / b, a.y / b);
105}
106inline __host__ __device__ void operator/=(float2 &a, float b)
107{
108 a.x /= b;
109 a.y /= b;
110}
111
112// abs, arg
113inline __host__ __device__ float complexAbs(float2 a)
114{
115 return sqrtf(a.x*a.x+a.y*a.y);
116}
117inline __host__ __device__ float complexArg(float2 a)
118{
119 return atan2f(a.y, a.x);
120}
121
122// make a complex number from phase
123inline __host__ __device__ float2 complexExp(float arg)
124{
125 return make_float2(cosf(arg), sinf(arg));
126}
127
128#endif //__FLOAT2_H
129// end of file

Generated for ISCE3.0 by doxygen 1.13.2.