mirror of
https://github.com/ziglang/zig.git
synced 2024-11-26 15:12:31 +00:00
Compare commits
3 Commits
3357eecc3f
...
7903b1a937
Author | SHA1 | Date | |
---|---|---|---|
|
7903b1a937 | ||
|
87863a834b | ||
|
f2b43f9549 |
@ -695,6 +695,7 @@ fn runPkgConfig(compile: *Compile, lib_name: []const u8) !PkgConfigResult {
|
||||
// -lSDL2 -> pkg-config sdl2
|
||||
// -lgdk-3 -> pkg-config gdk-3.0
|
||||
// -latk-1.0 -> pkg-config atk
|
||||
// -lpulse -> pkg-config libpulse
|
||||
const pkgs = try getPkgConfigList(b);
|
||||
|
||||
// Exact match means instant winner.
|
||||
@ -711,13 +712,14 @@ fn runPkgConfig(compile: *Compile, lib_name: []const u8) !PkgConfigResult {
|
||||
}
|
||||
}
|
||||
|
||||
// Now try appending ".0".
|
||||
// Prefixed "lib" or suffixed ".0".
|
||||
for (pkgs) |pkg| {
|
||||
if (std.ascii.indexOfIgnoreCase(pkg.name, lib_name)) |pos| {
|
||||
if (pos != 0) continue;
|
||||
if (mem.eql(u8, pkg.name[lib_name.len..], ".0")) {
|
||||
break :match pkg.name;
|
||||
}
|
||||
const prefix = pkg.name[0..pos];
|
||||
const suffix = pkg.name[pos + lib_name.len ..];
|
||||
if (prefix.len > 0 and !mem.eql(u8, prefix, "lib")) continue;
|
||||
if (suffix.len > 0 and !mem.eql(u8, suffix, ".0")) continue;
|
||||
break :match pkg.name;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -115,6 +115,10 @@ pub fn Complex(comptime T: type) type {
|
||||
pub fn magnitude(self: Self) T {
|
||||
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));
|
||||
}
|
||||
|
||||
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 {
|
||||
_ = @import("complex/abs.zig");
|
||||
_ = @import("complex/acosh.zig");
|
||||
|
Loading…
Reference in New Issue
Block a user