From aa09054c4db40a64201cccd5a9b8cc010299d950 Mon Sep 17 00:00:00 2001 From: adrien Date: Tue, 21 Apr 2026 18:16:37 +0200 Subject: [PATCH] Added fast path to mulBy too --- src/Quantity.zig | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Quantity.zig b/src/Quantity.zig index 3bc3b20..be358ce 100644 --- a/src/Quantity.zig +++ b/src/Quantity.zig @@ -61,7 +61,9 @@ pub fn Quantity(comptime T: type, comptime d: Dimensions, comptime s: Scales) ty const RhsType = @TypeOf(rhs); const SelfNorm = Quantity(T, dims, scales.min(RhsType.scales)); const RhsNorm = Quantity(T, RhsType.dims, scales.min(RhsType.scales)); - // Only convert the side(s) that actually need it + if (comptime Self == SelfNorm and RhsType == RhsNorm) + return .{ .value = self.value * rhs.value }; + const lhs_val = if (comptime Self == SelfNorm) self.value else self.to(SelfNorm).value; const rhs_val = if (comptime RhsType == RhsNorm) rhs.value else rhs.to(RhsNorm).value; return .{ .value = lhs_val * rhs_val };