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 z raised to the complex power of c.
8pub fn pow(z: anytype, s: anytype) Complex(@TypeOf(z.re, z.im, s.re, s.im)) {
9 return cmath.exp(cmath.log(z).mul(s));
10}
11
12test pow {
13 const epsilon = math.floatEps(f32);
14 const a = Complex(f32).init(5, 3);
15 const b = Complex(f32).init(2.3, -1.3);
16 const c = pow(a, b);
17
18 try testing.expectApproxEqAbs(58.049110, c.re, epsilon);
19 try testing.expectApproxEqAbs(-101.003433, c.im, epsilon);
20}