2019-03-02 16:46:04 -05:00
|
|
|
const std = @import("../../std.zig");
|
2019-02-08 18:18:47 -05:00
|
|
|
const testing = std.testing;
|
2018-04-24 19:18:31 +12:00
|
|
|
const math = std.math;
|
|
|
|
|
const cmath = math.complex;
|
|
|
|
|
const Complex = cmath.Complex;
|
|
|
|
|
|
2019-05-01 18:15:57 +12:00
|
|
|
/// Returns the angular component (in radians) of z.
|
2024-01-15 10:04:30 +08:00
|
|
|
pub fn arg(z: anytype) @TypeOf(z.re, z.im) {
|
|
|
|
|
return math.atan2(z.im, z.re);
|
2018-04-24 19:18:31 +12:00
|
|
|
}
|
|
|
|
|
|
2024-02-25 23:31:53 -08:00
|
|
|
test arg {
|
2024-07-30 16:29:51 +12:00
|
|
|
const epsilon = math.floatEps(f32);
|
2021-05-18 02:57:51 +07:00
|
|
|
const a = Complex(f32).init(5, 3);
|
2018-04-24 19:18:31 +12:00
|
|
|
const c = arg(a);
|
2024-07-30 16:29:51 +12:00
|
|
|
try testing.expectApproxEqAbs(0.5404195, c, epsilon);
|
2018-04-24 19:18:31 +12:00
|
|
|
}
|