From 8fa9002e3df9e822238d524fd887471ceb19610b Mon Sep 17 00:00:00 2001 From: Chris Boesch <48591413+chrboesch@users.noreply.github.com> Date: Sat, 16 Nov 2024 13:52:35 +0100 Subject: [PATCH 1/4] Added a missing complex function. --- lib/std/math/complex.zig | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/lib/std/math/complex.zig b/lib/std/math/complex.zig index 8398d0a69a..1bc1ba043c 100644 --- a/lib/std/math/complex.zig +++ b/lib/std/math/complex.zig @@ -115,6 +115,11 @@ pub fn Complex(comptime T: type) type { pub fn magnitude(self: Self) T { return @sqrt(self.re * self.re + self.im * self.im); } + + /// Returns the quared magnitude of a complex number. + pub fn sqrtmag(self: Self) T { + return self.re * self.re + self.im * self.im; + } }; } @@ -189,6 +194,13 @@ test "magnitude" { try testing.expect(math.approxEqAbs(f32, c, 5.83095, epsilon)); } +test "sqrtmag" { + const a = Complex(f32).init(5, 3); + const c = a.sqrtmag(); + + try testing.expect(math.approxEqAbs(f32, c, math.pow(f32, a.magnitude(), 2), epsilon)); +} + test { _ = @import("complex/abs.zig"); _ = @import("complex/acosh.zig"); From 0cf5853c203430e2c9bff24e0b4edb54d9d2e4f5 Mon Sep 17 00:00:00 2001 From: Chris Boesch <48591413+chrboesch@users.noreply.github.com> Date: Sat, 16 Nov 2024 14:28:02 +0100 Subject: [PATCH 2/4] Fixed typo in description. --- lib/std/math/complex.zig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/std/math/complex.zig b/lib/std/math/complex.zig index 1bc1ba043c..7440d16c70 100644 --- a/lib/std/math/complex.zig +++ b/lib/std/math/complex.zig @@ -116,7 +116,7 @@ pub fn Complex(comptime T: type) type { return @sqrt(self.re * self.re + self.im * self.im); } - /// Returns the quared magnitude of a complex number. + /// Returns the squared magnitude of a complex number. pub fn sqrtmag(self: Self) T { return self.re * self.re + self.im * self.im; } From 10c4bf53ca851354fc3fa70e9991bce97a845609 Mon Sep 17 00:00:00 2001 From: Chris Boesch <48591413+chrboesch@users.noreply.github.com> Date: Sat, 16 Nov 2024 15:20:08 +0100 Subject: [PATCH 3/4] Changed function name to 'sqrmag' --- lib/std/math/complex.zig | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/std/math/complex.zig b/lib/std/math/complex.zig index 7440d16c70..772b067b34 100644 --- a/lib/std/math/complex.zig +++ b/lib/std/math/complex.zig @@ -117,7 +117,7 @@ pub fn Complex(comptime T: type) type { } /// Returns the squared magnitude of a complex number. - pub fn sqrtmag(self: Self) T { + pub fn sqrmag(self: Self) T { return self.re * self.re + self.im * self.im; } }; @@ -194,9 +194,9 @@ test "magnitude" { try testing.expect(math.approxEqAbs(f32, c, 5.83095, epsilon)); } -test "sqrtmag" { +test "sqrmag" { const a = Complex(f32).init(5, 3); - const c = a.sqrtmag(); + const c = a.sqrmag(); try testing.expect(math.approxEqAbs(f32, c, math.pow(f32, a.magnitude(), 2), epsilon)); } From 196af45f083fbbdfe648a00ccb581894ed6b8666 Mon Sep 17 00:00:00 2001 From: Chris Boesch <48591413+chrboesch@users.noreply.github.com> Date: Mon, 25 Nov 2024 11:39:00 +0100 Subject: [PATCH 4/4] Changed function name to squaredMagnitude --- lib/std/math/complex.zig | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/std/math/complex.zig b/lib/std/math/complex.zig index 772b067b34..639474fb2a 100644 --- a/lib/std/math/complex.zig +++ b/lib/std/math/complex.zig @@ -116,8 +116,7 @@ pub fn Complex(comptime T: type) type { return @sqrt(self.re * self.re + self.im * self.im); } - /// Returns the squared magnitude of a complex number. - pub fn sqrmag(self: Self) T { + pub fn squaredMagnitude(self: Self) T { return self.re * self.re + self.im * self.im; } }; @@ -194,9 +193,9 @@ test "magnitude" { try testing.expect(math.approxEqAbs(f32, c, 5.83095, epsilon)); } -test "sqrmag" { +test "squaredMagnitude" { const a = Complex(f32).init(5, 3); - const c = a.sqrmag(); + const c = a.squaredMagnitude(); try testing.expect(math.approxEqAbs(f32, c, math.pow(f32, a.magnitude(), 2), epsilon)); }