mirror of
https://codeberg.org/ziglang/zig.git
synced 2025-12-07 22:34:28 +00:00
21 lines
545 B
Zig
21 lines
545 B
Zig
const std = @import("../../std.zig");
|
|
const testing = std.testing;
|
|
const math = std.math;
|
|
const Complex = math.Complex;
|
|
|
|
const cosh = @import("cosh.zig").cosh;
|
|
|
|
/// Calculates the cosine of a complex number.
|
|
pub fn cos(z: anytype) Complex(@TypeOf(z.re, z.im)) {
|
|
return cosh(z.mulByI());
|
|
}
|
|
|
|
test cos {
|
|
const epsilon = math.floatEps(f32);
|
|
|
|
const a: Complex(f32) = .init(5, 3);
|
|
const cos_a = cos(a);
|
|
|
|
try testing.expectApproxEqAbs(2.8558152, cos_a.re, epsilon);
|
|
try testing.expectApproxEqAbs(9.606383, cos_a.im, epsilon);
|
|
}
|