| ... | ... | @@ -37,28 +37,28 @@ pub fn Complex(comptime T: type) type { |
| 37 | 37 | }; |
| 38 | 38 | } |
| 39 | 39 | |
| 40 | | pub fn add(self: *const Self, other: *const Self) Self { |
| 40 | pub fn add(self: Self, other: Self) Self { |
| 41 | 41 | return Self{ |
| 42 | 42 | .re = self.re + other.re, |
| 43 | 43 | .im = self.im + other.im, |
| 44 | 44 | }; |
| 45 | 45 | } |
| 46 | 46 | |
| 47 | | pub fn sub(self: *const Self, other: *const Self) Self { |
| 47 | pub fn sub(self: Self, other: Self) Self { |
| 48 | 48 | return Self{ |
| 49 | 49 | .re = self.re - other.re, |
| 50 | 50 | .im = self.im - other.im, |
| 51 | 51 | }; |
| 52 | 52 | } |
| 53 | 53 | |
| 54 | | pub fn mul(self: *const Self, other: *const Self) Self { |
| 54 | pub fn mul(self: Self, other: Self) Self { |
| 55 | 55 | return Self{ |
| 56 | 56 | .re = self.re * other.re - self.im * other.im, |
| 57 | 57 | .im = self.im * other.re + self.re * other.im, |
| 58 | 58 | }; |
| 59 | 59 | } |
| 60 | 60 | |
| 61 | | pub fn div(self: *const Self, other: *const Self) Self { |
| 61 | pub fn div(self: Self, other: Self) Self { |
| 62 | 62 | const re_num = self.re * other.re + self.im * other.im; |
| 63 | 63 | const im_num = self.im * other.re - self.re * other.im; |
| 64 | 64 | const den = other.re * other.re + other.im * other.im; |
| ... | ... | @@ -69,14 +69,14 @@ pub fn Complex(comptime T: type) type { |
| 69 | 69 | }; |
| 70 | 70 | } |
| 71 | 71 | |
| 72 | | pub fn conjugate(self: *const Self) Self { |
| 72 | pub fn conjugate(self: Self) Self { |
| 73 | 73 | return Self{ |
| 74 | 74 | .re = self.re, |
| 75 | 75 | .im = -self.im, |
| 76 | 76 | }; |
| 77 | 77 | } |
| 78 | 78 | |
| 79 | | pub fn reciprocal(self: *const Self) Self { |
| 79 | pub fn reciprocal(self: Self) Self { |
| 80 | 80 | const m = self.re * self.re + self.im * self.im; |
| 81 | 81 | return Self{ |
| 82 | 82 | .re = self.re / m, |
| ... | ... | @@ -84,7 +84,7 @@ pub fn Complex(comptime T: type) type { |
| 84 | 84 | }; |
| 85 | 85 | } |
| 86 | 86 | |
| 87 | | pub fn magnitude(self: *const Self) T { |
| 87 | pub fn magnitude(self: Self) T { |
| 88 | 88 | return math.sqrt(self.re * self.re + self.im * self.im); |
| 89 | 89 | } |
| 90 | 90 | }; |