Compare commits
2 Commits
b02665fe89
...
bbab41008f
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bbab41008f | ||
|
|
aa09054c4d |
@ -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 };
|
||||
|
||||
@ -3,7 +3,7 @@ const hlp = @import("helper.zig");
|
||||
const Dimensions = @import("Dimensions.zig");
|
||||
const Dimension = @import("Dimensions.zig").Dimension;
|
||||
|
||||
pub const UnitScale = enum(i32) {
|
||||
pub const UnitScale = enum(isize) {
|
||||
P = 15,
|
||||
T = 12,
|
||||
G = 9,
|
||||
@ -28,7 +28,7 @@ pub const UnitScale = enum(i32) {
|
||||
// Undefined
|
||||
_,
|
||||
|
||||
pub fn str(self: @This()) []const u8 {
|
||||
pub inline fn str(self: @This()) []const u8 {
|
||||
var buf: [16]u8 = undefined;
|
||||
return switch (self) {
|
||||
inline .none => "",
|
||||
@ -38,7 +38,7 @@ pub const UnitScale = enum(i32) {
|
||||
}
|
||||
|
||||
/// Helper to get the actual scaling factor
|
||||
pub fn getFactor(self: @This()) f64 {
|
||||
pub inline fn getFactor(self: @This()) comptime_float {
|
||||
return switch (self) {
|
||||
inline .P, .T, .G, .M, .k, .h, .da, .none, .d, .c, .m, .u, .n, .p, .f => std.math.pow(f64, 10.0, @floatFromInt(@intFromEnum(self))),
|
||||
inline else => @floatFromInt(@intFromEnum(self)),
|
||||
@ -46,10 +46,10 @@ pub const UnitScale = enum(i32) {
|
||||
}
|
||||
|
||||
/// Helper to get the actual scaling factor in i32
|
||||
pub fn getFactorInt(self: @This()) i32 {
|
||||
pub inline fn getFactorInt(self: @This()) comptime_int {
|
||||
return switch (self) {
|
||||
inline .P, .T, .G, .M, .k, .h, .da, .none, .d, .c, .m, .u, .n, .p, .f => std.math.powi(i32, 10.0, @intFromEnum(self)) catch 0,
|
||||
inline else => @intFromEnum(self),
|
||||
inline .P, .T, .G, .M, .k, .h, .da, .none, .d, .c, .m, .u, .n, .p, .f => comptime std.math.powi(i32, 10.0, @intFromEnum(self)) catch 0,
|
||||
inline else => comptime @intFromEnum(self),
|
||||
};
|
||||
}
|
||||
};
|
||||
@ -89,7 +89,7 @@ pub fn min(comptime s1: Scales, comptime s2: Scales) Scales {
|
||||
return out;
|
||||
}
|
||||
|
||||
pub fn getFactor(comptime s: Scales, comptime d: Dimensions) f64 {
|
||||
pub inline fn getFactor(comptime s: Scales, comptime d: Dimensions) comptime_float {
|
||||
comptime var factor: f64 = 1.0;
|
||||
inline for (std.enums.values(Dimension)) |dim| {
|
||||
const power = d.get(dim);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user