abs
This commit is contained in:
18
src/numz.zig
18
src/numz.zig
@@ -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));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user