-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Proposal: xor operator for bool type #5805
Comments
Results of voting in Telegram channel:
Yes, the small community (voted by 8 users) 😄 |
Just wanted to point out some things: Also note that boolean-xor is equivalent in behaviour to |
That's always a funny point. What's your choice? |
const std = @import("std");
const warn = std.debug.warn;
const Vector = std.meta.Vector;
pub fn main () void {
const v1: Vector(4, bool) = [_]bool{ true, false, true, false };
const v2: Vector(4, bool) = [_]bool{ false, false, true, false };
// const v3 = v1 ^ v2; //it isn't compiles
const v4 = v1 != v2;
// ^ this
warn("v1 = {}\n", .{ v1 });
warn("v2 = {}\n", .{ v2 });
// warn("v3 = {}\n", .{ v3 });
warn("v4 = {}\n", .{ v4 });
} |
We will never be able to actually only have one way of doing things - that would be ridiculous; no programming language could do this. But do not let perfection get in the way of good - we can still confidently aim towards this (impossible) goal. We should at the very least try not to go in the opposite direction. Introducing an operator that does the exact same thing as I also do not see the problem with your example - v4 works fine. |
Yes. |
I believe vector equality comparison to check whether all elements are equal rather than performing the operation lane-wise is handled by #2698. |
It shouldn't be unexpected that |
Why?
|
A SIMD vector is not one value. It is a bundle of parallel values. Applying any operator to a SIMD vector applies it to each element in the bundle. This includes As another argument, consider Finally, an xor operation would only resolve this case for |
Because of its "rarity", I implemented comparison of vectors in
Maybe not a new operator, but an implementation |
I think there is a good case to be made for allowing bitwise operators on |
Many languages support it.
It would be nice if Zig will support this operator, too.
I implemented it (mostly) in xor_bool branch. Except for documentation and code generation.
I hope that core developers can finished my work.
The text was updated successfully, but these errors were encountered: