This repository has been archived by the owner on Oct 22, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
complex.h
76 lines (61 loc) · 1.87 KB
/
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
/*
* See http://www.asterisk.org for more information about
* the Asterisk project. Please do not directly contact
* any of the maintainers of this project for assistance;
* the project provides a web site, mailing lists and IRC
* channels for your use.
*
* This program is free software, distributed under the terms of
* the GNU General Public License Version 2 as published by the
* Free Software Foundation. See the LICENSE file included with
* this program for more details.
*/
struct c_complex
{ double re, im;
};
struct complex
{ double re, im;
complex(double r, double i = 0.0) { re = r; im = i; }
complex() { } /* uninitialized complex */
complex(c_complex z) { re = z.re; im = z.im; } /* init from denotation */
};
extern complex csqrt(complex), cexp(complex), expj(double); /* from complex.C */
extern complex evaluate(complex[], int, complex[], int, complex); /* from complex.C */
inline double hypot(complex z) { return ::hypot(z.im, z.re); }
inline double atan2(complex z) { return ::atan2(z.im, z.re); }
inline complex cconj(complex z)
{ z.im = -z.im;
return z;
}
inline complex operator * (double a, complex z)
{ z.re *= a; z.im *= a;
return z;
}
inline complex operator / (complex z, double a)
{ z.re /= a; z.im /= a;
return z;
}
inline void operator /= (complex &z, double a)
{ z = z / a;
}
extern complex operator * (complex, complex);
extern complex operator / (complex, complex);
inline complex operator + (complex z1, complex z2)
{ z1.re += z2.re;
z1.im += z2.im;
return z1;
}
inline complex operator - (complex z1, complex z2)
{ z1.re -= z2.re;
z1.im -= z2.im;
return z1;
}
inline complex operator - (complex z)
{ return 0.0 - z;
}
inline bool operator == (complex z1, complex z2)
{ return (z1.re == z2.re) && (z1.im == z2.im);
}
inline complex sqr(complex z)
{ return z*z;
}