Main Page
Classes
Files
File List
File Members
include
include/complex.h
Go to the documentation of this file.
1
18
#ifndef __COMPLEX_H
19
#define __COMPLEX_H
20
21
#include <cmath>
22
#include <cstdio>
23
24
double
epsilon
= 0.0000001;
25
26
struct
complex
{
double
r
;
double
i
;};
27
28
complex
czero
= {0,0};
29
30
complex
cmul
(
complex
a,
complex
b)
31
{
32
complex
r
;
33
r.
r
=a.
r
*b.
r
-a.
i
*b.
i
;
34
r.
i
=a.
i
*b.
r
+a.
r
*b.
i
;
35
return
r
;
36
}
37
38
complex
cadd
(
complex
a,
complex
b)
39
{
40
complex
r
;
41
r.
r
=a.
r
+b.
r
;
42
r.
i
=a.
i
+b.
i
;
43
return
r
;
44
}
45
46
complex
csub
(
complex
a,
complex
b)
47
{
48
complex
r
;
49
r.
r
=a.
r
-b.
r
;
50
r.
i
=a.
i
-b.
i
;
51
return
r
;
52
}
53
54
complex
r2c
(
double
x)
55
{
56
complex
r
;
57
r.
r
=x;
58
r.
i
=0;
59
return
r
;
60
}
61
62
bool
isEqual
(
complex
a,
complex
b)
63
{
64
return
((a.
r
==b.
r
)&&(a.
i
==b.
i
));
65
}
66
67
bool
isEqualE
(
complex
a,
complex
b)
68
{
69
return
((
abs
(a.
r
-b.
r
)<
epsilon
)&&(
abs
(a.
i
-b.
i
)<
epsilon
));
70
}
71
72
complex
cpow
(
complex
a,
int
b)
73
{
74
complex
r
;
75
r=a;
76
for
(
int
i
=1;
i
<b;
i
++) r=
cmul
(r,a);
77
return
r
;
78
}
79
80
complex
cdiv
(
complex
a,
complex
b)
81
{
82
complex
r
;
83
double
B=b.
r
*b.
r
+b.
i
*b.
i
;
84
r.
r
=(a.
r
*b.
r
+a.
i
*b.
i
)/B;
85
r.
i
=(a.
i
*b.
r
-a.
r
*b.
i
)/B;
86
return
r
;
87
}
88
89
complex
cexp
(
complex
a){
90
complex
r
;
91
double
length
,
angle
;
92
length=exp(a.
r
);
93
angle=a.
i
;
94
r.
r
=cos(angle)*length;
95
r.
i
=sin(angle)*length;
96
return
r
;
97
}
98
99
complex
cln
(
complex
a){
100
complex
r
;
101
double
length
,
angle
;
102
length=sqrt(a.
r
*a.
r
+a.
i
*a.
i
);
103
angle=atan2(a.
i
,a.
r
);
104
r.
r
=log(length);
105
r.
i
=angle;
106
return
r
;
107
}
108
109
complex
cneg
(
complex
a){
110
complex
r
;
111
r.
r
=-a.
r
;
112
r.
i
=-a.
i
;
113
return
r
;
114
}
115
116
complex
cpos
(
complex
a){
117
return
a;
118
}
119
120
complex
csqrt
(
complex
a)
121
{
122
complex
r
;
123
double
length
,
angle
;
124
length=sqrt(sqrt(a.
r
*a.
r
+a.
i
*a.
i
));
125
angle=atan2(a.
i
,a.
r
)/2;
126
r.
r
=cos(angle)*length;
127
r.
i
=sin(angle)*length;
128
return
r
;
129
}
130
131
void
cprint
(
complex
c)
132
{
133
printf(
"%f"
,c.
r
);
134
if
(c.
i
>0) printf(
"+%fi"
,c.
i
);
135
if
(c.
i
<0) printf(
"%fi"
,c.
i
);
136
printf(
"\n"
);
137
}
138
139
bool
isReal
(
complex
x)
140
{
141
return
(
abs
(x.
i
)<=
epsilon
);
142
}
143
#endif
csqrt
complex csqrt(complex a)
Definition:
include/complex.h:120
isEqual
bool isEqual(complex a, complex b)
Definition:
include/complex.h:62
complex::r
double r
Definition:
include/complex.h:26
cexp
complex cexp(complex a)
Definition:
include/complex.h:89
angle
TFSIMD_FORCE_INLINE tfScalar angle(const Quaternion &q1, const Quaternion &q2)
czero
complex czero
Definition:
include/complex.h:28
csub
complex csub(complex a, complex b)
Definition:
include/complex.h:46
cpos
complex cpos(complex a)
Definition:
include/complex.h:116
cneg
complex cneg(complex a)
Definition:
include/complex.h:109
cadd
complex cadd(complex a, complex b)
Definition:
include/complex.h:38
cprint
void cprint(complex c)
Definition:
include/complex.h:131
cpow
complex cpow(complex a, int b)
Definition:
include/complex.h:72
length
TFSIMD_FORCE_INLINE tfScalar length(const Quaternion &q)
complex
Definition:
include/complex.h:26
cmul
complex cmul(complex a, complex b)
Definition:
include/complex.h:30
isEqualE
bool isEqualE(complex a, complex b)
Definition:
include/complex.h:67
complex::i
double i
Definition:
include/complex.h:26
cdiv
complex cdiv(complex a, complex b)
Definition:
include/complex.h:80
isReal
bool isReal(complex x)
Definition:
include/complex.h:139
r2c
complex r2c(double x)
Definition:
include/complex.h:54
abs
double abs(quaternion a)
Definition:
include/quaternion.h:99
epsilon
double epsilon
Definition:
include/complex.h:24
cln
complex cln(complex a)
Definition:
include/complex.h:99
asr_flock_of_birds
Author(s): Bernhardt Andre, Engelmann Stephan, Giesler Björn, Heller Florian, Jäkel Rainer, Nguyen Trung, Pardowitz Michael, Weckesser Peter, Yi Xie, Zöllner Raoul
autogenerated on Mon Jun 10 2019 12:44:40