2019-03-02 21:46:04 +00:00
|
|
|
const std = @import("../../std.zig");
|
2019-02-08 23:18:47 +00:00
|
|
|
const testing = std.testing;
|
2018-04-24 08:18:31 +01:00
|
|
|
const math = std.math;
|
|
|
|
const cmath = math.complex;
|
|
|
|
const Complex = cmath.Complex;
|
|
|
|
|
2019-05-01 07:15:57 +01:00
|
|
|
/// Returns z raised to the complex power of c.
|
2023-11-07 20:10:43 +00:00
|
|
|
pub fn pow(z: anytype, s: anytype) Complex(@TypeOf(z.re, z.im, s.re, s.im)) {
|
|
|
|
return cmath.exp(cmath.log(z).mul(s));
|
2018-04-24 08:18:31 +01:00
|
|
|
}
|
|
|
|
|
2024-02-26 23:14:43 +00:00
|
|
|
test pow {
|
2024-07-30 05:29:51 +01:00
|
|
|
const epsilon = math.floatEps(f32);
|
2021-05-17 20:57:51 +01:00
|
|
|
const a = Complex(f32).init(5, 3);
|
|
|
|
const b = Complex(f32).init(2.3, -1.3);
|
2023-11-07 20:10:43 +00:00
|
|
|
const c = pow(a, b);
|
2018-04-24 08:18:31 +01:00
|
|
|
|
2024-07-30 05:29:51 +01:00
|
|
|
try testing.expectApproxEqAbs(58.049110, c.re, epsilon);
|
|
|
|
try testing.expectApproxEqAbs(-101.003433, c.im, epsilon);
|
2018-04-24 08:18:31 +01:00
|
|
|
}
|