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