Compare commits

...

4 Commits

Author SHA1 Message Date
Uzair Aftab
cfd62e7e06
Merge f9c0dd0450 into 87863a834b 2024-11-26 14:11:00 +01:00
Chris Boesch
87863a834b
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
2024-11-26 13:03:48 +00:00
Uzair Aftab
f9c0dd0450
Merge branch 'master' into master 2024-11-26 00:42:33 +01:00
Uzair Aftab
2682c359f9
cli: Improve wording of -femit-bin[=path] docs in help-text 2024-11-25 23:55:11 +01:00
3 changed files with 13 additions and 2 deletions

View File

@ -1805,7 +1805,7 @@ fn make(step: *Step, options: Step.MakeOptions) !void {
lp.path = b.fmt("{}", .{output_dir});
}
// -femit-bin[=path] (default) Output machine code
// -femit-bin[=path] (default) Produce and output a binary to an optional path. Defaults to the current working directory.
if (compile.generated_bin) |bin| {
bin.path = output_dir.joinString(b.allocator, compile.out_filename) catch @panic("OOM");
}

View File

@ -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");

View File

@ -414,7 +414,7 @@ const usage_build_generic =
\\ -j<N> Limit concurrent jobs (default is to use all CPU cores)
\\ -fincremental Enable incremental compilation
\\ -fno-incremental Disable incremental compilation
\\ -femit-bin[=path] (default) Output machine code
\\ -femit-bin[=path] (default) Produce and output a binary to an optional path. Defaults to the current working directory.
\\ -fno-emit-bin Do not output machine code
\\ -femit-asm[=path] Output .s (assembly code)
\\ -fno-emit-asm (default) Do not output .s (assembly code)