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