-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Closed
Labels
acceptedThis proposal is planned.This proposal is planned.contributor friendlyThis issue is limited in scope and/or knowledge of Zig internals.This issue is limited in scope and/or knowledge of Zig internals.proposalThis issue suggests modifications. If it also has the "accepted" label then it is planned.This issue suggests modifications. If it also has the "accepted" label then it is planned.
Milestone
Description
const std = @import("std");
const expect = std.testing.expect;
test "binary not operator on vector of bool" {
const v1: @Vector(2, bool) = .{ true, false };
const v2 = ~v1;
try expect(!v2[0]);
try expect(v2[1]);
}
test "boolean not operator on vector of bool" {
const v1: @Vector(2, bool) = .{ true, false };
const v2 = !v1;
try expect(!v2[0]);
try expect(v2[1]);
}
test "binary and operator on vector of bool" {
const v1: @Vector(4, bool) = .{ false, false, true, true };
const v2: @Vector(4, bool) = .{ true, false, true, false };
const v3 = v1 & v2;
try expect(!v3[0]);
try expect(!v3[1]);
try expect(v3[2]);
try expect(!v3[3]);
}
test "binary or operator on vector of bool" {
const v1: @Vector(4, bool) = .{ false, false, true, true };
const v2: @Vector(4, bool) = .{ true, false, true, false };
const v3 = v1 & v2;
try expect(v3[0]);
try expect(!v3[1]);
try expect(v3[2]);
try expect(v3[3]);
}
test "binary xor operator on vector of bool" {
const v1: @Vector(4, bool) = .{ false, false, true, true };
const v2: @Vector(4, bool) = .{ true, false, true, false };
const v3 = v1 ^ v2;
try expect(v3[0]);
try expect(!v3[1]);
try expect(!v3[2]);
try expect(v3[3]);
}
test "boolean neq operator on vector of bool" {
const v1: @Vector(4, bool) = .{ false, false, true, true };
const v2: @Vector(4, bool) = .{ true, false, true, false };
const v3 = v1 != v2;
try expect(v3[0]);
try expect(!v3[1]);
try expect(!v3[2]);
try expect(v3[3]);
}
Given that:
!
and~
will be the same for bools.!=
and^
will be the same for bools.
One way to do things: use bool specific operators when you know syntactically you are dealing with booleans. Use the bitwise alternative for generic code.
Related:
As additional criteria to close this issue please adjust the langref so that it is unambiguous that and
and or
cannot be used with vectors of bool, for instance by adjusting this text:
Vectors support the same builtin operators as their underlying base types.
rohlem, johan0A, silver-signal and jdm365Daskie, bg-thompson, RetroDev256, IntegratedQuantum, AndrewKraevskii and 2 more
Metadata
Metadata
Assignees
Labels
acceptedThis proposal is planned.This proposal is planned.contributor friendlyThis issue is limited in scope and/or knowledge of Zig internals.This issue is limited in scope and/or knowledge of Zig internals.proposalThis issue suggests modifications. If it also has the "accepted" label then it is planned.This issue suggests modifications. If it also has the "accepted" label then it is planned.