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 absolute value (modulus) of z.
8pub fn abs(z: anytype) @TypeOf(z.re, z.im) {
9 return math.hypot(z.re, z.im);
10}
11
12test abs {
13 const epsilon = math.floatEps(f32);
14 const a = Complex(f32).init(5, 3);
15 const c = abs(a);
16 try testing.expectApproxEqAbs(5.8309517, c, epsilon);
17}