Replies: 3 comments
-
Also, there's just one right shift operator here, but there are two possible behaviors that right shifts can have (arithmetic and logical). C only performs logical shifts when operating on unsigned integers, and I'm not sure what the behavior is for a right shift in C on a negative signed integer. Java has both shifts, and even JS has both arithmetic and logical shifts, as the |
Beta Was this translation helpful? Give feedback.
-
See also: |
Beta Was this translation helpful? Give feedback.
-
I wrote a little code to emulate arithmetic and logical right shifts, here. There are some other methods defined there too, including bitwise rotations. Note, I don't think these are a very good idea to include in Godot; a C++ and JS approach would be much better. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
there are a few functions commonly available in language specifications and standard libraries that work on the bits in integers beyond bitshifts and comparisons
I often times find these useful when working with bitmasks
gdscript has support for bitshift operations and comparisons (and, or, not, xor), but the below operations require a combination of looping or composite operations that (probably) is slower in pure gdscript without the proposed cpp backing:
Implementing these as an extension is an option in some cases, but not for web exports (sidenote: would the cpp implementation be faster for web exports or would it be slower/on par with pure gdscript ?)
Beta Was this translation helpful? Give feedback.
All reactions