finishing bitwise operatoins
All checks were successful
Build / build (push) Successful in 1m3s
Test / build (push) Successful in 6m4s

This commit is contained in:
2026-01-20 00:32:50 +01:00
parent 9fb8cbea05
commit 35099b33e1
9 changed files with 260 additions and 62 deletions

View File

@@ -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,