Compare commits

...

5 Commits

Author SHA1 Message Date
Chris Boesch
e8ce36a45f
Merge 10c4bf53ca into f845fa04a0 2024-11-21 00:20:48 +01:00
Alex Rønne Petersen
f845fa04a0 std.debug: Gracefully handle process_vm_readv() EPERM in MemoryAccessor.read().
Closes #21815.
2024-11-20 23:07:46 +01:00
Chris Boesch
10c4bf53ca
Changed function name to 'sqrmag' 2024-11-16 15:20:08 +01:00
Chris Boesch
0cf5853c20
Fixed typo in description. 2024-11-16 14:28:02 +01:00
Chris Boesch
8fa9002e3d
Added a missing complex function. 2024-11-16 13:52:35 +01:00
2 changed files with 14 additions and 1 deletions

View File

@ -48,7 +48,8 @@ fn read(ma: *MemoryAccessor, address: usize, buf: []u8) bool {
switch (linux.E.init(bytes_read)) {
.SUCCESS => return bytes_read == buf.len,
.FAULT => return false,
.INVAL, .PERM, .SRCH => unreachable, // own pid is always valid
.INVAL, .SRCH => unreachable, // own pid is always valid
.PERM => {}, // Known to happen in containers.
.NOMEM => {},
.NOSYS => {}, // QEMU is known not to implement this syscall.
else => unreachable, // unexpected

View File

@ -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 squared magnitude of a complex number.
pub fn sqrmag(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 "sqrmag" {
const a = Complex(f32).init(5, 3);
const c = a.sqrmag();
try testing.expect(math.approxEqAbs(f32, c, math.pow(f32, a.magnitude(), 2), epsilon));
}
test {
_ = @import("complex/abs.zig");
_ = @import("complex/acosh.zig");