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 cosine of z.
8pub fn cos(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 return cmath.cosh(p);
12}
13
14test cos {
15 const epsilon = math.floatEps(f32);
16 const a = Complex(f32).init(5, 3);
17 const c = cos(a);
18
19 try testing.expectApproxEqAbs(2.8558152, c.re, epsilon);
20 try testing.expectApproxEqAbs(9.606383, c.im, epsilon);
21}