forked from sestei/jscav
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcomplex.js
More file actions
39 lines (32 loc) · 869 Bytes
/
complex.js
File metadata and controls
39 lines (32 loc) · 869 Bytes
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
/***
jsCav - linear cavity calculator
2016, S. Steinlechner -- github.com/sestei/jscav
This work is licensed under the Creative Commons Attribution-NonCommercial-
ShareAlike 4.0 International License. To view a copy of this license, visit
http://creativecommons.org/licenses/by-nc-sa/4.0/ or send a letter to Creative
Commons, PO Box 1866, Mountain View, CA 94042, USA.
*/
class Complex {
constructor(re, im) {
this.re = re;
this.im = im;
}
add(other) {
this.re += other.re;
this.im += other.im;
}
sub(other) {
this.re -= other.re;
this.im -= other.im;
}
invert() {
var m = this.mag()
return new Complex(this.re/m, -this.im/m);
}
mag() {
return this.re*this.re + this.im*this.im;
}
clone() {
return new Complex(this.re, this.im);
}
}