| 1 | const std = @import("../../std.zig"); |
| 2 | const testing = std.testing; |
| 3 | const math = std.math; |
| 4 | const cmath = math.complex; |
| 5 | const Complex = cmath.Complex; |
| 6 | |
| 7 | /// Returns the complex conjugate of z. |
| 8 | pub fn conj(z: anytype) Complex(@TypeOf(z.re, z.im)) { |
| 9 | const T = @TypeOf(z.re, z.im); |
| 10 | return Complex(T).init(z.re, -z.im); |
| 11 | } |
| 12 | |
| 13 | test conj { |
| 14 | const a = Complex(f32).init(5, 3); |
| 15 | const c = a.conjugate(); |
| 16 | |
| 17 | try testing.expectEqual(5, c.re); |
| 18 | try testing.expectEqual(-3, c.im); |
| 19 | } |