This commit is contained in:
2026-09-02 15:31:22 -05:00
parent 3c3900a78d
commit 7d7e19b0fc

View File

@@ -92,6 +92,16 @@ pub fn Matrix(rows: comptime_int, cols: comptime_int, T: type) type {
return result;
}
pub fn abs(self: Self) Self {
var result: Self = .{ .mat = undefined };
inline for (&result.mat, self.mat) |*r_row, s_row| {
inline for (r_row, s_row) |*r, s| {
r.* = @abs(s);
}
}
return result;
}
pub const BinOp = struct {
f: @TypeOf(impl.add),
@@ -550,8 +560,8 @@ test "norm" {
}
test "cast" {
try std.testing.expectEqual(@as(f64, 3), stackRows(u32, .{ 3 }).floatFromInt(f64).get(.x));
try std.testing.expectEqual(@as(i32, -4), stackRows(f64, .{ -3.5 }).round(i32).get(.x));
try std.testing.expectEqual(@as(i32, 4), stackRows(f64, .{ 3.5 }).ceil(i32).get(.x));
try std.testing.expectEqual(@as(i32, 3), stackRows(f64, .{ 3.5 }).floor(i32).get(.x));
try std.testing.expectEqual(@as(f64, 3), stackRows(u32, .{3}).floatFromInt(f64).get(.x));
try std.testing.expectEqual(@as(i32, -4), stackRows(f64, .{-3.5}).round(i32).get(.x));
try std.testing.expectEqual(@as(i32, 4), stackRows(f64, .{3.5}).ceil(i32).get(.x));
try std.testing.expectEqual(@as(i32, 3), stackRows(f64, .{3.5}).floor(i32).get(.x));
}