Added overflaw security + made benchmark work (set to max)

This commit is contained in:
adrien
2026-04-22 23:11:42 +02:00
parent 5efa42c2e1
commit 2c94df7f4a
5 changed files with 74 additions and 40 deletions
+7 -5
View File
@@ -3,6 +3,8 @@ const hlp = @import("helper.zig");
const Dimensions = @import("Dimensions.zig");
const Dimension = @import("Dimensions.zig").Dimension;
// TODO: add more scales like feet and inch
/// Use to initiate Scalar and Scales type
pub const ArgOpts = struct {
L: UnitScale = .none,
@@ -53,17 +55,17 @@ pub const UnitScale = enum(isize) {
/// Helper to get the actual scaling factor
pub inline fn getFactor(self: @This()) comptime_float {
return switch (self) {
return comptime 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)),
};
}
/// Helper to get the actual scaling factor in 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 => comptime std.math.powi(i32, 10.0, @intFromEnum(self)) catch 0,
inline else => comptime @intFromEnum(self),
pub fn getFactorInt(self: @This()) comptime_int {
return comptime 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),
};
}
};