finishing bitwise operatoins
This commit is contained in:
@@ -11,19 +11,6 @@ const Operations = enum {
|
||||
Mod,
|
||||
};
|
||||
|
||||
fn Vec(comptime len: usize, comptime T: type) type {
|
||||
return struct {
|
||||
const Self = @This();
|
||||
val: @Vector(len, T),
|
||||
pub fn format(self: *const Self, w: *std.Io.Writer) std.Io.Writer.Error!void {
|
||||
inline for (0..len) |i| {
|
||||
try w.print("{d}", .{self.val[i]});
|
||||
if (i < len - 1) try w.writeAll(", ");
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
// Tests all mathematical operation on all NZSL supported primitive types
|
||||
test "Maths primitives" {
|
||||
const allocator = std.testing.allocator;
|
||||
@@ -106,8 +93,8 @@ test "Maths vectors" {
|
||||
while (it.next()) |op| {
|
||||
inline for (2..5) |L| {
|
||||
inline for (types) |T| {
|
||||
const base_color: Vec(L, T) = .{ .val = case.random(@Vector(L, T)) };
|
||||
const ratio: Vec(L, T) = .{ .val = case.random(@Vector(L, T)) };
|
||||
const base_color: case.Vec(L, T) = .{ .val = case.random(@Vector(L, T)) };
|
||||
const ratio: case.Vec(L, T) = .{ .val = case.random(@Vector(L, T)) };
|
||||
const expected = switch (op.key) {
|
||||
.Add => if (@typeInfo(T) == .int) @addWithOverflow(base_color.val, ratio.val)[0] else base_color.val + ratio.val,
|
||||
.Sub => if (@typeInfo(T) == .int) @subWithOverflow(base_color.val, ratio.val)[0] else base_color.val - ratio.val,
|
||||
|
||||
Reference in New Issue
Block a user