master
 1const std = @import("../../std.zig");
 2const testing = std.testing;
 3const math = std.math;
 4const cmath = math.complex;
 5const Complex = cmath.Complex;
 6
 7// Returns the arc-sine of z.
 8pub fn asin(z: anytype) Complex(@TypeOf(z.re, z.im)) {
 9    const T = @TypeOf(z.re, z.im);
10    const x = z.re;
11    const y = z.im;
12
13    const p = Complex(T).init(1.0 - (x - y) * (x + y), -2.0 * x * y);
14    const q = Complex(T).init(-y, x);
15    const r = cmath.log(q.add(cmath.sqrt(p)));
16
17    return Complex(T).init(r.im, -r.re);
18}
19
20test asin {
21    const epsilon = math.floatEps(f32);
22    const a = Complex(f32).init(5, 3);
23    const c = asin(a);
24
25    try testing.expectApproxEqAbs(1.0238227, c.re, epsilon);
26    try testing.expectApproxEqAbs(2.4529128, c.im, epsilon);
27}