mirror of
https://github.com/ziglang/zig.git
synced 2024-11-26 15:12:31 +00:00
std.math.complex: Add squared magnitude function (#21998)
Some checks are pending
ci / x86_64-linux-debug (push) Waiting to run
ci / x86_64-linux-release (push) Waiting to run
ci / aarch64-linux-debug (push) Waiting to run
ci / aarch64-linux-release (push) Waiting to run
ci / x86_64-macos-release (push) Waiting to run
ci / aarch64-macos-debug (push) Waiting to run
ci / aarch64-macos-release (push) Waiting to run
ci / x86_64-windows-debug (push) Waiting to run
ci / x86_64-windows-release (push) Waiting to run
ci / aarch64-windows (push) Waiting to run
Some checks are pending
ci / x86_64-linux-debug (push) Waiting to run
ci / x86_64-linux-release (push) Waiting to run
ci / aarch64-linux-debug (push) Waiting to run
ci / aarch64-linux-release (push) Waiting to run
ci / x86_64-macos-release (push) Waiting to run
ci / aarch64-macos-debug (push) Waiting to run
ci / aarch64-macos-release (push) Waiting to run
ci / x86_64-windows-debug (push) Waiting to run
ci / x86_64-windows-release (push) Waiting to run
ci / aarch64-windows (push) Waiting to run
This commit is contained in:
parent
b0dcce93f7
commit
87863a834b
@ -115,6 +115,10 @@ pub fn Complex(comptime T: type) type {
|
|||||||
pub fn magnitude(self: Self) T {
|
pub fn magnitude(self: Self) T {
|
||||||
return @sqrt(self.re * self.re + self.im * self.im);
|
return @sqrt(self.re * self.re + self.im * self.im);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn squaredMagnitude(self: Self) T {
|
||||||
|
return self.re * self.re + self.im * self.im;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -189,6 +193,13 @@ test "magnitude" {
|
|||||||
try testing.expect(math.approxEqAbs(f32, c, 5.83095, epsilon));
|
try testing.expect(math.approxEqAbs(f32, c, 5.83095, epsilon));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
test "squaredMagnitude" {
|
||||||
|
const a = Complex(f32).init(5, 3);
|
||||||
|
const c = a.squaredMagnitude();
|
||||||
|
|
||||||
|
try testing.expect(math.approxEqAbs(f32, c, math.pow(f32, a.magnitude(), 2), epsilon));
|
||||||
|
}
|
||||||
|
|
||||||
test {
|
test {
|
||||||
_ = @import("complex/abs.zig");
|
_ = @import("complex/abs.zig");
|
||||||
_ = @import("complex/acosh.zig");
|
_ = @import("complex/acosh.zig");
|
||||||
|
Loading…
Reference in New Issue
Block a user