| 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 sine of z. |
| 8 | pub fn sin(z: anytype) Complex(@TypeOf(z.re, z.im)) { |
| 9 | const T = @TypeOf(z.re, z.im); |
| 10 | const p = Complex(T).init(-z.im, z.re); |
| 11 | const q = cmath.sinh(p); |
| 12 | return Complex(T).init(q.im, -q.re); |
| 13 | } |
| 14 | |
| 15 | test sin { |
| 16 | const epsilon = math.floatEps(f32); |
| 17 | const a = Complex(f32).init(5, 3); |
| 18 | const c = sin(a); |
| 19 | |
| 20 | try testing.expectApproxEqAbs(-9.654126, c.re, epsilon); |
| 21 | try testing.expectApproxEqAbs(2.8416924, c.im, epsilon); |
| 22 | } |