-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCmpx.cu
84 lines (71 loc) · 1.41 KB
/
Cmpx.cu
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include <cmath>
#include <assert.h>
#include "Cmpx.hpp"
// constructor
HOSTDEVICE
Cmpx::Cmpx() {
re = 0;
im = 0;
}
HOSTDEVICE
Cmpx::Cmpx(const fptype x, const fptype y) {
re = x;
im = y;
}
// Cmpx& Cmpx::set_re(const fptype x) {
// re = x;
// return *this;
// }
// Cmpx& Cmpx::set_im(const fptype x) {
// im = x;
// return *this;
// }
// Cmpx Cmpx::conjugate() const {
// return Cmpx(re, -im);
// }
HOSTDEVICE
fptype Cmpx::get_mag() const {
return sqrtf(re*re + im*im);
}
HOSTDEVICE
fptype Cmpx::get_ang() const {
return atan2f(im, re);
}
// Cmpx& Cmpx::operator+=(const Cmpx &z) {
HOSTDEVICE
void Cmpx::operator+=(const Cmpx &z) {
re += z.re;
im += z.im;
// return *this;
}
// Cmpx& Cmpx::operator-=(const Cmpx &z) {
// re -= z.re;
// im -= z.im;
// return *this;
// }
// Cmpx& Cmpx::operator*=(const Cmpx &z) {
HOSTDEVICE
void Cmpx::operator*=(const Cmpx &z) {
fptype x = re*z.re - im*z.im;
fptype y = re*z.im + im*z.re;
re = x;
im = y;
// return *this;
}
// Cmpx& Cmpx::operator*=(const fptype k) {
HOSTDEVICE
void Cmpx::operator*=(const fptype k) {
re *= k;
im *= k;
// return *this;
}
HOST
char* Cmpx::polar() const {
char *ch = new char[100];
sprintf(ch, "%g<%gr", get_mag(), get_ang()); return ch;
}
HOST
char* Cmpx::cartesian() const {
char *ch = new char[100];
sprintf(ch, "%g+%gj", re, im); return ch;
}