authorgravatar for 77922942+expikr@users.noreply.github.comexpikr <77922942+expikr@users.noreply.github.com> 2023-11-08 04:10:43+08:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-01-14 18:09:26-08:00
logff23efe9fa46f6ae568ae6d335fc0fd058064aa1
tree02068ed3eb80f0c864e3b80fd43ffa5772efd513
parent0c70d9c71455122c6d67777c216e47133b8f8416

Update pow.zig


1 files changed, 3 insertions(+), 5 deletions(-)

lib/std/math/complex/pow.zig+3-5
......@@ -5,10 +5,8 @@ const cmath = math.complex;
55const Complex = cmath.Complex;
66
77/// Returns z raised to the complex power of c.
8pub fn pow(comptime T: type, z: T, c: T) T {
9 const p = cmath.log(z);
10 const q = c.mul(p);
11 return cmath.exp(q);
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));
1210}
1311
1412const epsilon = 0.0001;
......@@ -16,7 +14,7 @@ const epsilon = 0.0001;
1614test "complex.cpow" {
1715 const a = Complex(f32).init(5, 3);
1816 const b = Complex(f32).init(2.3, -1.3);
19 const c = pow(Complex(f32), a, b);
17 const c = pow(a, b);
2018
2119 try testing.expect(math.approxEqAbs(f32, c.re, 58.049110, epsilon));
2220 try testing.expect(math.approxEqAbs(f32, c.im, -101.003433, epsilon));