|
const std = @import("../../std.zig"); const testing = std.testing; const math = std.math; const cmath = math.complex; const Complex = cmath.Complex; |
abs()Returns the absolute value (modulus) of z. |
pub fn abs(z: anytype) @TypeOf(z.re) { const T = @TypeOf(z.re); return math.hypot(T, z.re, z.im); } const epsilon = 0.0001; |
Test:complex.cabs |
test "complex.cabs" { const a = Complex(f32).init(5, 3); const c = abs(a); try testing.expect(math.approxEqAbs(f32, c, 5.83095, epsilon)); } |
Generated by zstd-browse2 on 2023-11-04 14:12:21 -0400. |