-
Notifications
You must be signed in to change notification settings - Fork 7
/
cvc_complex.h
92 lines (71 loc) · 2.2 KB
/
cvc_complex.h
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
85
86
87
88
89
90
91
/* cvc_complex.h */
#ifndef _CVC_COMPLEX_H
#define _CVC_COMPLEX_H
#include <math.h>
/* A complex number. */
/* if complex is define as a macro in complex.h */
#ifdef complex
#undef complex
#endif
namespace cvc {
typedef struct {
double re, im;
} complex;
/* c1 = c2 * c3 */
#define _co_eq_co_ti_co(c1,c2,c3) {\
(c1)->re = (c2)->re * (c3)->re - (c2)->im * (c3)->im; \
(c1)->im = (c2)->re * (c3)->im + (c2)->im * (c3)->re;}
/* c1 = c2 / c3 */
#define _co_eq_co_ti_co_inv(c1,c2,c3) {\
(c1)->re = ( (c2)->re * (c3)->re + (c2)->im * (c3)->im ) / ( (c3)->re*(c3)->re + (c3)->im*(c3)->im); \
(c1)->im = ( (c2)->im * (c3)->re - (c2)->re * (c3)->im ) / ( (c3)->re*(c3)->re + (c3)->im*(c3)->im);}
/* c1 = c2 * c3^* */
#define _co_eq_co_ti_co_conj(c1,c2,c3) {\
(c1)->re = (c2)->re * (c3)->re + (c2)->im * (c3)->im; \
(c1)->im = -(c2)->re * (c3)->im + (c2)->im * (c3)->re;}
/* c1 = c2 + c3 */
#define _co_eq_co_pl_co(c1,c2,c3) {\
(c1)->re = (c2)->re + (c3)->re; \
(c1)->im = (c2)->im + (c3)->im;}
/* c1 = c2 - c3 */
#define _co_eq_co_mi_co(c1,c2,c3) {\
(c1)->re = (c2)->re - (c3)->re; \
(c1)->im = (c2)->im - (c3)->im;}
/* c1 += c2 */
#define _co_pl_eq_co(c1,c2) {\
(c1)->re += (c2)->re; \
(c1)->im += (c2)->im;}
/* c1 -= c2 */
#define _co_mi_eq_co(c1,c2) {\
(c1)->re -= (c2)->re; \
(c1)->im -= (c2)->im;}
/* c1 += c2 * c3 */
#define _co_pl_eq_co_ti_co(c1,c2,c3) {\
(c1)->re += (c2)->re * (c3)->re - (c2)->im * (c3)->im; \
(c1)->im += (c2)->re * (c3)->im + (c2)->im * (c3)->re;}
/* c1 += c2 * Conj(c3) */
#define _co_pl_eq_co_ti_co_conj(c1,c2,c3) {\
(c1)->re += (c2)->re * (c3)->re + (c2)->im * (c3)->im; \
(c1)->im += -(c2)->re * (c3)->im + (c2)->im * (c3)->re;}
/* c1 -= c2 * c3 */
#define _co_mi_eq_co_ti_co(c1,c2,c3) {\
(c1)->re -= (c2)->re * (c3)->re - (c2)->im * (c3)->im; \
(c1)->im -= (c2)->re * (c3)->im + (c2)->im * (c3)->re;}
/* c1 = c2 */
#define _co_eq_co(c1,c2) {\
(c1)->re = (c2)->re; \
(c1)->im = (c2)->im;}
/* c = r+0i */
#define _co_eq_re(c,r) {\
(c)->re = r; \
(c)->im = 0.;}
/* c1 *= r */
#define _co_ti_eq_re(c1,r) {\
(c1)->re *= r; \
(c1)->im *= r;}
/* c1 = c2*r */
#define _co_eq_co_ti_re(c1,c2,r) {\
(c1)->re = (c2)->re*r; \
(c1)->im = (c2)->im*r;}
}
#endif