| 1 | const std = @import("../../std.zig"); |
| 2 | const testing = std.testing; |
| 3 | const math = std.math; |
| 4 | const cmath = math.complex; |
| 5 | const Complex = cmath.Complex; |
| 6 | |
| 7 | /// Returns the angular component (in radians) of z. |
| 8 | pub fn arg(z: anytype) @TypeOf(z.re, z.im) { |
| 9 | return math.atan2(z.im, z.re); |
| 10 | } |
| 11 | |
| 12 | test arg { |
| 13 | const epsilon = math.floatEps(f32); |
| 14 | const a = Complex(f32).init(5, 3); |
| 15 | const c = arg(a); |
| 16 | try testing.expectApproxEqAbs(0.5404195, c, epsilon); |
| 17 | } |