| ... | @@ -37,28 +37,28 @@ pub fn Complex(comptime T: type) type { | ... | @@ -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 | return Self{ | 41 | return Self{ |
| 42 | .re = self.re + other.re, | 42 | .re = self.re + other.re, |
| 43 | .im = self.im + other.im, | 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 | return Self{ | 48 | return Self{ |
| 49 | .re = self.re - other.re, | 49 | .re = self.re - other.re, |
| 50 | .im = self.im - other.im, | 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 | return Self{ | 55 | return Self{ |
| 56 | .re = self.re * other.re - self.im * other.im, | 56 | .re = self.re * other.re - self.im * other.im, |
| 57 | .im = self.im * other.re + self.re * other.im, | 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 | const re_num = self.re * other.re + self.im * other.im; | 62 | const re_num = self.re * other.re + self.im * other.im; |
| 63 | const im_num = self.im * other.re - self.re * other.im; | 63 | const im_num = self.im * other.re - self.re * other.im; |
| 64 | const den = other.re * other.re + other.im * other.im; | 64 | const den = other.re * other.re + other.im * other.im; |
| ... | @@ -69,14 +69,14 @@ pub fn Complex(comptime T: type) type { | ... | @@ -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 | return Self{ | 73 | return Self{ |
| 74 | .re = self.re, | 74 | .re = self.re, |
| 75 | .im = -self.im, | 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 | const m = self.re * self.re + self.im * self.im; | 80 | const m = self.re * self.re + self.im * self.im; |
| 81 | return Self{ | 81 | return Self{ |
| 82 | .re = self.re / m, | 82 | .re = self.re / m, |
| ... | @@ -84,7 +84,7 @@ pub fn Complex(comptime T: type) type { | ... | @@ -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 | return math.sqrt(self.re * self.re + self.im * self.im); | 88 | return math.sqrt(self.re * self.re + self.im * self.im); |
| 89 | } | 89 | } |
| 90 | }; | 90 | }; |