| 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 arc-cosine of z. |
| 8 | pub fn acos(z: anytype) Complex(@TypeOf(z.re, z.im)) { |
| 9 | const T = @TypeOf(z.re, z.im); |
| 10 | const q = cmath.asin(z); |
| 11 | return Complex(T).init(@as(T, math.pi) / 2 - q.re, -q.im); |
| 12 | } |
| 13 | |
| 14 | test acos { |
| 15 | const epsilon = math.floatEps(f32); |
| 16 | const a = Complex(f32).init(5, 3); |
| 17 | const c = acos(a); |
| 18 | |
| 19 | try testing.expectApproxEqAbs(0.5469737, c.re, epsilon); |
| 20 | try testing.expectApproxEqAbs(-2.4529128, c.im, epsilon); |
| 21 | } |