mirror of
https://github.com/ziglang/zig.git
synced 2024-11-21 19:42:56 +00:00
Compare commits
5 Commits
f378d29392
...
e8ce36a45f
Author | SHA1 | Date | |
---|---|---|---|
|
e8ce36a45f | ||
|
f845fa04a0 | ||
|
10c4bf53ca | ||
|
0cf5853c20 | ||
|
8fa9002e3d |
@ -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
|
||||
|
@ -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");
|
||||
|
Loading…
Reference in New Issue
Block a user